# plot points on circle between 2 points.

This topic is 4025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys, I have some code that plots points on a circle: for (float theta = 0; theta <= 2 * PI; theta += PI / (rRadius * rAccuracy)) { float x = rRadius * cos(theta); float y = rRadius * sin(theta); } How would I instead plot points between 2 points on circle? ie I have 2 points on a circle, how do I plot points between these points? I figure I need to convert these points to theta values (Do you know how to do this) and then use the loop from theta1 to theta2. thanks!

##### Share on other sites
EDIT: i wrote something wrong, better take a look here.

http://www.teacherschoice.com.au/Maths_Library/Coordinates/polar_-_rectangular_conversion.htm

##### Share on other sites
If you look at your (kneeride's) code snippet posted in the OP, you'll see a conversion from the angle theta to a point (x,y) like so:

x := R * cos( theta )
y := R * sin( theta )

What you want to do is the inverse function, namely convert from a point to an angle. Unfortunately you have a sine _and_ a cosine of the unknown variable theta; but there is a correspondence

tan( theta ) = sin( theta ) / cos( theta )

that can be used to isolate theta.

Since this computation is to be used w/ caution due to its division by zero possibility and its periodicity, your programming API typically offers a function atan2(y,x) that considers these aspects as well.

##### Share on other sites
Does this look like I'm on the right track? I found some code deep in my library. it looks similar to what I need. (I however have no idea why y is before x in the parameters)

double x(double y, double x){  if (x > 0)  {    return atan2(y,x);  }  else if (x > 0)  {    return G_PI + atan2(y,x);  }  else // x == 0  {    if (y >= 0)     {      return G_PI / 2;    }    else    {      return -(G_PI / 2);    }  }}

##### Share on other sites
The atan2 function already does all neccessary case distinctions for you (okay, I don't really know the standard at this point, but AFAIK it does).

However, atan2 returns a value between -pi and +pi, and perhaps you would be more happy w/ values between 0 and 2pi. Then a downstream add-on
  if(theta<0) {     theta += TWO_PI;  }

would be appropriate.

Besides that there is a typo in your snippet w/ distincting x<0.

##### Share on other sites
cool. thanks for tips

##### Share on other sites
You could also just add PI to all results, and get a range of 0 to 2PI. This changes where 0 radians is (opposite direction) though.

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002140
×