问题
My question is probably more about maths rather than programming, but I hope that is not a problem. In my app, I am calculating some movement paths, consisting of pixel coordinates (only calculating, not displaying them). I am now trying to smoothen the turn, which are now too sharp, so I would like to use some arc here. I found how I could draw the exact arc I need, using code like this:
e.Graphics.DrawArc(myPen, myPoint.X, myPoints.Y, 50, 50, 180, 90);
Basically what I know are three points (the arc will be between two of these, third is now the turn's corner), the height and width of the arc, the initial and wanted course/heading/angle. I tried this in an app that visualizes the path later, and it works. However, I need to calculate some coordinates on the arc, to add to the array of Points that I save as the path. Anyone knows how? I would need about 5 points for an arc of this size (the number of points will change however) Thanks
回答1:
DrawArc draws a part of an ellipse or a circle in your case (regarding the 4th and 5th parameter.) The radius of your circle is 25. The math of a circle is: x^2 + y^2 = r^2
.
Therefore, I think you can calculate points on this circle by calculating:
Y = myPoint.Y + 25 +/- Sqrt(625 - (X - myPoint.X - 25)^2).
Let X run from myPoint.X
to myPoint.X + 50
and you will find some corresponding Y's.
Because it is a circle, each X has 2 Y values (Therefore, +/- in the formula; you need to calculate the + and the -).
来源:https://stackoverflow.com/questions/25935315/calculate-points-coordinates-of-an-arc