Define the arc to and from angles without conditionals

wduk

New member
Joined
Dec 11, 2016
Messages
46
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:

02GPuh2.gif


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
 
First, "if" is perfectly mathematical; look up "piecewise defined function"! So what you have is fine.

Second, I don't know what math is hidden inside SignedAngle, but the atan2 function in most programming languages serves a purpose similar to what you are looking for, determining the appropriate quadrant for an angle. I would expect that to be used inside SignedAngle, so probably what you want is beyond that.
 
Signed angle just gets the acute angle but also determines the winding order by making it negative or positive. Basically if its in Q1 or Q2 the signed angle will be between 0 and 180. If its in Q3 or Q4 the signed angle will be between -180 and 0.

Yes i'm aware of piece wise functions from Fourier studies but i was just wondering if the final angles can be calculated without piece wise approach since from a programming perspective, branching conditionals is not ideal especially for GPU programming due to the nature of the hardware.
 
Top