简体   繁体   English

点在一个圆上,有限制。 如何在没有角度但半径和中心点的情况下进行计算?

[英]Points on a circle, with limits. How To calculate without angle, but radius and centre point?

This is quite complicated to explain, so I will do my best, sorry if there is anything I missed out, let me know and I will rectify it. 这很难解释,因此我会尽力而为,如果有任何遗漏的地方,对不起,请告诉我,我将予以纠正。

My question is, I have been tasked to draw this shape, 我的问题是,我受命绘制这种形状,

新月
(source: learnersdictionary.com ) (来源: studentsdictionary.com

This is to be done using C++ to write code that will calculate the points on this shape. 这是使用C ++编写代码来计算此形状上的点来完成的。

Important details. 重要细节。

User Input - Centre Point (X, Y), number of points to be shown, Font Size (influences radius) 用户输入-中心点(X,Y),要显示的点数,字体大小(影响半径)

Output - List of co-ordinates on the shape. 输出-形状上的坐标列表。

The overall aim once I have the points is to put them into a graph on Excel and it will hopefully draw it for me, at the user inputted size! 一旦掌握了所有要点,总体目标就是将其放入Excel中的图形中,并希望以用户输入的大小为我绘制图形!

I know that the maximum Radius is 165mm and the minimum is 35mm. 我知道最大半径为165mm,最小为35mm。 I have decided that my base Font Size shall be 20. I then did some thinking and came up with the equation. 我决定将我的基本字体大小设置为20。然后我做了一些思考,得出了等式。

Radius = (Chosen Font Size/20)*130. 半径=(选择的字体大小/ 20)* 130。 This is just an estimation, I realise it probably not right, but I thought it could work at least as a template. 这只是一个估计,我意识到这可能不正确,但是我认为它至少可以作为模板。

I then decided that I should create two different circles, with two different centre points, then link them together to create the shape. 然后,我决定应该创建两个具有两个不同中心点的不同圆,然后将它们链接在一起以创建形状。 I thought that the INSIDE line will have to have a larger Radius and a centre point further along the X-Axis (Y staying constant), as then it could cut into the outside line. 我认为INSIDE线必须具有更大的半径和沿X轴更远的中心点(Y保持不变),这样才可以切入外线。

So I defined 2nd Centre point as (X+4, Y). 因此,我将第二个中心点定义为(X + 4,Y)。 (Again, just estimation, thought it doesn't really matter how far apart they are). (再次,只是估计,认为它们之间的距离并不重要)。

I then decided Radius 2 = (Chosen Font Size/20)*165 (max radius) 然后我决定半径2 =(选择的字体大小/ 20)* 165(最大半径)

So, I have my 2 Radii, and two centre points. 因此,我有2个Radii和两个中心点。

Now to calculate the points on the circles, I am really struggling. 现在计算圆上的积分,我真的很挣扎。 I decided the best way to do it would be to create an increment (here is template) 我决定最好的方法是创建一个增量(这是模板)

for(int i=0; i<=n; i++) //where 'n' is users chosen number of points
{ 
  //Equation for X point
  //Equation for Y Point
  cout<<"("<<X<<","<<Y<<")"<<endl;
}

Now, for the life of me, I cannot figure out an equation to calculate the points. 现在,对于我的一生,我无法找出方程式来计算积分。 I have found equations that involve angles , but as I do not have any, I'm struggling. 我发现了涉及角度的方程,但是由于我没有方程,所以我很努力。

I am, in essence, trying to calculate Point 'P' here, except all the way round the circle. 从本质上讲,我一直在尝试计算点“ P”,除了一直绕圆。 圆点
(source: tutorvista.com ) (来源: tutorvista.com

Another point I am thinking may be a problem is imposing limits on the values calculated to only display the values that are on the shape.? 我在想的另一点可能是一个问题,就是对计算出的值施加限制以仅显示形状上的值。 Not sure how to chose limits exactly other than to make the outside line a full Half Circle so I have a maximum radius? 除了使外线成为完整的半圆之外,不确定是否要选择其他极限,所以我有最大半径吗?

So. 所以。 Does anyone have any hints/tips/links they can share with me on how to proceed exactly? 任何人都没有任何提示/技巧/链接,可以与我分享如何正确进行操作?

Thanks again, any problems with the question, sorry will do my best to rectify if you let me know. 再次感谢您,如果有任何问题,对不起,如果您让我知道,我们将尽力纠正。

Cheers 干杯

UPDATE; 更新;

R1 = (Font/20)*130;
R2 = (Font/20)*165;

for(X1=0; X1<=n; X1++)
{
    Y1 = ((2*Y)+(pow(((4*((pow((X1-X), 2)))+(pow(R1, 2)))), 0.5)))/2;
    Y2 = ((2*Y)-(pow(((4*((pow((X1-X), 2)))+(pow(R1, 2)))), 0.5)))/2;
    cout<<"("<<X1<<","<<Y1<<")";
    cout<<"("<<X1<<","<<Y2<<")";
}

Opinion? 意见?

The equation of a circle is 圆的方程是

(x - h)^2 + (y - k)^2 = r^2

With a little bit of algebra, you can iterate x over the range from h to h+r incrementing by some appropriate delta and calculate the two corresponding values of y. 只需一点代数,您就可以在从hh+r的范围内以适当的delta递增迭代x ,并计算y的两个对应值。 This will draw a complete circle. 这将画出一个完整的圆圈。

The next step is to find the x-coordinate for the intersection of the two circles (assuming that the moon shape is defined by two appropriate circles). 下一步是找到两个圆的交点的x坐标(假设月亮形状由两个适当的圆定义)。 Again, some algebra and a pencil and paper will help. 同样,一些代数和铅笔和纸将有所帮助。

More details: 更多细节:

To draw a circle without using polar coordinates and trig, you can do something like this: 要在不使用极坐标和触发的情况下绘制圆,可以执行以下操作:

for x in h-r to h+r increment by delta
    calculate both y coordinates

To calculate the y-coordinates, you need to solve the equation of a circle for y. 要计算y坐标,您需要求解y的圆方程。 The easiest way to do this is to transform it into a quadratic equation of the form A*y^2+B*y+C=0 and use the quadratic equation: 最简单的方法是将其转换为形式为A*y^2+B*y+C=0的二次方程,然后使用二次方程:

(x - h)^2 + (y - k)^2 = r^2
(x - h)^2 + (y - k)^2 - r^2 = 0
(y^2 - 2*k*y + k^2) + (x - h)^2  - r^2 = 0
y^2 - 2*k*y + (k^2 + (x - h)^2  - r^2) = 0

So we have 所以我们有

A = 1
B = -2*k
C = k^2 + (x - h)^2  - r^2

Now plug these into the quadratic equation and chug out the two y-values for each x value in the for loop. 现在将它们插入二次方程式,并为for循环中的每个x值导出两个y值。 (Most likely, you will want to do the calculations in a separate function -- or functions.) (很可能,您将需要在一个或多个单独的函数中进行计算。)

As you can see this is pretty messy. 如您所见,这非常混乱。 Doing this with trigonometry and angles will be much cleaner. 使用三角函数和角度进行此操作会更清洁。

More thoughts: 更多想法:

Even though there are no angles in the user input described in the question, there is no intrinsic reason why you cannot use them during calculations (unless you have a specific requirement otherwise, say because your teacher told you not to). 即使问题中描述的用户输入中没有角度,也没有内在的原因为什么您不能在计算过程中使用它们(除非您有特殊要求,否则请说,因为您的老师告诉您不要这样做)。 With that said, using polar coordinates makes this much easier. 话虽如此,使用极坐标使此操作变得更加容易。 For a complete circle you can do something like this: 对于完整的圈子,您可以执行以下操作:

for theta = 0 to 2*PI increment by delta
    x = r * cos(theta)
    y = r * sin(theta)

To draw an arc, rather than a full circle, you simply change the limits for theta in the for loop. 要绘制圆弧而不是完整的圆,您只需在for循环中更改theta的限制。 For example, the left-half of the circle goes from PI/2 to 3*PI/2 . 例如,圆的左半部分从PI/2变为3*PI/2

As per Code-Guru's comments on the question, the inner circle looks more like a half circle than the outer. 根据Code-Guru对问题的评论,内圈看起来比外圈更像一个半圈。 Use the equation in Code-Guru's answer to calculate the points for the inner circle. 使用Code-Guru答案中的方程式计算内圆的点。 Then, have a look at this question for how to calculate the radius of a circle which intersects your circle, given the distance (which you can set arbitrarily) and the points of intersection (which you know, because it's a half circle). 然后,看看这个问题 ,在给定距离(可以任意设置)和相交点(因为是半圆)的情况下,如何计算与圆相交的圆的半径。 From this you can draw the outer arc for any given distance, and all you need to do is vary the distance until you produce a shape that you're happy with. 由此,您可以绘制任意给定距离的外圆弧,而要做的就是改变距离,直到生成满意的形状。

This question may help you to apply Code-Guru's equation. 这个问题可以帮助您应用Code-Guru方程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM