Check my maths theory?

(bits in bold are more to the point)

Okay I'm just going to explain it because I don't have any formulas/code for this new version of what I want to do.

The task is testing if a point in 3D space lies within an object (defined by a point array and index array to make triangles). So I'd read about collision detection before using planes to test if it's in front or behind the plane and for convex objects all triangles will need to be in front, blah, blah.

But I didn't understand any of it or any of the maths involved so struggled with it myself and basically came up with my own methods of achieving this. Currently I stand at sending the 3 points on the current plane in testing, and the test point(s) into a function which transforms the plane and points onto it's own (X,Y,Z) mapping system and simply testing if Z > 0 for being inside the shape.

Rotating the plane takes time and power though so just today I spent like 10 minutes thinking and came up with testing the angle between 2 lines, the normal of the plane, and any of the 3 plane points to the point in testing. My theory is that if the angle < (pi/2) then point is inside shape.

I suppose I've pointlessly rambled for quite a while but I wanted to ask if this new method is sound... And also to ask if anyone know's how I'd calculate the normal to the plane. I was worried that a cross product of 2 of the planes lines would create a normal in the opposite direction because I don't fully understand how it works mathematically.

Thanks guys
Last edited on
Well, do you have the direction vector for the plane?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vec3 norm( vec3 v1, vec3 v2, vec3 v3) {

    float Vx, Vy, Vz;
    float Ux, Uy, Uz;

    Ux = v2->x - v1->x;
    Uy = v2->y - v1->y;
    Uz = v2->z - v1->z;

    Vx = v3->x - v1->x;
    Vy = v3->y - v1->y;
    Vz = v3->z - v1->z;

    return normalize( vec3 (
                  Uy * Vz - Uz * Vy,
                  Uz * Vx - Ux * Vz,
                  Ux * Vy - Uy * Vx
                ) );
}


Since normal vectors are directional, it is necessary to do all calculations in the same manner. For instance, if a triangle's vertices are given to the formula in a counter clockwise fashion rather than clockwise, the resulting normal vector will point in the opposite direction.

http://www.tjhsst.edu/~dhyatt/supercomp/n310.html
Last edited on
testing the angle between 2 lines, the normal of the plane, and any of the 3 plane points to the point in testing. My theory is that if the angle < (pi/2) then point is inside shape.

Can you explain this a little clearer, I don't understand what you mean.
say that n is the normal to the plane
A is a point in the plane
and P is the point in testing

the test would be
angle(P-A, n) < pi/2

that's equivalent to
dot(P-A, n) > 0
@htirwin
Once I have the direction vector for the normal of the plane (position shouldn't matter) I'll find the angle between this normal, and the direction vector from one of the 3 points to the point in testing (shouldn't matter which point as they should all be <90 if the test point is behind plane)

Here I've redone my sketches on the PC, hopefully this should clear up what I'm wanting to do...
[link removed]
Last edited on
I've redone my sketches on the PC (very rough) but hopefully it should clear up what I'm wanting to do.
[link removed]

ABC is a plane of 3 points, D is the point to be tested whether it's in front or behind the plane, n is the normal to ABC.

I should be able to test for the angle between (n, AD) || (n, BD) || (n CD)

If the angle in testing (D) is in front of the plane then clearly AD, BD and CD all point in the opposite direction to n, so a test for the angle should return greater than half pi (or 90 degrees for n00bs XD ).
I'm testing for the angle using the dot product over the product of the magnitudes of the 2 vectors, which get's cos(a), then simply inverse it.

EDIT: Whoops, Sorry for the double post, it didn't show up for a long while some reason.
Last edited on
closed account (D80DSL3A)
I believe ne555 nailed it. htirwins code gives the normal vector.
Last edited on
Okay I think I've covered this enough to ensure that I can get things pointing in the right directions. Suppose I'll find out because it'll either sometimes work (when objects are colliding) or never work (cos it's broken) =D

Thanks guys.
Topic archived. No new replies allowed.