Function to determine angle?
|
|
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
|
04-01-2008 18:43
I'm not certain I even need this, but just wondering.
And I hate trig in grade 12 and now I'm paying for it.
I have two z points. one is low, and is high. And, I know how far apart they are.
So how can I figure out in SL the angle from the low to the high?
(something to do with picturing them in a right triangle, and working with opposite/adjacent sides??
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
04-01-2008 19:11
I think you need to describe the problem with a little more detail.
_____________________
So many monkeys, so little Shakespeare.
|
|
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
|
04-01-2008 19:39
From: Lee Ponzu I think you need to describe the problem with a little more detail. Sample heights / distances Cable car rising on an inclined cable. Starts at 0 metres height, it's stop is say at 50 metres height, 100 metres away in a straight line. Want to work out angle of incline. Maybe I don't need it though, might not do anything for me. A friend made some groovy looking cable cars, and asked if I'd make some scripts to drop in, but this is turning out to be a heavy job. I probably should do this as a vehicle, but if so then I'll have to drop the project as have pre-commitments and no time right now to learn vehicles.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-01-2008 20:57
float angleOfIncline(vector p1, vector p2) { vector delta = p2-p1; return llAsin(delta.z, llVecMag(delta)); }
Note that if p2 is below p1, this will return a negative angle. You could always use llFabs() if that's not what you want. Also note that the returned angle is in radians, and you should multiply by RAD_TO_DEG if you want to change it to degrees.
|
|
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
|
04-02-2008 07:24
From: Hewee Zetkin float angleOfIncline(vector p1, vector p2) { vector delta = p2-p1; return llAsin(delta.z, llVecMag(delta)); } Note that if p2 is below p1, this will return a negative angle. You could always use llFabs() if that's not what you want. Also note that the returned angle is in radians, and you should multiply by RAD_TO_DEG if you want to change it to degrees. Thanks Hewee. Sadly, the function won't compile cause llAsin(float val) only takes 1 value. And I can't figure out how you wanted to join "delta.z, llVecMag(delta)" into one value, though I suspect that's an essential part of the magic. So sorry to bother you, but I wonder if you could just check to see if you made a typo?
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-02-2008 10:00
From: Chaz Longstaff Thanks Hewee. Sadly, the function won't compile cause llAsin(float val) only takes 1 value. And I can't figure out how you wanted to join "delta.z, llVecMag(delta)" into one value, though I suspect that's an essential part of the magic. So sorry to bother you, but I wonder if you could just check to see if you made a typo? Oh. Gosh. Yes. I'm sorry. I use llAtan2() 95% of the time I do trig in LSL, so that's where my head was. float angleOfIncline(vector p1, vector p2) { vector delta = p2-p1; float len = llVecMag(delta); if (len < 0.001) { return 0.0; } return llAsin(delta.z/len); }
|
|
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
|
04-02-2008 10:18
From: Hewee Zetkin Oh. Gosh. Yes. I'm sorry. I use llAtan2() 95% of the time I do trig in LSL, so that's where my head was. Hey listen, no, that's great that you can do trig at all. For some reason my mind always soaked up classical Greek and Latin noun declensions like a sponge, but always short-circuited in trig.
|