Find points on the circle

We encode in C ++, we have half the circle, starting from a certain point (for example, (0,-310) ) and ending at a certain point (0,310) . We have a radius, and we have the equation X^2 + Y^2 = r^2 . Now we are trying to calculate some (for example, 10+) points on the line of this circle.

Therefore, we are trying to create an increment that will calculate the Y / X values ​​between these points using the equation above to make sure that all the counted points are on the circle line.

Once we have these points, we try to put them in several complex equations to calculate the angles of the robot arm, which should draw this shape. This is not a priority, but I thought I should include our common goal in the matter.

How to create an increment to calculate all the coordinates on the semicircle line between our two starting points?
Then put these values ​​in the equations in the code above to calculate the angles of the robot arm. looking for a way to do this without calculating each point separately, i.e. create an increment that does this in one go.

This is what we are aiming for in bold.

+4
source share
3 answers

Should the points be evenly distributed? If not, you can simply use your formula directly:

 // assume half-circle centered at (0,0) and radius=310 double r = 310.0; int n = 10; for( int i=0; i<n; i++ ) { double x = i*r/n; double y = sqrt( r*r - x*x ); // both (x,y) and (x,-y) are points on the half-circle } 

Once this works, you can also play with the distribution of x values ​​to get closer to a uniform distance around the circle.

If your circle is not centered on (0,0) , then just compare the calculated (x,y) with the actual center.

+3
source

Circle points can be determined by the formulas:

 x = radius * cos(angle) y = radius * sin(angle) 

You will need to determine the piece, part or arc of the circle that you draw, and determine the angle of the beginning and the angle of rotation.

Otherwise, do a SO and network search for the "C ++ Arc Drawing Algorithm".

+4
source

you can do this by changing your equation as theta (angle): X = X0 + Cos (Theta) * r
Y = Y0 + Sin (Theta) * r
while in your case (X0, Y0) = (0,0), r = 310 and Theta range is between -180 - 180 (if your cos and sin are in degrees) or between -Phi - Phi (if cos and sin in radii).

Now, if you need 10 points, you need to take the Theta range and divide it by 10 and cal X, Y for each of these values.

0
source

All Articles