Check this!
3 posts • Page 1 of 1
Check this!
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)))
}
 Luezma
 Posts: 14
 Joined: Thu Dec 13, 2012 7:19 pm
 Location: Argentina
Re: Check this!
Too complicated.
I wrote whis one for my old AI battel scene:
I wrote whis one for my old AI battel scene:
 Code: Select all
angleDiff := (a1, a2)=>{
tau := (math.pi * 2);
d := (a1 % tau  a2 % tau) % tau;
d > math.pi ? {d  tau} : {d <  math.pi ? {d + tau} : {d}}
}
Dream of Algodoo as game development engine...

Kilinich  [Best bug reporter 2010]
 Posts: 2098
 Joined: Mon Aug 31, 2009 8:27 pm
 Location: South Russia
Re: Check this!
What does % do?
*edit* Ok I know what it does, and I can't believe how simple you made it...
*edit* Ok I know what it does, and I can't believe how simple you made it...
 Luezma
 Posts: 14
 Joined: Thu Dec 13, 2012 7:19 pm
 Location: Argentina
3 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest