Check this!
Posted: Wed Aug 30, 2017 10:08 am
I made this function without really understanding what I was doing... Anyway, this function returns the smallest rotation needed to get from one angle to another, instead of using angle1 - angle2, even if they are like -3.06 and 2.5 (Algodoo would normaly go all the way from -3.06 to 2.5, but rotating in clockwise is a better option for something like angvel), this function has a range of -2π to 2π, anything else will fail. It's not finished as I can't input higher values by now.
Mr. Code
You can test it on a circle with with...
Mr. Code
- Code: Select all
angularDistanceOrWhatever := (an, gle)=>{
a := 0;
b := 0;
an > math.pi ? {
a = an - math.pi * 2
} : {
an < - math.pi ? {
a = an + math.pi * 2
} : {a = an}
};
gle > math.pi ? {
b = gle - math.pi * 2
} : {
gle < - math.pi ? {
b = gle + math.pi * 2
} : {b = gle}
};
x := a - b;
y := -(b - a - math.pi * 2);
z := -(b - a + math.pi * 2);
(x ^ 2) ^ 0.5 < (y ^ 2) ^ 0.5 ? {
(x ^ 2) ^ 0.5 < (z ^ 2) ^ 0.5 ? {x} : {z}
} : {
(y ^ 2) ^ 0.5 < (z ^ 2) ^ 0.5 ? {y} : {z}
}
}
You can test it on a circle with with...
- Code: Select all
postStep = (e)=>{
yeah := app.mousepos - pos;
angvel = - _dist(angle - math.pi / 2, - math.aTan2(yeah(0), yeah(1)))
}