Jump to content
Sign in to follow this  
Bloodsong Termagant

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

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.

https://www.quora.com/How-can-you-find-the-angle-of-line-by-using-its-slope

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

Quote

<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.

 

Share this post


Link to post
Share on other sites
Posted (edited)

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.

WAIT!

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...