Skip to main content
GameDev.net gamedev.net
🔒 Locked

Plane on polygon

Started by FlyingDodo Apr 5, 2006 at 12:18 AM 5 replies 1.4k views
Original Post
FlyingDodo
FlyingDodo
I have the following: 1: a plane define by a normal + d 2: a radius 3: a centre point I need to create a polygon made from 4 vertices which lie on the given plane, and so that the edges touch the edge of a circle with the given radius centred on the centre point. Like this:
Zakwayda
Zakwayda
Here's one way to do it:

1. Construct the quad in local space, e.g. in the xy plane, centered at the origin, with +z forward
2. Create an arbitrary orthonormal basis from the plane normal
3. Create an affine transform (e.g. using a 4x4 matrix) from the basis and the center point
4. Use it to transform the 4 vertices of the quad

The only non-trivial step is number 2, but it's fairly simple and can be done with a few cross products (ask if you need details). You might also describe what it is you're actually trying to do, because depending on what it is, the above may not be the best solution.
FlyingDodo
FlyingDodo
I am creating polygons along each bsp split so that I can find portals between leaves.
FlyingDodo
FlyingDodo
Could you please describe how I would create this matrix? I'm assuming once I have it I can just matrix multiply the vertices with it, right?
Niwak
Niwak
From my point of view, the easiest way is to directly create the orthonormal system based on the plane equation. Let's say N is the plane normal (assuming it's already normalized) ;

Zaxis = N
Xaxis = N x (1,0,0)
if (Xaxis squared length is too small) Xaxis = N x (0,1,0)
if (Xaxis squared length is too small) Xaxis = N x (0,0,1)
Yaxis = Zaxis x Xaxis

V1 = Plane Center + radius * (Xaxis + Yaxis)
V2 = Plane Center + radius * (Xaxis - Yaxis)
V3 = Plane Center - radius * (Xaxis + Yaxis)
V4 = Plane Center - radius * (Xaxis - Yaxis)
FlyingDodo
FlyingDodo
That seems to work fine, however I don't know what you mean by "if x axis squared is too short" what defines too short? Do you mean that if its total length is not equal to 1?
Niwak
Niwak
I have forgotten a line in my pseudo-code ;
Xaxis = N x (1,0,0) will result in a vector which is not normalized. You will have to normalize it and therefore perform a division by the norm of Xaxis. This is where things may go wrong if Xaxis norm is 0 or nearly 0.

If N is colinear with (1,0,0) the length of Xaxis will be 0.
To keep good precision, you should avoid the situations were you build your Xaxis from 2 colinear (or nearly colinear) vectors.

You have two solutions for this ;
- The one i described ; you just try with the base vector (1,0,0), (0,1,0) and (0,0,1) and as soon as you have found one which is not colinear with N, you use it.
- You can also decide that the vector you need is the one for which N as the smallest coordinates ; N = (0.1, 0, 0.9) => Xaxis = N x (0,1,0)

Hope it helps

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.