[comp.graphics] newell plane equation

stephenj@deblil.Eng.Sun.COM (Stephen Johnson) (03/07/91)

I have been using the Newell technique for computing the plane
equation in the form:

Ax + By + Cz + D = 0

and I discovered that the plane defined by the following points is
computing incorrectly:

(2,2,0), (12,2,0), (2,2,3), (12, 2, 3)

From "Procedural Elements for Computer Graphics" bu David F. Rogers,
page 209, the Newell equations are

In the loops: if (i == n) j = 1 else j = i + 1

A = SUM(y[i] - y[j]) * (z[i] + z[j]) for i = 1 to N
B = SUM(z[i] - z[j]) * (x[i] + x[j]) for i = 1 to N
C = SUM(x[i] - x[j]) * (y[i] + y[j]) for i = 1 to N

D = (A * x[0] + B * y[0] + C * z[0])

Unfortunately, with the previously mentioned points:

A = (0 * 0) + (0 * -3) + (0 * 0) + (0 * 3) = 0
B = (0 * 14) + (-3 * 14) + (0 * 14) + (3 * 14) = 0
C = (-10 * 0) + (10 * 0) + (-10 * 0) + (10 * ) = 0

Oops, by inspection we can see that the equation for this plane is
y = -2.  So, what's wrong?  Has someone noticed this before and fixed
it.

Thanks for the Advice,
Stephen Johnson

wilson@cs.ucf.edu (tom wilson) (03/07/91)

In article <9283@exodus.Eng.Sun.COM> stephenj@deblil.Eng.Sun.COM (Stephen Johnson) writes:
>I have been using the Newell technique for computing the plane
>equation in the form:
>Ax + By + Cz + D = 0
>and I discovered that the plane defined by the following points is
>computing incorrectly:
>(2,2,0), (12,2,0), (2,2,3), (12, 2, 3)
>From "Procedural Elements for Computer Graphics" bu David F. Rogers,
>page 209, the Newell equations are
>In the loops: if (i == n) j = 1 else j = i + 1
>
>A = SUM(y[i] - y[j]) * (z[i] + z[j]) for i = 1 to N
>B = SUM(z[i] - z[j]) * (x[i] + x[j]) for i = 1 to N
>C = SUM(x[i] - x[j]) * (y[i] + y[j]) for i = 1 to N
>
>D = (A * x[0] + B * y[0] + C * z[0])
>
>Unfortunately, with the previously mentioned points:
>
>A = (0 * 0) + (0 * -3) + (0 * 0) + (0 * 3) = 0
>B = (0 * 14) + (-3 * 14) + (0 * 14) + (3 * 14) = 0
>C = (-10 * 0) + (10 * 0) + (-10 * 0) + (10 * ) = 0
>
>Oops, by inspection we can see that the equation for this plane is
>y = -2.  So, what's wrong?  Has someone noticed this before and fixed

??? y=-2? How about y=2? Look at the y value for each point.

>it.

Well, first I don't have the book. Your values are right. This leads me to
think that maybe the equations are meant to show that the points are coplanar
(i.e. if all sums are 0, then they're coplanar), but that doesn't make sense
since it says A=..., B=..., C=...

Here's a way that works involving vectors (which I won't go into). Given
three points on a plane p0=(x0,y0,z0), p1=(x1,y1,z1), and p2=(x2,y2,z2), then
the equation for the plane is:
A = (y1-y0)*(z2-z1) - (y2-y1)*(z1-z0)
B = (z1-z0)*(x2-x1) - (z2-z1)*(x1-x0)
C = (x1-x0)*(y2-y1) - (x2-x1)*(y1-y0)
D = -A*x0 - B*y0 - C*z0

thus,
A = (2-2)*(3-0) - (2-2)*(0-0) = 0
B = (0-0)*(2-12) - (3-0)*(12-2) = -30
C = (12-2)*(2-2) - (2-12)*(2-2) = 0
D = 0*2 - -30*2 - 0*0 = 60

Thus, the plane equation is -30y + 60 = 0 => y = 2.

Tom

jonas-y@isy.liu.se (Jonas Yngvesson) (03/08/91)

stephenj@deblil.Eng.Sun.COM (Stephen Johnson) writes:

>I have been using the Newell technique for computing the plane
>equation in the form:

>Ax + By + Cz + D = 0

>and I discovered that the plane defined by the following points is
>computing incorrectly:

>(2,2,0), (12,2,0), (2,2,3), (12, 2, 3)

If you use the points in the above order they don't define a proper
polygon but a polygon with two "loops" in it. Rather like an 8:

        3*-----*4
          \   /
           \ /
            X
           / \
          /   \
        1*-----*2

Such a polygon doesn't have a defined normal vector (which is what
you calculate in the sums). If you change the order of the first two
or the last two points your calculations will be (last two changed):

A = (0 * 0) + (0 * 3) + (0 * 6) + (0 * 3) = 0
B = (0 * 14) + (-3 * 24) + (0 * 14) + (3 * 4) = -60
C = (-10 * 4) + (0 * 4) + (10 * 4) + (0 * 4) = 0

D = -(A * x[0] + B * y[0] + C * z[0]) = 120
    ^
    `--Note!

This gives the plane equation:

    -60y + 120 = 0  or  -y + 2 = 0  or  y = 2

which is correct (not y=-2 as you wrote, actually there were
several errors in your figures but the point order was the crucial bit).

--Jonas


-- 
------------------------------------------------------------------------------
 J o n a s   Y n g v e s s o n
Dept. of Electrical Engineering	                         jonas-y@isy.liu.se
University of Linkoping, Sweden                   ...!uunet!isy.liu.se!jonas-y

neeman@s5.csrd.uiuc.edu (Henry J. Neeman) (03/08/91)

In article <9283@exodus.Eng.Sun.COM>
stephenj@deblil.Eng.Sun.COM (Stephen Johnson) writes:
>I have been using the Newell technique for computing the plane
>equation in the form Ax + By + Cz + D = 0
>and I discovered that the plane defined by the following points is
>computing incorrectly:  (2,2,0), (12,2,0), (2,2,3), (12, 2, 3)
>In the loops: if (i == n) j = 1 else j = i + 1
>A = SUM(y[i] - y[j]) * (z[i] + z[j]) for i = 1 to N
>B = SUM(z[i] - z[j]) * (x[i] + x[j]) for i = 1 to N
>C = SUM(x[i] - x[j]) * (y[i] + y[j]) for i = 1 to N
>D = (A * x[0] + B * y[0] + C * z[0])

Actually, I think D = -(Ax[k] + By[k] + Cz[k]), for any k in 1..N.

>Unfortunately, with the previously mentioned points:
	[A=B=C=0]
>Oops, by inspection we can see that the equation for this plane is
>y = -2.  So, what's wrong?  Has someone noticed this before and fixed
>it.

Actually, by inspection we see that y = 2, but I guess that's a typo.

Anyway, your problem is that you're overdetermining your plane.  A plane
can be described by three points, and I'm guessing that Newell's technique
takes advantage of that.  Let's try it:

(2,2,0), (12,2,0), (2,2,3)
A=(2- 2)(0+ 0)+(2- 2)( 0+3)+(2-2)(3+0)=    0*0+   0*3 +0*3=  0+ 0+ 0= *   0 *
B=(0- 0)(2+12)+(0- 3)(12+2)+(3-0)(2+2)=0(-14) +(-3)*14+3*4=  0-42+12= * -30 *
C=(2-12)(2+ 2)+(12-2)( 2+2)+(2-2)(2+2)=(-10)*4+  10*4 +0*4=-40+40+ 0= *   0 *

So, we have 0*x-30*y+0*z=-D.  Plugging in (2,2,0), we get -30*2=-D or D=60.
In other words, -30 * y + 60 = 0, or y = 2.

I think it's safe to assume that we'll get the same results for any combination
of three of your four points.

					Henry Neeman
					neeman@csrd.uiuc.edu

jonas-y@isy.liu.se (Jonas Yngvesson) (03/09/91)

neeman@s5.csrd.uiuc.edu (Henry J. Neeman) writes:

>Actually, I think D = -(Ax[k] + By[k] + Cz[k]), for any k in 1..N.

Correct.

>Anyway, your problem is that you're overdetermining your plane.  A plane
>can be described by three points, and I'm guessing that Newell's technique
>takes advantage of that.  Let's try it:

Nope. As I pointed out in another posting, the problem was that the points
were used in wrong order. The great *advantage* with Newell's method is
that you use *all* the points around the polygon, *not* just three of them.
If the three points you choose happends to lie on a straight line in the
plane your computations will fail. This is avoided in Newell's method (if
*all* the points in the polygon is on a straight line in the plane it fails
too, of course, but then it's not really a polygon).

The important thing is to take the points in the correct order, walking
clockwize, or counterclockwize, around the polygon. In the example, the
points were taken in an order that created an 8-shaped polygon.

--Jonas
-- 
------------------------------------------------------------------------------
 J o n a s   Y n g v e s s o n
Dept. of Electrical Engineering	                         jonas-y@isy.liu.se
University of Linkoping, Sweden                   ...!uunet!isy.liu.se!jonas-y

groc1@cs.aukuni.ac.nz (GuyonAlanEdward Roche ) (03/12/91)

In <9283@exodus.Eng.Sun.COM> stephenj@deblil.Eng.Sun.COM (Stephen Johnson) writes:

>and I discovered that the plane defined by the following points is
>computing incorrectly:

>(2,2,0), (12,2,0), (2,2,3), (12, 2, 3)

[ stuff deleted here ]

>Oops, by inspection we can see that the equation for this plane is
>y = -2.  So, what's wrong?  Has someone noticed this before and fixed
>it.


What is in fact wrong here is that the points have to be entered in
in a clockwise or counter-clockwise direction making a simple closed
polygon.

If you were to rearange the points like this ..

(2,2,0), (12,2,0),(12, 2, 3), (2,2,3)

it should work.


========================================================================
| Guyon Roche : Don't buy a used car from Caveat Emptor's used cars!   |
========================================================================