# Given two 3-d vectors defining a 2-d quad in R3 how can I find the other 2 vertices?

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

## Recommended Posts

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.

##### Share on other sites
Can't you just define your points in the origin and translate/rotate?

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

##### Share on other sites
OK ... that makes sense ... what if the third point was (0, 1, 0)? Could I find the plane then?

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

##### Share on other sites
Thanks for the help Japro. Here's what I've got so far:

	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.

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

##### Share on other sites
Thank you japro - rating you up.