# Plane on polygon

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

## Recommended Posts

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:

##### Share on other sites
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.

##### Share on other sites
I am creating polygons along each bsp split so that I can find portals between leaves.

##### Share on other sites
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?

##### Share on other sites
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)

##### Share on other sites
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?

##### Share on other sites
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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015570
×