Working on tower lean - could use some trig help!

General hangout discussion area for other non-printing stuff
User avatar
626Pilot
ULTIMATE 3D JEDI
Posts: 1716
Joined: Tue May 14, 2013 12:52 pm

Re: Working on tower lean - could use some trig help!

Post by 626Pilot »

Polygonhell wrote:You use the X and Y portions of the vector as the inputs to the annealer rather than the angles, you compute Z as sqrt(X*X + Y*Y).
If you want to clamp X and Y to reasonable values you clamp them to the sin of the desired angle so for say +/- 10 degrees you's clamp abs(X) and Y to be < 0.17364817766

Your optimizer should end up with approximate tower vectors, but you need to phrase the other math in terms of the tower vectors rather than the angles, I suspect that you will find the other math turns out easier/cheaper without the angles. All the sin/cos stuff just goes away and you end up with a bunch of dot and cross products instead.

What this doesn't let you do is deal with tower rotation in addition for that you need to use a quaternion, the trivial explanation of a quat is it's basically equivalent to a rotation about an arbitrary axis, and in fact toy can trivially compute one from that, but that's a somewhat toy explanation.

When I worked in games we always said if you deal with geometry and convert it to angles to solve a problem you're doing it wrong.
Okay. Do you have any suggestions for how I might turn two lean-angles into a quaternion, and then use that to project points on the line? I don't want to make the annealer find the solution itself. It's more precise my way, and the annealer already has enough wildcard variables to solve for.
User avatar
626Pilot
ULTIMATE 3D JEDI
Posts: 1716
Joined: Tue May 14, 2013 12:52 pm

Re: Working on tower lean - could use some trig help!

Post by 626Pilot »

I found some source code to turn angles into a quaternion:

Code: Select all

public final void rotate(double heading, double attitude, double bank) {
    double c1 = Math.cos(heading/2);
    double s1 = Math.sin(heading/2);
    double c2 = Math.cos(attitude/2);
    double s2 = Math.sin(attitude/2);
    double c3 = Math.cos(bank/2);
    double s3 = Math.sin(bank/2);
    double c1c2 = c1*c2;
    double s1s2 = s1*s2;
    w =c1c2*c3 - s1s2*s3;
    x =c1c2*s3 + s1s2*c3;
    y =s1*c2*c3 + c1*s2*s3;
    z =c1*s2*c3 - s1*c2*s3;
}
I suppose I would use X and Y lean as "heading" and "attitude", and for the bank, the Z axis, which I suppose would be 90. Does that look right?
Polygonhell
ULTIMATE 3D JEDI
Posts: 2417
Joined: Mon Mar 26, 2012 1:44 pm
Location: Redmond WA

Re: Working on tower lean - could use some trig help!

Post by Polygonhell »

The code looks right, I'd pick my axis so that a perfectly aligned tower is at 0 degrees offset in in all 3 or Roll Pitch and Yaw. i.e. it's the identity Quat (1,0,0,0).
Post Reply

Return to “The Lounge”