Subject:
|
Re: Quad intersections
|
Newsgroups:
|
lugnet.cad.dev
|
Date:
|
Fri, 16 Apr 1999 20:11:56 GMT
|
Viewed:
|
777 times
|
| |
| |
John VanZwieten wrote:
>
> Based on Dave's formulae, I have been able to calculate the intersection of a
> plane (given three points) and a line (given two points). How do I then
> determine whether the point of intersection falls within a quad (as in Dave's
> "exercise left for the reader")?
Here's what I use, it works for triangles but you can easily change it
for a quad. The idea is to check the angles between the vectors formed
by each vertex and the point you're testing.
x,y,z: point
p1,p2,p3: vertex (float[3])
double pa1[3], pa2[3], pa3[3], a1, a2, a3;
pa1[0] = p1[0] - x;
pa1[1] = p1[1] - y;
pa1[2] = p1[2] - z;
Normalize(pa1);
pa2[0] = p2[0] - x;
pa2[1] = p2[1] - y;
pa2[2] = p2[2] - z;
Normalize(pa2);
pa3[0] = p3[0] - x;
pa3[1] = p3[1] - y;
pa3[2] = p3[2] - z;
Normalize(pa3);
a1 = pa1[0]*pa2[0] + pa1[1]*pa2[1] + pa1[2]*pa2[2];
a2 = pa2[0]*pa3[0] + pa2[1]*pa3[1] + pa2[2]*pa3[2];
a3 = pa3[0]*pa1[0] + pa3[1]*pa1[1] + pa3[2]*pa1[2];
double total = (acos(a1) + acos(a2) + acos(a3)) * RTOD;
if (fabs(total - 360) > 0.001)
return FALSE; // Outside triangle
And as Steve said "There's probably a more elegant solution, but this
one works". Don't know if this is a better way of doing things or not.
Leonardo
|
|
Message is in Reply To:
| | Re: Quad intersections
|
| Based on Dave's formulae, I have been able to calculate the intersection of a plane (given three points) and a line (given two points). How do I then determine whether the point of intersection falls within a quad (as in Dave's "exercise left for (...) (26 years ago, 16-Apr-99, to lugnet.cad.dev)
|
5 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|