# Elevation of a child prim? (a.k.a. rotations are boggling my head)

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

I need to get the elevation of a child prim's y-axis; that is, the angle (a single floating point number) between the child's y-axis and the global horizontal plane.

Both the root and child prim can be rotated arbitrarily and independently and the script needs to be in the child prim.

I've been trying to figure this out for days (once upon a time I could have done it in my head in no time, but not any more. Such is life.)

I know that if I just wanted the root prim's y-elevation, I could use llRot2Left, followed by using Pythagorus' theorem on x and y then atan on that result with z to get the elevation of the root's y axis. I can't help feeling there should be a better, built-in way though.

But moving that to a child prim with a rotated root is causing what's left of my brain to melt.

##### Share on other sites

Try this:

`rotation gr = llGetRot();vector y = llRot2Left( gr);vector vertical = <0.0, 0.0, 1.0>;float cosinus = y*vertical;float angle_to_vertical = llAcos( cosinus);float angle_to_horz_plane = PI_BY_TWO - angle_to_vertical;`

This is not debugged I will trust you to do that

:smileysurprised::smileyvery-happy:

##### Share on other sites

Thank you very much for that!

I had just figured it out myself a few seconds before coming back here, although mine still used my square,square-root,atan method. Yours looks simpler to compute and gives exactly the same results as mine. (ETA: by which I mean yours is better )

My mistake was thinking that using llRot2Left on a child prim was going to be more complicated than on the root prim because the wiki says it gives a result relative to the parent. So, I've been going round and round in circles in my head trying to figure out how to deal with that and having failed attempts.

Maybe I'm misunderstanding the wiki, but it seems to work on a child prim without any further fiddling due to root offset. Hence just using it as above works, as I  just found out.

##### Share on other sites

Is there a more efficient way to calculate the corresponding azimuth (expressed as a rotation; should only have components in the horizontal plane) than what I have now? I'm using this:

`vector V=llRot2Left(gLinkRotation); // gLinkRotation is the child's global rotationfloat AzAngle=PI_BY_TWO+llAtan2(V*<0.0,1.0,0.0>, V*<1.0,0.0,0.0>); // Fixed offset for child's -y 'forward'rotation Azimuth=llEuler2Rot(<0.0, 0.0, AzAngle);`

I can then use the azimuth rotation to project along the child's negative y-axis direction in the horizontal plane.

##### Share on other sites

Slightly:

```vector V=llRot2Left(gLinkRotation); // gLinkRotation is the child's global rotation
float AzAngle=PI_BY_TWO+llAtan2(V.y, V.x); // Fixed offset for child's -y 'forward'
rotation Azimuth=llEuler2Rot(<0.0, 0.0, AzAngle);```

You don't need to perform a dot product to get the vector components

:smileysurprised::smileyvery-happy:

##### Share on other sites

D'uh! Of course, I do know that. It's not like I haven't done it before. I've got myself tied up in knots with this and doing silly things

Thank you once again.

It's all working perfectly now. It's a vehicle-mounted but independently pointable gun turret (think artillery, hence the alt-azimuth stuff), using llCastRay to better determine what should happen at the business end of the projectile.

I've just today realised that llCastRay is limited to within the sim; I've been reading the wiki Talk. That's a real shame because the battles can easily cross sims and the gun's useful range is well over 256m. At least my thing works well inside the sim. Outside... it's more fire-and-hope (as it was without llCastRay).