POV-Ray : Newsgroups : povray.general : Normals with large and small traingles. Server Time
6 Aug 2024 12:18:52 EDT (-0400)
  Normals with large and small traingles. (Message 1 to 9 of 9)  
From: Shay
Subject: Normals with large and small traingles.
Date: 8 Apr 2002 17:54:51
Message: <3cb211ab$1@news.povray.org>
How would I calculate the normals of triangles where a vertex may lay on the
edge of a triangle but not be at a corner? This ASCII art should clear up
the question:

___________
|\       /|
| \  B  / |
|  \   /  |
|   \ /   |
| C  X    |
|   /     |
|  /   A  |
| /       |
|/________|

How would I calculate the normal at point X given triangles A, B, & C?

 -Shay


Post a reply to this message

From: Shay
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 18:01:53
Message: <3cb21351@news.povray.org>
This question didn't make much sense the first time I wrote it. Let me try
again.

How can I calculate the normal of a vertex which lies on the side of a
triangle. but not at the corner?
 ___________
 |\       /|
 | \  B  / |
 |  \   /  |
 |   \ /   |
 | C  X    |
 |   /     |
 |  /   A  |
 | /       |
 |/________|

 How would I calculate the normal at point X given the normals of triangles
A, B, & C?

  -Shay


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 19:42:13
Message: <3CB22755.46DB428@online.no>
Shay wrote:
> 
> This question didn't make much sense the first time I wrote it. Let me try
> again.
> 
> How can I calculate the normal of a vertex which lies on the side of a
> triangle. but not at the corner?
>  ___________
>  |\       /|
>  | \  B  / |
>  |  \   /  |
>  |   \ /   |
>  | C  X    |
>  |   /     |
>  |  /   A  |
>  | /       |
>  |/________|
> 
>  How would I calculate the normal at point X given the normals of triangles
> A, B, & C?


Shay, there are several possible ways to calculate
such a normal. It all depends on the application.

But assuming that you are going to use it in
a mesh2{}, then I would recommend the following:

If vN_A, vN_B and vN_C are normals with unknown
length, then I would suggest this for the normal
vector at X:

#declare vNormalX =
vnormalize(
  vnormalize(vN_A)*AreaA
 +vnormalize(vN_B)*AreaB
 +vnormalize(vN_C)*AreaC
)


If you know the coordinates of the corners p00,
p10, p11 and p01, then I would suggest the
following:

 p01_______p11
  |\       /|
  | \     / |
  |  \   /  |
  |   \ /   |
  |   pXX   |
  |   /     |
  |  /      |
  | /       |
 p00_______p10

#declare vNormalX =
vnormalize(vcross(p01 - p10, p11 - p00))


I would also recommend the same formula even
if the triangles were arranged like this:

 p01_______p11
  |\       /|
  | \     / |
  |  \   /  |
  |   \ /   |
  |   pXX   |
  |   / \   |
  |  /   \  |
  | /     \ |
 p00_______p10



The argument for this involves some vector
cross product calculations (which I can try to
show and explain if you're interested).

Note that I have not tested my suggestions
above yet, so there may be defects in my
reasoning.


Tor Olav


Post a reply to this message

From: Warp
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 19:43:02
Message: <3cb22b06@news.povray.org>
Shay <sah### [at] simcopartscom> wrote:
> How can I calculate the normal of a vertex which lies on the side of a
> triangle. but not at the corner?
>  ___________y
>  |\       /|
>  | \  B  / |
>  |  \   /  |
>  |   \ /   |
>  | C  X    |
>  |   /     |
>  |  /   A  |
>  | /       |
>  |/________|
   z

>  How would I calculate the normal at point X given the normals of triangles
> A, B, & C?

  If B and C both share a vertex with A (marked as vertices 'y' and 'z' in
the picture), and X lies on the side of A, then B and C lie on the same plane
and could be replaced with one triangle.
  If replacing them is not an option, then the answer is that the normal
at X is the interpolation of the normal vectors at 'y' and 'z', that is,
the weigthed average of the normals, where the weighting factor is the
distance of X from y or z.
  This is how POV-Ray interpolates the normals of a smooth triangle (or at
least I suppose so), so you should get smooth lighting in this edge. (If
POV-Ray interpolates in some other way, you'll get a sharp edge in the
lighting.)

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Warp
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 19:54:05
Message: <3cb22d9c@news.povray.org>
Tor Olav Kristensen <tor### [at] onlineno> wrote:
> Shay, there are several possible ways to calculate
> such a normal. It all depends on the application.

  I think that the idea is to get smooth lighting. The normal at X must
be exactly the normal that POV-Ray would calculate if B and C were just
one triangle.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 20:08:47
Message: <3CB22D89.547853CA@online.no>
Warp wrote:
> 
> Tor Olav Kristensen <tor### [at] onlineno> wrote:
> > Shay, there are several possible ways to calculate
> > such a normal. It all depends on the application.
> 
>   I think that the idea is to get smooth lighting. The normal at X must
> be exactly the normal that POV-Ray would calculate if B and C were just
> one triangle.

Hmmm... I don't know how POV-Ray calculates this.

But IIRC ABX once "proved" with an image example
that if the area of the triangles are used to
scale the normal vectors for each triangle, then
it produces quite "smooth shading" results for a
mesh.


Tor Olav


Post a reply to this message

From: Warp
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 20:44:45
Message: <3cb2397c@news.povray.org>
Tor Olav Kristensen <tor### [at] onlineno> wrote:
> Hmmm... I don't know how POV-Ray calculates this.

> But IIRC ABX once "proved" with an image example
> that if the area of the triangles are used to
> scale the normal vectors for each triangle, then
> it produces quite "smooth shading" results for a
> mesh.

  We have to make a distinction between normals at triangle vertices and
normals inside triangles (which are calculated internally by POV-Ray).
  The normals at the vertices of the triangles are user-defined and thus
whatever the user wants them to be.
  The normals inside the triangle are calculated by POV-Ray by interpolating
the vertex normals.
  The normal vector at any point in the triangle is the weigthed average
of the normals at the vertices, where the weight factor for each normal is
the distance of the point from that normal. At the edge of the triangle the
normal at any point is the weigthed average of the two normals at the two
vertices of that edge.

  In this special case, where we need the normal vector at the point X and
we want the result to be smooth, we can't set X to whatever we like, but
we have to set it to what POV-Ray calculates as the normal vector of triangle
A at point X. If you set the normal vectors at X for triangles B and C to
*anything* else than what POV-Ray calculates for triangle A at the point X,
you will not get smooth lighting.
  This is the crucial thing to understand in this.

  As said before, the normal vector of the triangle A at the point X is
the weighted average of the two vertex normals (which I marked as y and z),
where the weigth factor is the distance of X from them.
  I don't know what is the *exact* formula (eg. I don't know if POV-Ray
normalizes the two vertex normals or not before calculating the weighted
average), but it shouldn't be too complicated.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Shay
Subject: Re: Normals with large and small traingles.
Date: 8 Apr 2002 21:10:54
Message: <3cb23f9e@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message
news:3cb22b06@news.povray.org...
>
> the normal at X is the interpolation of the normal > vectors at 'y' and
'z', that is,
> the weigthed average of the normals, where the
> weighting factor is the
> distance of X from y or z.

This could get messy really quickly if y or z is on the side of a triangle
as well.

 -Shay


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Normals with large and small traingles.
Date: 4 May 2002 20:12:00
Message: <3CD4782E.9C15A588@hotmail.com>
Warp, I just remembered that I had not replied to this.

I think that I misunderstood the "nature" of the problem.
Thank you for explaining though.


Tor Olav


Warp wrote:
> 
> Tor Olav Kristensen <tor### [at] onlineno> wrote:
> > Hmmm... I don't know how POV-Ray calculates this.
> 
> > But IIRC ABX once "proved" with an image example
> > that if the area of the triangles are used to
> > scale the normal vectors for each triangle, then
> > it produces quite "smooth shading" results for a
> > mesh.
> 
>   We have to make a distinction between normals at triangle vertices and
> normals inside triangles (which are calculated internally by POV-Ray).
>   The normals at the vertices of the triangles are user-defined and thus
> whatever the user wants them to be.
>   The normals inside the triangle are calculated by POV-Ray by interpolating
> the vertex normals.
>   The normal vector at any point in the triangle is the weigthed average
> of the normals at the vertices, where the weight factor for each normal is
> the distance of the point from that normal. At the edge of the triangle the
> normal at any point is the weigthed average of the two normals at the two
> vertices of that edge.
> 
>   In this special case, where we need the normal vector at the point X and
> we want the result to be smooth, we can't set X to whatever we like, but
> we have to set it to what POV-Ray calculates as the normal vector of triangle
> A at point X. If you set the normal vectors at X for triangles B and C to
> *anything* else than what POV-Ray calculates for triangle A at the point X,
> you will not get smooth lighting.
>   This is the crucial thing to understand in this.
> 
>   As said before, the normal vector of the triangle A at the point X is
> the weighted average of the two vertex normals (which I marked as y and z),
> where the weigth factor is the distance of X from them.
>   I don't know what is the *exact* formula (eg. I don't know if POV-Ray
> normalizes the two vertex normals or not before calculating the weighted
> average), but it shouldn't be too complicated.


Post a reply to this message

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