Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Math & Shapes & Points

Zor Zeddmore
Registered User
Join date: 13 May 2006
Posts: 87
02-24-2007 04:34
I need to figure out if a point is within a given polygon, by points.

From what iv researched, you can figure this out by doing some angle math.
However I havent been able to get this to work correctly.

Anyone know what I'm doing wrong?

CODE

list positions =[
<51.47958, 35.27858, 80.32906>,
<51.47958, 35.27858, 83.15882>,
<51.47958, 48.38833, 80.32906>,
<51.47958, 48.38833, 83.15882>,
<60.99294, 48.42350, 80.32906>,
<60.99294, 48.42350, 83.15882>,
<60.99294, 35.27858, 80.32906>,
<60.99294, 35.27858, 83.15882>
];
vector target = <61.62799, 42.75370, 81.86267>;

float EPSILON = 0.0000001;

float MODULUS(vector p){
return llSqrt(p.x*p.x + p.y*p.y + p.z*p.z);
}

float CalcAngleSum(vector point){
integer i;
integer n = llGetListLength(positions);
float m1;
float m2;
float anglesum=0;
float costheta;
vector p1;
vector p2;
for (i=0;i<n;i++) {
vector p = llList2Vector(positions,i);
p1.x = p.x - point.x;
p1.y = p.y - point.y;
p1.z = p.z - point.z;
vector pp = llList2Vector(positions,(i+1)%n);
p2.x = pp.x - point.x;
p2.y = pp.y - point.y;
p2.z = pp.z - point.z;

m1 = MODULUS(p1);
m2 = MODULUS(p2);
if (m1*m2 <= EPSILON)
return(TWO_PI);
else
costheta = (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z) / (m1*m2);

anglesum += llAcos(costheta);
}
return anglesum;
}
_____________________
Sterling Whitcroft
Registered User
Join date: 2 Jul 2006
Posts: 678
02-24-2007 05:55
Does it work if the test 'Target' is INSIDE the space?
Zor Zeddmore
Registered User
Join date: 13 May 2006
Posts: 87
02-24-2007 06:45
the results are wrong regardless if its inside the space or out.
_____________________