I have a half-circle (green) and an object (blue). I want to move that object on that circle from start (left) to end (right). The object should follow the path (black) of the half-circle. Object should move based on specific value. Value is a number from 0 to 1. Start = 0, end = 1. My current solution: translate the

# Tag: math

## Formula to calculate time needed for a ball to reach destination where the ball’s x y is updated in a time loop

I am coding a simulation of ball movement. I have an updateBall function which runs every 100 miliseconds to update the location of the ball. How is the formula to find out the time in miliseconds needed to reach a given target coordinate? For example, given target x=100 y=200 the time needed to reach is approximately 5300ms. Below is the

## How to calculate a bounding box for a rectangle rotated around its center?

I am looking to calculate the bounding box of a rectangle rotated around its center. I have read this question and while MarkusQ’s answer works in general, it is not efficient enough for my needs. I am trying to get Troubadour’s answer working, but it seems to only work when the origin of rotation is around a corner, not the

## Using Trigonometry to draw equidistant parralleles lines through a circle

As seen on the picture, I need a math formula that calculate the red circled point with cartesian coordonate that will make equidistant lines. It is not simple trigonometry I guess… My goal is to be able to calculate cartesian point around half of the circle and trace my lines from it. Using p5js, I’ll use random value from Perlin

## Compressing or converting game data to a short string password (and back again) in Javascript

(Edited the title because I had no idea what I was looking for and it was misleading.) Edit: What I was looking for was binary to string and back again. I have answered my own question below.) Original Post: I’m trying to make a retro-style password system for a game made with JavaScript. (like on an old NES game for

## Cannot create type as specific number when number is in variable

I want to create a type that can be only 1 or root 2. This works: But when I try to use Math.SQRT2, or any variable reference to the numeric value of root 2, I get an error. For example: Typescript playground demonstrating the issue In my code I want to be able to reference the root of 2 with

## How can I change the angle of a vector when hitting an obstacle

So, my issue concerns vectors, I don’t know where I’m going with that case. I’m building a pandemic simulation (using Javascript and the library p5.js), and I’m trying to add a lockdown feature. Here is an image to make everything clearer: Essentially, at the moment, when two molecules collide, their velocity vector change appropriately by switching their former velocity. My

## Canvas zoom to cursor doesn’t work correct

I’m trying to scale canvas to/from mouse position, but it works not perfect (always goes few cells away from mouse pos). I’ve read all similar posts but i don’t know what’s wrong. https://jsfiddle.net/shumikua/3afxtmqw/ All code is only to run snippet, it works good. Problem is in function scale. Answer In function scale() keep the same values for x and y

## Calculate the radius of an ellipse using Javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question If I have the height and width of an ellipse and the angle from the center. How can I calculate

## Does putting intermediary math results into variables improve performance in javascript?

I have been playing around with the Riemann zeta function. I want to optimize execution time as much as possible here so I put the intermediary results in temporary variables. But testing revealed that I get no performance boost from this. At least not noticeably. My question is: Even though I couldn’t measure a difference in execution time, what’s theoretically