I have to draw an arc between two points at the edge of a circle. Assuming that the arc is drawn always in the shortest distance possible(edit2: sweep flag set to 0), I need to know if the arc is drawn clockwise or anticlockwise.
I got the following inputs:
- start point (point1)
- end point (point2)
- center point
- radius
Edit1: This question is related to arcs in svg. Hence its belongs to programming.
CodePudding user response:
The answer is SVG supports both clockwise and anticlockwise arcs. You switch between them by changing the "sweep" flag in an arc (A) command.
If you want to learn how SVG arcs work, the place to look is the Paths arcs section of the SVG specification.
CodePudding user response:
Having described data, you can find what arc is smaller - CCW or CW one.
Just check sign of cross product of vectors point1-center
and point2-center
to reveal shortest arc orientation:
cp = (p1.x-c.x)*(p2.y-c.y)-(p1.y-c.y)*(p2.x-c.x)
For cp>0
you have to set sweep
parameter to 0, otherwise to 1 (perhaps vice versa), whilst large-arc-flag
should be always 0.