fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.37k stars 354 forks source link

Question about `DrawArc` #112

Closed Lantero closed 2 years ago

Lantero commented 3 years ago

One thing that I don't quite understand is DrawArc start and end angles. I just want to ask if my investigation about it is correct or not.

In Mathematics - as far as I'm aware - angles go counterclockwise, starting from the right (3 o'clock). DrawArc seem to go clockwise, starting from the same point.

This should not be much of an issue except for the behaviour of dc.DrawArc(x, y, radius, radians(270), radians(0)). Following this clockwise convention, I would expect this to start at the top (270) and finish at the right (0), hence drawing the top-right cuadrant of the circle. However, it draws exactly the opposite using the same star/end points, which are the other three quadrants, like if it used clockwise to define the angles and counterclockwise to draw the arc.

This is different from, let's say, dc.DrawArc(x, y, radius, radians(180), radians(270)), where the arc starts at the left (180) and ends at the top (270), but it keeps the clockwise direction, hence drawing just the top left quadrant.

My only explanation for this is that depending on the angle diff (<180),(>180) it takes one direction or the other, but this all looks counter-intuitive to me. My expectations on the function had been taking the angles as defined in Maths, hence always using the counterclockwise direction, for both angle positioning and direction of the arc.

99% this is me not understand some Mathematics concept behind it, so an explanation would be very helpful, as the underlying code for DrawEllipticalArc doesn't easily tell me what's going on either - because I don't understand the Maths behind it! -

Thank you!