I have two 3-d vectors like topLeft = (x0, y0, z0) and bottomRight = (x1, y1, z1) and I want to find the other two 3-d vectors that would make these two points form a 2-d quad in 3-d space.
In 2 dimensions I can easily figure out the x and z values for the other 2 vertices, but I am stuck in 3-d trying to figure out what the y-value (up-value) of the missing two vertices should be.
So in 2-d (x moving from left to right and z moving from top to bottom), the other rectangle points are:
topLeft = (x0, z0)
bottomRight = (x1, z1)
topRight = (x1, z0)
bottomLeft = (x0, z1)
If I move this into 3-d space (y moving up-down), how do I figure out the correct y-values for the 3rd and 4th vertex, assuming I am provided differing y-values for vertex 1 and 2?
I know this quad lays on a plane in 3-space but I'm not sure which one.
Given two 3-d vectors defining a 2-d quad in R3 how can I find the other 2 vertices?
You need more information than just two points. Two points only confine the other two other points to circles in 3d space. To define a plain in 3d you need 3 points or something equivalent.
[Edited by - japro on December 14, 2010 6:14:58 AM]
[Edited by - japro on December 14, 2010 6:14:58 AM]
OK ... that makes sense ... what if the third point was (0, 1, 0)? Could I find the plane then?
I guess the most elegant form to define a plane is with a normal and a point on the plane. If you have three points in the plane (A,B, C) you can easily obtain the normal by calculating the cross product:
N = CrossP(B-A. C-A)
and normalize N for convenience (the following depends on N being normalized!).
Now, if say AB is one of the edges (with direction E1 = B-A) of you quad you can calculate the perpendicular edge direction (E2) in the plane with another cross product:
E2 = CrossP(N, E1)
Now you can calculate the other points of the quad by linear combination of E1 and E2.
So the points are:
{A, A + E1, A + E1 + E2, A + E2}
I hope this helps
N = CrossP(B-A. C-A)
and normalize N for convenience (the following depends on N being normalized!).
Now, if say AB is one of the edges (with direction E1 = B-A) of you quad you can calculate the perpendicular edge direction (E2) in the plane with another cross product:
E2 = CrossP(N, E1)
Now you can calculate the other points of the quad by linear combination of E1 and E2.
So the points are:
{A, A + E1, A + E1 + E2, A + E2}
I hope this helps
Thanks for the help Japro. Here's what I've got so far:
I'm having trouble correctly selecting the assignment of vectors for A, B, C. With what I have above ... the generated quads are extremely large and don't fit in my world. My topLeft and bottomRight vectors are in world space.
std::vector< D3DXVECTOR3 > verts; std::vector< IndexFormat > indices; D3DXVECTOR3 A, B, C, E1, E2, N; A = D3DXVECTOR3( 0, 1, 0 ); B = topLeft; C = bottomRight; // N = Normalize(Cross( B- A, C - A )) D3DXVec3Cross( &N, &D3DXVECTOR3( B - A ), &D3DXVECTOR3( C - A ) ); D3DXVec3Normalize( &N, &N ); E1 = B - A; // E2 = Cross( N, E1 ) D3DXVec3Cross( &E2, &N, &E1 ); // // Generate a quad between topLeft and bottomRight. // // // First triangle // verts.push_back( A ); verts.push_back( A + E2 ); verts.push_back( A + E1 + E2 ); // // Second triangle // verts.push_back( A ); verts.push_back( A + E1 ); verts.push_back( A + E1 + E2 ); indices.push_back( 0 ); indices.push_back( 1 ); indices.push_back( 2 ); indices.push_back( 3 ); indices.push_back( 4 ); indices.push_back( 5 );
I'm having trouble correctly selecting the assignment of vectors for A, B, C. With what I have above ... the generated quads are extremely large and don't fit in my world. My topLeft and bottomRight vectors are in world space.
Whoop, I didn't realize you had the diagonal of the quad and not an edge. I guess in your case
E1 = 0.5*(B-C + cross(B-C, N))
and
E2 = 0.5*(B-C - cross(B-C, N))
should do it.
Also the linear combinations should possibly "start" at C in this case:
C+E1, C+E1+E2 etc.
E1 = 0.5*(B-C + cross(B-C, N))
and
E2 = 0.5*(B-C - cross(B-C, N))
should do it.
Also the linear combinations should possibly "start" at C in this case:
C+E1, C+E1+E2 etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement