Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / General Programming / draw equation of plane Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 14, 2005, 05:49 PM

i have an equation of a plane, and i am trying to draw it. it seems quite easy since i have the ax + by + cz + d = 0 equation, but the problem is that i don't have the x y z coordinates to draw the 4 vertices of the plane.

i different ways of just randomly picking the points, but that is not good since i cannot tell what type of plane equation i am given before hand, so i cannot calculate which points to use.

can anyone shed some light on this? thanx.

Victor Widell

March 14, 2005, 07:28 PM

How do you want to draw it?

Like a quad, or like a true infinite plane?


March 14, 2005, 08:59 PM

well i don't think it matters, i guess just a quad would be fine. i am just having trouble figuring out how to draw it not knowing the coordinates.


March 15, 2005, 12:35 AM

A plane is infinite so we can only draw part of a plane. It like saying drawing a ray. We can only draw a line segments that is part of a ray. What I have given below draws a triangle that is part of the plane. It will draw the part of the plane closest to the origin.

This is what just came to my mind. Please correct me if I am wrong. My explanations as to why I am doing each step is beside each line

// Given
N = normal of the plane
d = distance of the plane
fMul = some number depending on how big you want the triangle

// To draw a traingle on the plane

// Algo
v1 = N * d // Find one point on the plane. This is the point closest to the origin
vUp = (0.0f, 1.0f, 0.0f) //Create a vector pointing up
v2 = Cross(v1, vUp) // Taking the cross product will result in a vector parallel to the plane
Normalize(v2) // Normalize this vector
v3 = v2 // make a copy for use later
v2 *= fMul // Multiply it based on the desired size
v2 += v1 // Add this point to v1 so the point lies on the same plane
v3 = Cross(N, v3) // now take the cross product of the plane normal and v3. we will get a vector that is perpendicular to the 2 and also is parallel to the plane
Normalize(v3) // normalize this too
v3 *= fMul // multiply this too by the mutiplier
v3 += v1 // Add this point to v1 so the point lies on the same plane
DrawTri(v1, v2, v3) // Traw a triangle from the 3 points.

This will create a right angled triangle with the right angle at v1. You should be able to create a quad if you understood the algo above

hope this helps.

- Sid

Victor Widell

March 15, 2005, 05:23 AM

cipherx wrote: A plane is infinite so we can only draw part of a plane.

Not true. Anyone who has used a simple raytracer knows that. And it is pretty simple in opengl too. Just draw a quad with infinitely far corners. (Set W to zero.)


March 15, 2005, 05:42 AM

A plane is mathematically infinite, anyone who is up on his/her maths knows that. The infinitely far corners you mention are only infinitely far as far as float representation goes (or, indeed, 'far enough', such that we are guaranteed never to see its ends). But since none of us has the time or space to actually watch a (infinite) plane, this discussion is of theoretical importance only (at least in the context of games).

Rui Martins

March 15, 2005, 09:25 AM

v2 = Cross(v1, vUp) // Taking the cross product will result in a vector parallel to the plane

It's safer to use the inverse of the vector than the up Vector, because the plane can be horizontal, i.e. it's normal coincides with your up vector.

Just do this instead:

v2 = Cross(v1, -v1);

It only fails if v1 is the "Zero" Vector, which is not a valid vector/normal for a plane.


March 15, 2005, 08:00 PM

hmmmmmmmmmm, thanx for the help so far guys, i just tried the above algorithm but unforunately cannot get it to work. or perhaps i am understanding it worng. to normalize a vector you just do

v.x = x / sqrt( x*x + y*y + z*z );
v.y = y / sqrt( x*x + y*y + z*z );
v.z = z / sqrt( x*x + y*y + z*z );


is there another easier way to do this? i was kinda hoping of some sort of function in opengl where i can just take the Ax + By + Cz + D = 0 and plug in the A B C D values and magically get the plane drawn. :D


March 15, 2005, 08:24 PM

Although you can project points at infinity (other than those on the view plane) into view space points not at infinity, you still can't see all of the plane as its infinite extent will assuredly extend past any finite viewport's clipping rectangle.


March 15, 2005, 09:29 PM

Ummm, cross(v1, -v1) is always zero.


March 15, 2005, 09:30 PM

You can, of course, use a frustum with an infinitely distant far plane.


March 15, 2005, 09:32 PM

  1. float mag = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
  2. v.x /= mag;
  3. v.y /= mag;
  4. v.z /= mag;

Make sure you only calculate mag once, both because it's faster and because if you calculate it each time as you have above, it will change!

Rui Martins

March 16, 2005, 05:02 AM

Ummm, cross(v1, -v1) is always zero.

Oops, you are right! My Bad.

There is a trick though, I just don't remember it right.
It had to do with multiplying by -1, but maybe not all coords of them, can't remember right now.

Next time, think first, post after 8)

Erik Faye-Lund

March 18, 2005, 12:26 AM

how about only doing one division while we're at it? it doesn't really matter for correction, but hey.

float one_over_mag = 1.f / sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
v.x *= one_over_mag;
v.y *= one_over_mag;
v.z *= one_over_mag;

This thread contains 14 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.