1

Is there any way to find out the direction of svg path elements i.e clockwise or counterclockwise.

I have d path of semi circle.For example, path: "M-75 0A75 75 0 1 0 75 0Z"

Another example: M2,2 Q8,2 8,8z

Help me find out its direction or for any svg paths.Suggestions please.

Hin
  • 65
  • 6
  • Possible duplicate of [How to determine if a list of polygon points are in clockwise order?](https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order) – Matthias Winkelmann Dec 05 '18 at 13:25
  • @MattW. The above example has only two points (-75,0),(75,0) i.e collinear points.Then the above calculation does not stand right ??.I should check the sweep flag of arc command ?? – Hin Dec 09 '18 at 07:46

1 Answers1

2

Look at the specification

A   75  75   0                  1                0         75  0
    rx  ry   x-axis-rotation   large-arc-flag sweep-flag    x  y

sweep flag 0 corresponds to CCW direction

ccprog
  • 20,308
  • 4
  • 27
  • 44
MBo
  • 77,366
  • 5
  • 53
  • 86
  • @ccprog The above example has only two points (-75,0),(75,0) i.e collinear points.Then the calculation does not stand right https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order ??.I should check the sweep flag of arc command ?? – Hin Dec 09 '18 at 07:51
  • @Hin Two points cannot be collinear, they just lie on the same horizontal. Their positions has no relation to arc direction. Again - sweep is already defined in your code. – MBo Dec 09 '18 at 09:40
  • what for quadratic curves ?? M2,2 Q8,2 8,8z @MBo – Hin Dec 09 '18 at 10:40
  • Q is quadratic Bezier with control point 8, 2 and end point 8,8 – MBo Dec 09 '18 at 11:22
  • can we know the direction for this @MBo – Hin Dec 09 '18 at 11:24
  • Check whether control point is left to start-end vector using cross product. If yes - CW, if right - CCW – MBo Dec 09 '18 at 11:43