Jump to content

Trig! Slope to Angle Formula... Not Giving Expected Results

Bloodsong Termagant

You are about to reply to a thread that has been inactive for 1409 days.

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

Recommended Posts

so on my slope quest...


i have two coordinates, one that is right below my avatar, and one that is about 2 meters ahead of it.  these are raycast coordinates, shooting out from the avatar's center point.  anyway, i have gotten the formula that the angle of the slope  is Tan^-1 (slope).  and slope = (z2 - z1)/ (x2 - x1).

        vector p1 = llList2Vector(res1, 1);
        vector p2 = llList2Vector(res2, 1);
        float angle =  llPow(llTan(
                (p2.z - p1.z)/(p2.x - p1.x)
                ), -1);

so tangent of the slope to the -1 power.

i'm standing on a prim rotated at 45 degrees, and facing upslope.  but the angle keeps coming out to tiny numbers like -0.41267.  eh???

my brain is melted.


if you're nuts, these are some of the readouts i got:


<209.548500, 46.837690, 52.863240>
<210.040200, 45.872910, 53.828010>
slope tester: The angle came out to -0.412608 degrees.


yeah, i tried getting the normals, but... i don't think i can wrangle those into anything useful for my purposes.  i'm trying to see if the avatar is walking up or down a slope, and how steep it is.  the normal just gives me the angle of the prim surface, not any idea of which way im facing on it.


Link to comment
Share on other sites

hey, thanks, madelaine!


buuuuut, i'm having trouble.  i'm trying to get the angle from the slope.  which is the z difference divided by the x difference, which gives me one float.  the llAtan2 is looking for 2 floats.  annnnnnd i don't know what those are supposed to be? 

i tried using the z difference and the x difference in the formula, but i came out with 1.5 for the 45 degree slope.  hmm, in good news, facing down the incline gave me -1.5, so at least it's sensing direction...

and now a 30 degree slope is giving me bogus answers.


i'm sorry, this is why i'm an artist, not a mathematician!! :)


okay, the wiki page says it is dividing the two inputs.

i still don't get it.


further reading shows, that the fool thing is returning PI.  so.  RAD_TO_DEG to the rescue?  or is it that other fool thing.

should not post while in the middle of doing stuff.


okay, it's consistently coming out to be 12 degrees more than the angle i have the prim facing.  i'm not anticipating needing the exact angle, so that's good enough for me...  just weird.


Edited by Bloodsong Termagant
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1409 days.

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

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...