# Tessellate a plane

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

## Recommended Posts

Hi everyone, could anyone please tell me how can I tessellate a plane. I have the start and end position of the plane, so I need the width and height as well to divide them by the number of sub items. but I don't know how!!!

##### Share on other sites
Do you mean a plane as in "airplane?" If so, how is it represented in memory?

Or do you mean a plane as in the infinite affine variety of dimension 2? If so, what do you mean by start and end position of an infinite surface?

And what items, precisely, are you talking about? Polygons?

##### Share on other sites
Hi ToohrVyk,
tnx for the reply, well by plane I mean a rectangle, so it's not infinite which I store the information in 3D so the start position could be 1,0,0 and the end position could be 1,1,1. I also have the normal to that surface. by the way, all the rectangles are aligned to one of the X,Y or Z axis.

##### Share on other sites
Can you determine what the other two corners of the rectangle are? There are many possible rectangles for a given diagonal, even within a plane.

##### Share on other sites
No, but that's why that I have the normal for it.

##### Share on other sites
Quote:
 Original post by jeff_rowaNo, but that's why that I have the normal for it.
Given two corners and a normal, you can create a coordinate system for the rectangle. Furthermore, if the rectangle is a square, you can uniquely determine the other two corners.

Anyway, perhaps you could explain what you're really trying to do (billboards? debug graphics?). We'd be able to give you better advice that way.

##### Share on other sites
Hi jyk
tnx for the reply, well I want to draw a rectangle in openGL and I'm reading from a data file which has only the startPosition and endPosition and the normal to that surface. They may make a square with Width and Height equal or maybe not. but the point is that these positions are in 3D.

##### Share on other sites
Do the 'start and end positions' have to be corners of the rectangle? Or could they be points midway along opposite sides? (If the latter, the problem is fairly easy to solve.)

##### Share on other sites
Those points are the opposite corners of the rectangle.

##### Share on other sites
to illustrate it

D-----------------------C
| |
| |
| |
| |
| |
A-----------------------B

I have position of A and C.

##### Share on other sites
Quote:
 Original post by jeff_rowato illustrate itD-----------------------C| || || || || |A-----------------------BI have position of A and C.

It's not solvable. Even with the normal, there are an infinite number of rectangles you can have in that plane given the diagonal there. I mean, just taking your diagram:

                    ---D                 --/    C              --/   /---          ---/   /--           --/    /--           --/    /--           --/    /--             A    /--                 B---

Same diagonal, same plane, different rectangle.

##### Share on other sites
Quote:
Original post by superpig
Quote:
 Original post by jeff_rowato illustrate itD-----------------------C| || || || || |A-----------------------BI have position of A and C.

It's not solvable. Even with the normal, there are an infinite number of rectangles you can have in that plane given the diagonal there. I mean, just taking your diagram:

                    ---D                 --/    C              --/   /---          ---/   /--           --/    /--           --/    /--           --/    /--             A    /--                 B---

Same diagonal, same plane, different rectangle.
He does have the dimensions as well, which reduces it to two choices (and it's possible that could be disambiguated further by other contraints, such as axis alignment or winding).

Still, this seems like a pain. So to the OP, I'll ask again: what is this for exactly, and why this representation? There are a number of other representations for a rectangle in 3D that would be much more convenient.

##### Share on other sites
tnx guyz for your replies, but could you please tell me what's the best way of representing 3D rectangle?
cos I think by having two points which are the opposite corners and a normal to that surface you should be able to define that rectangle.

##### Share on other sites
Quote:
 Original post by jeff_rowacos I think by having two points which are the opposite corners and a normal to that surface you should be able to define that rectangle.
Nope. As noted previously, in the absence of additional information there is an infinite number of solutions. Knowing the dimensions of the rectangle makes the number of solutions finite, but there is still ambiguity.

A better representation would be a center point and two orthonormal basis vectors (a coordinate frame), and the dimensions (width and height). Other variations of this that offered essentially the same information would work as well.

##### Share on other sites
Quote:
 Original post by jeff_rowa... by the way, all the rectangles are aligned to one of the X,Y or Z axis.

I think he means it's an axis aligned rect.

##### Share on other sites
yeah, exactly, I meant a rectangle with angles equal 90 degrees.

##### Share on other sites
Quote:
 Original post by jeff_rowayeah, exactly, I meant a rectangle with angles equal 90 degrees.
That's not what 'axis aligned' means; 'axis aligned' means aligned with the global/world (cardinal) axes.

##### Share on other sites
oh, sorry :)
I think I found a way for solving it, by having opposite corners and knowing the angle is 90 and the normal:
since normal is always one of the i,j or k vectors, it should looks like as if rectangle is drawn in 2D. So for instance if one corner is 0,0,0 and the other is 1,1,0 there should be a way to calculate the two other points which are 1,0,0 and 0,1,0.
cos the normal is also 0,0,1

##### Share on other sites
I think it's solveable only if you're saying it's a square, not a rectangle.

Consider the 2d case:

In the upper row you clearly see that you can form several rectangles from the same two points.
In the lower row you see that you can only build one square from two points.

It works exactly the same in 3d but with the exception that you need a normal to define the plane, otherwise you'll have an infinite number of squares rotated arounf the axis formed by the two points.

##### Share on other sites
Hi eq,
tnx for your reply, yeah I meant square, sorry about my english guyz!!, so by saying that I want to draw a square, how can I calculate the other two points based on the other two points that you marked in your diagram and the normal in 3D.

##### Share on other sites
Ok, I'll give it a go.

I denote the two known points A and C, thus the objective is to find two points B and D that forms a square together with A and C.
Further more I call the normal N and assumes that this is a normalized normal (important).

B = (((A - C) x N) + A + C) * 0.5
D = C - B + A

Please note that you need to try out what B or D means for you, depending on how your normal is pointing and how your cross product (x) is defined.
Simply swap B and D if the results seem wrong.

Edit: Found and corrected a typo in the formula above.

Actually wrote the code and tested it, with my SSE enabled math library it looks like this:

voidmakeSquare(Vec3& b, Vec3& d, const Vec3& a, const Vec3& c, const Vec3& n){	b = ((a - c).cross(n) + a + c) * Vec3::m_half;	d = c - b + a;}Vec3 b, d;makeSquare(b, d, Vec3(0.0f, 0.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f), Vec3(0.0f, 0.0f, 1.0f));// b = {0, 1, 0}// d = {1, 0, 0}

[Edited by - eq on November 24, 2006 9:08:56 AM]

##### Share on other sites
hi eq,
tnx for your reply again, could you please explain how did u get that formula? or why B = ((a-c) X n + a + c) X n/2.
Regards,

##### Share on other sites
Once you know and understand the definition of cross product, the code is self-explanatory.

##### Share on other sites
well I know the definition of cross product, a X b = ||a|| * ||b|| * sin(Θ) but still I don't understand the formula!!

##### Share on other sites
Here is what I think is the explanation but correct me guyz if I'm wrong.
(a-c) X n gives us another vector which is ac' and has 90 degrees with ac and by adding a+c we can get ab so we can get b, but why do I have to divide it by n/2?