point in triangular mesh

Software: Away3D 3.x

jagguy, Newbie
Posted: 18 June 2011 09:24 AM   Total Posts: 27

hi,

I have a half cube shape mesh (3D right angled triangle shape) and is there a way to detect if a point lies inside this shape?

I can easily if a point lies inside its 3D bounding box but I need to test if the point lies inside the object.


in flash 2d you have a way to detect alpha.

   

Stephen Hopkins, Sr. Member
Posted: 18 June 2011 11:41 AM   Total Posts: 110   [ # 1 ]

You can do this for each face in the mesh:
http://forums.anandtech.com/showthread.php?t=162930

If all the dot products are negative, then its inside your mesh (assuming your mesh normals face outwards)

 Signature 

http://www-scf.usc.edu/~shopkins

   

jagguy, Newbie
Posted: 18 June 2011 12:50 PM   Total Posts: 27   [ # 2 ]

i really need to see an example.

I just need to test on the sloping face of the mesh and a point.

i just spent 2 hours on vector math hell with a line and point and in the end the mathematics didnt work

   

Stephen Hopkins, Sr. Member
Posted: 18 June 2011 09:19 PM   Total Posts: 110   [ # 3 ]
var testPoint:Vector3D = ...
for 
each face in mesh
 
var normal:Vector3D face.normal;
 var 
position:Vector3D face.v0;
 
//the plane and the testPoint need to be in the same space, this moves the plane to the origin
 //the transformedPoint is now relative to the plane
 
var transformedPoint:Vector3D testPoint.subtract(position);
 var 
dot:Number transformedPoint.dotProduct(normal);
 if(
dot >= 0)
  
//point on plane, or on same side of normal
 
else 
  
//point on opposite side of normal 

You are gonna have to figure out how to get faces, vertices, and normals.

 Signature 

http://www-scf.usc.edu/~shopkins

   

jagguy, Newbie
Posted: 19 June 2011 03:52 AM   Total Posts: 27   [ # 4 ]

looks like I am doing everything manually.

i will find the suface that is on a slope for right angled triangle 3d Shape (the longest side).

now the slope is at a 45 deg angle .

4 points around this rectangle surface is
A(0,0,0)
B(200,0,0)
C(200,71,71)
D(0,71,71)

V1 vector1= B - A (200,0,0)
V2 vector2=C - A (200,71,71)

cross product vector1 X vector2

cross product x= v1.y X v2.z - v1.zX v2.y = 0X71 - 71X0= 0
cross product y= - (( v2.z X v1.x) - (v2.x X v1.z)) = - 71X200 -0= -14200
cross product z= v1.x X v2.y - v1.y X v2.x= 14200

(0,-14200,14200) is normal so normalize i get

20081 = normalize factor


(0, -.707, .707) = normal vector for this shape


now since y value is negative the normal points down but i want it to point up dont I out of the surface?

   

Stephen Hopkins, Sr. Member
Posted: 19 June 2011 07:30 AM   Total Posts: 110   [ # 5 ]

swap v1 and v2 in your cross product

If you have an actual away3d mesh, there should be a way to access vertex data or faces, at least there was a way in 3.6, not sure about in broomstick.

 Signature 

http://www-scf.usc.edu/~shopkins

   

Avatar
Alejandro Santander, Administrator
Posted: 19 June 2011 07:40 AM   Total Posts: 414   [ # 6 ]

I have an article on OBB on my site that might help: http://www.lidev.com.ar/obb-collision-detection/
obb = oriented bounding box
aabb = axis aligned bounding box

What matters to you is the method of separating axes.

   
   
‹‹ overlapping ground

X

Away3D Forum

Member Login

Username

Password

Remember_me



X