It's been 10 years since I did any math like this... I am programming a game in 2D and moving a player around. As I move the player around I am trying to calculate the point on a circle 200 pixels away from the player position given a positive OR negative angle(degree) between -360 to 360. The screen is 1280x720 with 0,0 being the center point of the screen. The player moves around this entire Cartesian coordinate system. The point I am trying trying to find can be off screen.
I tried the formulas on article Find the point with radius and angle but I don't believe I am understanding what "Angle" is because I am getting weird results when I pass Angle as -360 to 360 into a Cos(angle) or Sin(angle).
So for example I have...
- 1280x720 on a Cartesian plane
- Center Point (the position of player):
- let x = a number between minimum -640 to maximum 640
- let y = a number between minimum -360 to maximum 360
- Radius of Circle around the player: let r always = 200
- Angle: let a = a number given between -360 to 360 (allow negative to point downward or positive to point upward so -10 and 350 would give same answer)
What is the formula to return X on the circle?
What is the formula to return Y on the circle?
You should post the code you are using. That would help identify the problem exactly.
However, since you mentioned measuring your angle in terms of -360 to 360, you are probably using the incorrect units for your math library. Most implementations of trigonometry functions use radians for their input. And if you use degrees instead...your answers will be weirdly wrong.
Note that you might also run into circumstance where the quadrant is not what you'd expect. This can fixed by carefully selecting where angle zero is, or by manually checking the quadrant you expect and applying your own signs to the result values.
Recommend:
The simple equations you've linked to give the X and Y coordinates of the point on the circle relative to the center of the circle.
This tells you how far the point is offset from the center of the circle. Since you have the coordinates of the center (Cx, Cy), simply add the calculated offset.
The coordinates of the point on the circle are:
Here is the c# implementation. The method will return the circular points which takes
radius
,center
andangle interval
as parameter. Angle is passed as Radian.and the calling example:
I think the reason your attempt did not work is that you were passing angles in degrees. The
sin
andcos
trigonometric functions expect angles expressed in radians, so the numbers should be from0
to2*M_PI
. Ford
degrees you passM_PI*d/180.0
.M_PI
is a constant defined inmath.h
header.I also needed this to form the movement of the hands of a clock in code. I tried several formulas but they didn't work, so this is what I came up with:
So the formula would be
where x and y are the points on the circumference of a circle, Cx and Cy are the x,y coordinates of the center, r is the radius, and d is the amount of degrees.