+ 4
How to determine x,y coordinates of a point of a 360 degree circle?
I'm really embarrassed posting this question since it's something I've learned in primary school and in high school but I've forgotten the formula. I'm try to determine the x,y coordinates of a point of a 360 degree circle created using the canvas. I want to know the formula really, because I'm busy with a code that can't work without it. Example, let's say I have these following stats: canvas = 1000x1000 circle center = x(500), y(500) radius of circle = 900 Now let's say I want to draw a line from the center coordinates to the 30 degree point on that circle, how do I calculate the coordinates of where to draw that line to? Help would really be appreciated, but I'm also searching for a solution on my own.
12 odpowiedzi
+ 5
X = Cx + (r * cosine(degrees * pi / 180))
Y = Cy + (r * sine(degrees * pi / 180))
http://etc.usf.edu/clipart/43200/43217/unit-circle9_43217.htm
+ 4
Thank you all for the help, I really appreciate it. Special thanks to Calvin and Martin that gave the correct formulas.
The formula for my code now is:
X=Cx+(radius*Math.cos((angle+(-90))*(Math.PI/180)));
Y=Cy+(radius*Math.sin((angle+(-90))*(Math.PI/180)));
I tweeked it a little to suit the purpose of my code. Now if the angle is 30 degree then it would be 30 degree starting from the top and going clockwise.
Basically the same as with a normal clock.
+ 2
Hmmm let me see
+ 2
What information are you given?
+ 2
You calculate it with sine and cosine. Usually there are functions for that.
+ 2
// in Javascript , 30deg to the positive side
var x = cx + r*Math.cos(30/180 * Math.PI);
var y = cy + r*Math.sin(30/180 * Math.PI);
+ 2
That's really cool Andrew ☺ but that's not what I mean. Calvin's formula is correct and it's working but I'm just a bit confused that it's giving me coordinates starting from the right and not from the top.
+ 2
Thank you for those who helped me here, this is the code I've been working on.
https://code.sololearn.com/W8yx1kn73QDI/?ref=app
+ 1
I'm trying out the solutions you guys posted, you've lead me in the right direction. I'll post an answer here once I've successfully integrated these formulas in my code.
For now I'm still having hiccups but it's my lack of understanding of these formulas that causes the problem.