I have got short question: How to draw Arc in 2 demension know only start and end point in OpenGL?
Actually, something already wrote, however, this algorithm does not accomplish its purpose. Here we go:
1. Get startXY
2. Get endXY
3. Const num_segments = numeric below than 0
4. Calc midPoint.SetXY((start.x + end.x) / 2, (start.y + end.y) / 2)
5. Calc diameter = sqrt(pow((end.x - start.y), 2) + pow((end.y -
start.y), 2));
6. Calc start_angle = atan2(start.y - midPoint.y, start.x -
midPoint.x);
7. Calc end_angle = atan2(end.y - midPoint.y, end.y - midPoint.x);
8. Calc r = sqrt(((midPoint.x - start.x)*(midPoint.x - start.x)) +
((midPoint.y - start.y)*(midPoint.y - start.y)));
9. Calc theta = end_angle / num_segments;
10. Calc tangetial_factor = tanf(theta);
11. Calc float radial_factor = cosf(theta);
12. Calc x = r * cosf(start_angle); //we now start at the start angle
13. Calc y = r * sinf(start_angle);
14. for (int ii = 0; ii < num_segments; ii++)
drawXY(x + midPoint.x, windowHeight - (y + midPoint.y));
float tx = -y;
float ty = x;
x += tx * tangetial_factor;
y += ty * tangetial_factor;
x *= radial_factor;
y *= radial_factor;
15. endFor
Where I made a mistake? Is there a faster way to draw semi-circle?
The formula for the equation of the circle using $(x_{start}, y_{start})$ and $(x_{end}, y_{end})$ as two endpoints of its diameter is:-
$$(x - x_{start})(x - x_{end}) + (y - y_{start})(y - y_{end}) = 0$$
It saves some time than going through the process of finding the midpoint.