Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Geometric math help

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
06-29-2007 14:47
I'm trying to determine if an object lies within an arc defined by an angle about a vector (example, PI/2 around <1,1,0> from the point <1,2,3>;) without having to resort to a sensor. I know that I can use llSay to broadcast the originating point and the vector and have the object do some kind of math to give a yes/no answer, but I don't know exactly what the math is i need to perform.


to clarify the image: the blue is the origin, the red arc is the angle about the vector, the green arrow is the directional vector, and the yellow cone is what is defined by these, I just don't know how to do this mathematically and in the LSL language.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
06-29-2007 15:08
It should be pretty straightforward.


oriPos = llGetPos() of your origin
targetPos = llGetPos() of your target, which you're trying to find out whether it's in your arc

dirVector = vector, "directional vector" in your illustration
angle = float of your "angle about vector", in radians

now, if ( llRot2Angle( llRotBetween( dirVector, (targetPos - oriPos) ) ) < angle ), then you know you're in the arc

That should be roughly right

You'll probably need another "if" to make sure it's not "behind" your origin
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
06-29-2007 15:11
vector obj_position; // position of the object, in world coords
vector test_position; // position the object is being tested against, in world coords
vector test_pointer; // vector relative to test_position which is the center of the arc
float half_arc; // angle between test_pointer and edge of cone

vector relative = obj_position - test_position;

float dot = llVecNorm( relative ) * llVecNorm( test_pointer ); // dot product, i.e. consine of the angle between the two vectors, multiplied by their respective magnitudes. Vectors are first normalized, i.e. set to a magnitude of 1, so that only the cosine remains.

float angle = llACos( dot ); // get the angle from the cosine

if( angle <= half_arc )
// obj_position falls within cone
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
06-29-2007 15:13
From: Ged Larsen
It should be pretty straightforward.


oriPos = llGetPos() of your origin
targetPos = llGetPos() of your target, which you're trying to find out whether it's in your arc

dirVector = vector pointing in direction
angle = float of your "angle about vector", in radians

now, if ( llRot2Angle( llRotBetween( dirVector, (targetPos - oriPos) ) ) < angle ), then you know you're in the arc

That should be roughly right


ah! thanks! also thanks to Bryndyn Burton for helping me in world with the same solution :) I was approaching this by trying to create some kind of cone shaped bounding box more or less and hadn't thought about comparing angles between vectors.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.