Page 2 of 2

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

Posted: Tue Apr 07, 2015 9:54 pm
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.

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

Posted: Wed Apr 08, 2015 6:19 am
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?

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

Posted: Wed Apr 08, 2015 11:52 am
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).