It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,
visit the help center.
Closed 7 years ago.
We are coding in C++, have half a circle, starting a a certain point (e.g. (0,-310)
) and finishing at a certain point (0,310)
. We have the radius, and we have the equation X^2 + Y^2 = r^2
. Now we are trying to calculate some (say 10+) points on the line of this circle.
Hence, we are trying to create an increment that will calculate the Y/X values between these points, using the equation shown above to make sure that all the points calculated are on the line of the circle.
Once we have these points, we are trying to put them into several complex equations to calculate angles of a robot arm that is to draw this shape. This is not really the priority, but I thought I should include our overall aim in the question.
How to create an increment to calculate all the coordinates on line of the half circle between our two start points?
Then put these values into 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 individually, i.e. create an increment that will do it in one go.
This is kind of what we are aiming for, to calculate the points in bold.
Do the points need to be evenly spaced? If not, then you could just 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 is working, you could also play with the distribution of x values to approximate even spacing around the circle.
If your circle is not centered at (0,0)
then just offset the computed (x,y)
by the actual center.
The points of a circle can be determined using the formulas:
x = radius * cos(angle)
y = radius * sin(angle)
You will have to determine the piece, portion, or arc of the circle you are drawing and determine the starting angle and ending angle.
Otherwise, search SO and the web for "arc drawing algorithm c++".
you can do it by changing your equation to be of Theta (the angle) like that:
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 in degrees) or between -Phi - Phi (if cos and sin in radii).
Now if you want 10 points you need to take your Theta range, and split it to 10 and cal X,Y for each of those values.