Hello
I am writing a bit of programming code to draw an arc from point A to point B.
There is also a direction, this is defined as a unit vector tangent at the start point. So we always travel from one point to the other - the tangent vector defines clockwise or counterclockwise from the start point.
I have it working, but i have a bunch of "if" checks to fix the angles correctly so that i always get the result of A to B counterclockwise.
To visualise here is a gif attatched:
So you can see green and red swap in order to maintain counterclockwise direction (from green to red) this is dependant on tangent direction and quadrants the points lie in on the circle.
What i do to make sure the angles for both points are correct to create the arc is as follows:
Now this works, so i am not too worried if there is no answer, but i am wondering - is there a mathematical way to find angleA and angleB directly through math without using if check conditionals to make adjustments, which feels a bit like a band-aid - I would much rather a pure mathematical solution.
If it is possible how would it be done?
Thanks
I am writing a bit of programming code to draw an arc from point A to point B.
There is also a direction, this is defined as a unit vector tangent at the start point. So we always travel from one point to the other - the tangent vector defines clockwise or counterclockwise from the start point.
I have it working, but i have a bunch of "if" checks to fix the angles correctly so that i always get the result of A to B counterclockwise.
To visualise here is a gif attatched:
So you can see green and red swap in order to maintain counterclockwise direction (from green to red) this is dependant on tangent direction and quadrants the points lie in on the circle.
What i do to make sure the angles for both points are correct to create the arc is as follows:
Code:
//get signed angle from vector (A-O) and (B-O) to the (1,0) axis, around the normal UP axis (0,1)
//the result will never be greater than 180 degrees or smaller than -180 degrees
angleA = SignedAngle(a - origin, right, up);
angleB = SignedAngle(b - origin, right, up);
//fix the angles to make sure we traverse the arc counter clockwise correctly between the two angles
if (_isClockwise and angleB < angleA) angleB += 360;
else if (!_isClockwise and angleB < angleA) angleB += 360;
Now this works, so i am not too worried if there is no answer, but i am wondering - is there a mathematical way to find angleA and angleB directly through math without using if check conditionals to make adjustments, which feels a bit like a band-aid - I would much rather a pure mathematical solution.
If it is possible how would it be done?
Thanks