point in 3d triangle
Blitz3D Forums/Blitz3D Programming/point in 3d triangle
| ||
Does anybody know how to determine if a 3d point is inside a 3d triangle ? |
| ||
Surely it would be a 2d point running across the 3d triangle? Or else, it would be verrrrrrrry difficult to get this answer, due to floating point in accuracies in 3d space. If you can imagine a triangle in 3d, and you wanted to click on the triangle and place a dot where the mouse hits (and only it it hits the triangle) Is this the kind of thing your after? If so, fredborg's picked U() and PickedV() commands are what you need. There might be something more suitable though. I'll check. |
| ||
look, in 2d what you need to do is that if you have function: PointInside(x,y,x1,y1,x2,y2,x3,y3) then you need to calculate the area of the triangles: (x,y)(x1,y1)(x2,y2) , (x,y)(x2,y2)(x3,y3) , (x,y)(x1,y1)(x3,y3) and if it equals to the area of (x1,y1)(x2,y2)(x3,y3) you can be sure it is inside the triangle. I'm tired and going to sleep, so I would look tomorrow if no one will answer you how to implement it in 3d. |
| ||
Should be pretty much the same man. You'll first need to convert the point into a 2d point relative to the triangle. |
| ||
Thanks very much for the idea! I've given a go at implementing it, using two functions from the archive by RaGR: *edit* Well .. it is usable, but it seems somewhat slow. If someone has a faster and/or better method for this, I would still like to know. |