# Realtime Collision Detection - Method of creating Plane makes no sense to me

This topic is 3391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

For those of you who have the book: Realtime Collision Detection by Christer Ericson I am stuck on P194 where the book shows me how to create a Triangle struct with Planes. "For a triangle ABC, the triangle stucture tri can be initalized as follows." The lines of code I am having a problem with are:

tri.p = Plane(n, a);  // n = Normal, a = tri.a (Point A in the triangle)
tri.edgePlaneBC = Plane(Cross(n, c - b), b);
tri.edgePlaneCA = Plane(Cross(n, a - c), c);

From what I can understand is the code is telling me to create a Plane using a Normal and another parameter. I assumed it would probably be the D of the Plane but seeing as a, b and c are all Vector3's then that couldn't be possible as the D is always a float. I am not sure what that other parameter is though, can anyone please help me? Thanks guys.

##### Share on other sites
Here is how the constructor in question would likely be implemented (C++-ish pseudocode):
Plane::Plane(Vector3 normal, Vector3 point) :
normal(normal), distance(dot(point, normal))
{
}
For this form of a plane, we know that p.n = d, where n is the plane normal, d is the plane distance, and p is any point on the plane. If we have a point available that we know lies on the plane, we can compute the distance directly from this point and the plane normal using the aforementioned equation.

##### Share on other sites
hmmmmmm :) let me see
perhaps its a point on the triangle (eg one of the corners)

tri.p = Plane(n, a); // n = Normal, a = tri.a (Point A in the triangle) <- slight clue :)

##### Share on other sites
Yes, a,b, and c are the points of the triangle, n is the normal of the triangle which gets calculated from the part you removed:

Triangle tri;
Vector n = Cross(b - a,c - a);

n doesn't seem to be normalized, maybe its done in the Plane constructor/function.

What the code does is fill the Triangle structure consisting of the 3 perpendicular planes to the triangle normal that pass through the edges of the triangle (See figure 5.25 on page 193), in the book, it is used to get barycentric coordinates.

##### Share on other sites
I get you.

Would this be a correct implementation then (in C#):

public struct CD_Plane
{
private Vector3 normal; // Plane Normal. Points (x) on the Plane satisfy: Vector3.Dot(Normal, x) = D
private float d; // D = Vector3.Dot(Normal, p) for a given point (p) on the Plane

/// <summary>
/// Given 3 noncollinear Points [ordered Counter-Clockwise] compute the plane equation
/// (3 or more points are said to be collinear if they lie on a single straight line)
/// </summary>
/// <param name="a">Point 1 (As Vector3)</param>
/// <param name="b">Point 2 (As Vector3)</param>
/// <param name="c">Point 3 (As Vector3)</param>
public CD_Plane(Vector3 a, Vector3 b, Vector3 c)
{
this.normal = Vector3.Normalize(Vector3.Cross(b - a, c - a));
this.d = Vector3.Dot(this.normal, a);
}

/// <summary>
/// If we have a Point available that we know lies on the Plane.
/// We can compute the distance directly from this Point and the plane normal using:
/// distance = (Vector3.Dot(Point, Normal))
/// </summary>
/// <param name="normal">Plane Normal</param>
/// <param name="point">Point that lies on Plane</param>
public CD_Plane(Vector3 normal, Vector3 point)
{
this.normal = Vector3.Normalize(normal);
this.d = Vector3.Dot(this.normal, point);
}

public Vector3 Normal
{
get { return this.normal; }
}

public float D
{
get { return this.d; }
}
}

All feedback welcome.

##### Share on other sites
Yeah, seems correct enough, if you just want to calculate the plane equation of the triangle and not duplicate the functionality of the book's code sample that is.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007528
• ### Who's Online (See full list)

There are no registered users currently online

×