Jump to content

Trying to determine if vector point is within an area.


Guest
 Share

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

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

Recommended Posts

I am trying to figure out how to detect if an avatar X and Y location is within an L shaped area.  I've seen it done before but curious on how this is being done.

 

list protect_x = [233.365100,223.688900,223.688900,228.208000,228.208000,233.365100];
list protect_y = [214.940700,214.940700,208.975000,208.975000,204.834500,204.834500];
vector getPos(key owner)
{
vector pos = llList2Vector(llGetObjectDetails(owner, [OBJECT_POS]),0);
return pos;
}

default
{
touch_start(integer total_number)
{
key id = llDetectedKey(0);
vector pos = getPos(id);
llOwnerSay("Your current position: "+(string)pos);
float x = (float)pos.x;
float y = (float)pos.y;
llOwnerSay("X: "+(string)x+" Y: "+(string)y);
integer len = llGetListLength(protect_x);
integer i = 0;
integer j = 1;
integer G = FALSE;
while (j < len)
{

if (x > llList2Float(protect_x,i) && x < llList2Float(protect_x,j) && y > llList2Float(protect_y,i) && y < llList2Float(protect_y,j))
{
G=TRUE;
}
++i;
++j;
}
if (G == TRUE) { llSay(0,"You're in protected area");} else { llSay(0,"You're not in protected area");}
}
}

 

The area is an L shaped area.  Just really hung up on this one :\

Link to comment
Share on other sites

Last time I encountered this problem it was very simple. I had to find out if the point x, y was within a 2D rectangle. While I was digging for that, I found several more complex situations, such as finding out if a point is within a 2D polygon, if a line passes through (or just in) an n-sided polygon, etc.

I'm sure a Google search can help you find the math you're looking for.

A search led me here:

http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

This looks like a 2D test. But it could be modified to run multiple times. Four, I think, with two sides of each rectangle making up the L shape would do the job.

Math is not my strong suit. Especially not 3D math. Something I'm still learning. But the problem you're seeking the answer to is not new, and has been documented countless times. Finding the math for it is just a matter of finding the official terminology used to describe such a situation.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4008 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
 Share

×
×
  • Create New...