POV-Ray : Newsgroups : povray.windows : Computing normals for use in smooth_triangle Server Time
24 Nov 2024 20:49:46 EST (-0500)
  Computing normals for use in smooth_triangle (Message 1 to 4 of 4)  
From: Jim Kress
Subject: Computing normals for use in smooth_triangle
Date: 10 May 1998 00:09:26
Message: <35552876.2EC1244E@dccmail.com>
I have an object that isdescribed by a large number of triangles.  I
have the x,y,z coordinates for each vertex of every triangle.  Can
anyone explain how to calculate the normal vectors for me to use with
the smooth_triangle function in POVray?

Thanks for the help.


Jim

-----

"He who is void of virtuous attachments in private life is, or very soon

will be, void of all regard for his country."  Samuel Adams


Post a reply to this message

From: yang444
Subject: Re: Computing normals for use in smooth_triangle
Date: 10 May 1998 03:48:02
Message: <35555BB2.D4147A37@pacbell.net>
Jim Kress wrote:

> I have an object that isdescribed by a large number of triangles.  I
> have the x,y,z coordinates for each vertex of every triangle.  Can
> anyone explain how to calculate the normal vectors for me to use with
> the smooth_triangle function in POVray?
>
> Thanks for the help.
>
> Jim
>

------------- Given the 3 points: (x[i], y[i], z[i]),   i=0,1 2

Each of the points satisfies the eq. for a plane:

  A(x-x[i]) + B(y-y[i]) + C(z-z[i]) = 0    (1)

Substituting each point in the equation,
you have 3 eqs. in 3 unknowns, A, B and C.

Once you have solved for A, B and C,
the vector normal to the plane is:

  N = Ai + Bj + Ck

where i, j and k are the usual unit vectors.

To see this, pick any pt, P1(x[0], y[0], z[0]), on the plane.
and pick another arbitrary pt, P(x, y, z), on the plane.

The vector from the origin to P1 is

  r0 =  x[0]i + y[0]j + z[0]k

The vector from the origin to P is

  r = xi + yj + zk

So the vector r - r0, which must lie on the plane, is:

  M = (x - x[0])i + (y - y[0])j + (z - z[0])k

Now dot N with M, and you get the left side of eq. (1),
which is equal to the left side, which is zero.

But if the dot product of 2 vectors is zero,
they must be perpendicular to each other.

So N is perpendicular to all vectors on the plane
and so is the normal to the plane.




--
Alan

 Spam Bait:
root@localhost
admin@localhost
current board of the Federal Communications Commission:
Chairman Reed Hundt: rhu### [at] fccgov
Commissioner James Quello: jqu### [at] fccgov
Commissioner Susan Ness: sne### [at] fccgov
Commissioner Rachelle Chong: rch### [at] fccgov


Post a reply to this message

From: Johannes Hubert
Subject: Re: Computing normals for use in smooth_triangle
Date: 10 May 1998 06:50:55
Message: <6j40rr$r06$1@oz.aussie.org>
Jim Kress wrote in message <35552876.2EC1244E@dccmail.com>...
>I have an object that isdescribed by a large number of triangles.  I
>have the x,y,z coordinates for each vertex of every triangle.  Can
>anyone explain how to calculate the normal vectors for me to use with
>the smooth_triangle function in POVray?
>


First, calculate the normal for each triangle. If the triangle has the tree
vertices v1, v2, v3, it is defined by the following cross-product:



Once you have the normal for each triangle, you then calculate the normal of
each vertex by calculating the average of the triangle-normals of all
triangles that use this vertex:
Simply add the normals of all triangles that use a vertex together and
normalize the resulting vector.

Note: In the cross-product the order of the vertices is important. You
should choose v1, v2, v3 in clockwise or counter-clockwise fashion for all
triangles in a mesh. Which one doesn't matter but to mix them can have
strange results. Why? Because the crossproduct gives you a vector pointing
in one direction or the same vector pointing in the opposite direction,
depending on the order of the vertices. And mixing normals that point to the
"inside" and the "outside" of the mesh when calculating the averaged normal
often gives strange results.

You can find a little bit more on this page (this is for OpenGL but the
theory applies here too):
(Note, this is a very strange URL. The whole stuff from "http" to "td=6" is
the URL, you need it all!)

http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@
Generic__BookTextView/27318;cd=7;td=6

Also, there is a tool around by Nieminen Mika that does exactly this: Read
POV-Ray triangles, calculate the normals and output POV-Ray smooth
triangles. The URL used to be
http://www.iki.fi/warp/PovUtils/smooth.html
But it seems to be down now...

Johannes.


Post a reply to this message

From: Jim Kress
Subject: Re: Computing normals for use in smooth_triangle
Date: 10 May 1998 11:26:14
Message: <3555C716.A7EEC0C3@dccmail.com>
Thanks again.  After recovering from my initial attack of stupidity, if figured
out what you meant and implemented.  It works GREAT!

Jim

Johannes Hubert wrote:

> Jim Kress wrote in message <35552876.2EC1244E@dccmail.com>...
> >I have an object that isdescribed by a large number of triangles.  I
> >have the x,y,z coordinates for each vertex of every triangle.  Can
> >anyone explain how to calculate the normal vectors for me to use with
> >the smooth_triangle function in POVray?
> >
>
> First, calculate the normal for each triangle. If the triangle has the tree
> vertices v1, v2, v3, it is defined by the following cross-product:
>

>
> Once you have the normal for each triangle, you then calculate the normal of
> each vertex by calculating the average of the triangle-normals of all
> triangles that use this vertex:
> Simply add the normals of all triangles that use a vertex together and
> normalize the resulting vector.
>
> Note: In the cross-product the order of the vertices is important. You
> should choose v1, v2, v3 in clockwise or counter-clockwise fashion for all
> triangles in a mesh. Which one doesn't matter but to mix them can have
> strange results. Why? Because the crossproduct gives you a vector pointing
> in one direction or the same vector pointing in the opposite direction,
> depending on the order of the vertices. And mixing normals that point to the
> "inside" and the "outside" of the mesh when calculating the averaged normal
> often gives strange results.

--






History students know full well that similar opinions have existed
before.  The circumstances paralleled those of today.  For example:

A country enjoying a booming economy was led by someone whose
ethical and legal malfeasance was already well known.  The economic

transgressions, until it was too late. It was all looked at as

else he claimed he was doing for the country.

         It happened in the 1930s.
         In Germany.  Under Adolph Hitler.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.