Sign in to follow this  
jeff_rowa

Tessellate a plane

Recommended Posts

jeff_rowa    136
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 this post


Link to post
Share on other sites
ToohrVyk    1595
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 this post


Link to post
Share on other sites
jeff_rowa    136
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 this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by jeff_rowa
No, 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 this post


Link to post
Share on other sites
jeff_rowa    136
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 this post


Link to post
Share on other sites
jyk    2094
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 this post


Link to post
Share on other sites
superpig    1825
Quote:
Original post by jeff_rowa
to illustrate it

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

I 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 this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by superpig
Quote:
Original post by jeff_rowa
to illustrate it

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

I 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 this post


Link to post
Share on other sites
jeff_rowa    136
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 this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by jeff_rowa
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.
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 this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by jeff_rowa
yeah, 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 this post


Link to post
Share on other sites
jeff_rowa    136
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 this post


Link to post
Share on other sites
eq    654
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 this post


Link to post
Share on other sites
jeff_rowa    136
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 this post


Link to post
Share on other sites
eq    654
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:


void
makeSquare(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 this post


Link to post
Share on other sites
jeff_rowa    136
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?


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this