# Construct a plane from 3 points

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

## Recommended Posts

I'm attempting to construct a plane from 3 points for my raytracer, and wanted to check that my code is correct. I can construct a plane from a normal and a distance along that normal to the origin, which renders fine, however when constructing a plane from 3 points, nothing is rendered at all. I'm guessing I end up with an invalid plane, so I wanted someone to check over my code and tell me if I'm still sane.
RTPlane::RTPlane(const Vector3f &A, const Vector3f &B, const Vector3f &C, const RTMaterial &material)
{
mMaterial = material;

Vector3f v1 = B - A;
Vector3f v2 = C - A;

mNormal = (v1.cross(v2)).normalise();

mDistance = mNormal.dot(A);
}

The points are wound in a clockwise order.

##### Share on other sites
The only thing I can find is that the distance calculation is incorrect. You should not normalize before the dot product.

##### Share on other sites
Thanks for the advice, but it doesn't seem to be making any difference.

A = (-1, -1, 0)B = (1, -1, 0)C = (1, 1, 0)mDistance = 0mNormal = (0, 0, 4) //(0, 0, 1) normalised

As a sanity check I've got another plane with the same coords in reverse winding order...

A = (1, 1, 0)B = (-1, -1, 0)C = (1, -1, 0)mDistance = 0mNormal = (0, 0, 4)

Are these values correct? If that's not the problem then I'm beginning to wonder whether or not my ray-plane intersection algorithm fails horribly on any plane that isn't facing straight up or down (something which I have yet to test :S)

edit: ray-plane intersection definitely performs as expected.

##### Share on other sites
Nevermind, all appears to be good now. I'll test it a bit more and come back later if I have any further trouble. Thanks jpmcmu :)

##### Share on other sites
Then length of the normal is irrelevant as long as you satisfy the equation Ax + By + Cz + D = 0, which will always be the case so long as you calculate the distance after the normal. By convention though normals are unit length, which is where the normalization comes in. You should not, however, modify the normal after the distance is calculated or else your plane definition will be incorrect. If you rearrange the equation as Ax + By + Cz = -D, then you can see that if the normal (A,B,C) changes, D must change accordingly to maintain equality.

Long story short, if you modify the normal you must recalculate the distance to maintain correctness. Everything else isn't mathematically necessary, including unit normal length.

##### Share on other sites
So I should be performing a normalisation before calculating the distance afterall?

##### Share on other sites
Quote:
 Original post by _Sauce_So I should be performing a normalisation before calculating the distance afterall?
If you're going to normalize, you should normalize before calculating the distance. (As for whether or not you *need* to normalize the plane normal, that depends on what you'll be doing with the plane exactly.)

##### Share on other sites
Quote:
 Original post by _Sauce_So I should be performing a normalisation before calculating the distance afterall?

Absolutely. Remember that another definition of the dot product is:

A·B = |A||B|cos(Θ)

If one of your input vectors has a large magnitude, then your dot product would also be quite large if the vectors were relative parallel. After the normalization, you still have this gigantic distance simply because one of the input vectors had a large magnitude and has nothing to do with the new normal.

##### Share on other sites
Quote:
Original post by jyk
Quote:
 Original post by _Sauce_So I should be performing a normalisation before calculating the distance afterall?
If you're going to normalize, you should normalize before calculating the distance. (As for whether or not you *need* to normalize the plane normal, that depends on what you'll be doing with the plane exactly.)

I'll be using the normals for lighting, so yes it's important :)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631428
• Total Posts
3000027
×