问题描述
我们在C ++中编码,有半个圆圈,从某个点开始(例如(0,-310)
),并在某个点结束(0,310)
。我们有半径,我们有等式 X ^ 2 + Y ^ 2 = r ^ 2
。现在我们试图计算这个圆的线上的一些(比如10+)点。
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.
因此,我们试图创建一个增量来计算Y / X值在这些点之间,使用上面显示的方程,以确保计算的所有点都在圆的线上。
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
}
一旦这个工作完成,你也可以使用x值的分布来近似围绕圆周的间距。
Once this is working, you could also play with the distribution of x values to approximate even spacing around the circle.
如果你的圆不以(0,0)
为中心,然后将计算的(x,y)
。
If your circle is not centered at (0,0)
then just offset the computed (x,y)
by the actual center.
这篇关于在圆圈上寻找点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!