0

I have:

private double AngleToRadians(double angle)
{
     return (Math.PI / 180) * angle;
}


double x = 30, y = 60;
var dist = 10;
var angle = 120;

x = x + dist * Math.Cos(AngleToRadians(angle));
y = y + dist * Math.Sin(AngleToRadians(angle));

What this does is returns me a new coordinate, 10 points into direction (angle) from (x,y) starting point.

This works correctly in top-right quadrant, but does not on any of other three.

Is there a formula that would work in all 4?

user2818626
  • 43
  • 1
  • 2
  • 8

2 Answers2

7

x = x + dist * Math.Cos(AngleToRadians(angle)); y = y + dist * Math.Sin(AngleToRadians(angle));

It seems you are using the same x and y variables both for central point and for ending point, so coordinates of center are updated every time

Just use x0, y0 as center and x, y as ending point

x = x0 + dist * Math.Cos(AngleToRadians(angle));

MBo
  • 77,366
  • 5
  • 53
  • 86
-2

a (horizontal length), b (vertical length), x (coordinate x), y (coordinate y), r (radius of the sphere), θ (angle), L (distance until the ball stops) are given, find coordinates (X, Y) at which the ball stops.

Tips:

If the billiard table is infinitely large and the ball can not reach to wall, then calculated, the coordinates (X, Y) at which the ball stops can be calculated by the following formula. X = L * cos (θ) + x Y = L * sin (θ) + y

Baba
  • 1