POV-Ray : Newsgroups : povray.general : Calculate normal vector? Server Time
1 Aug 2024 16:28:30 EDT (-0400)
  Calculate normal vector? (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: Hasan3
Subject: Calculate normal vector?
Date: 8 Sep 2005 02:25:01
Message: <web.431fd888f4e5b5152f6d7a0@news.povray.org>
That code is generated by Povray:
>// rounded-surface FINITE (no CSG) triangle shape
>     smooth_triangle {
>           <  0,  30, 0> <0,  0.7071, -0.7071>  // <Vertex1>  <SurfaceNormal1>
>           < 40, -20, 0> <0, -0.8664, -0.5>     // <Vertex2>  <SurfaceNormal2>
>           <  0,   0, 0> <0, -0.5,    -0.8664>  // <Vertex3>  <SurfaceNormal3>
>    }


How can I calculate '<0,  0.7071, -0.7071>' SurfaceNormal1 ?


Post a reply to this message

From: Slime
Subject: Re: Calculate normal vector?
Date: 8 Sep 2005 02:52:57
Message: <431fdfc9$1@news.povray.org>
> How can I calculate '<0,  0.7071, -0.7071>' SurfaceNormal1 ?

If all you have is a single triangle, you can use any vector for the normal
of a vertex. Use what looks good.

If you have multiple triangles connected at a single vertex, you typically
use the average of all of the triangle's normals as the normal for that
vertex. To do this, you take the normal of each triangle, which can be
calculated by a cross product between the vectors forming two sides of that
triangle:

(triangle consists of v1, v2, v3)
normal = vnormalize(vcross(v2 - v1, v3 - v1));

To get the average of all the triangle's normals, add them together and
vnormalize() the result.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Hasan3
Subject: Re: Calculate normal vector?
Date: 8 Sep 2005 09:45:00
Message: <web.43203f6a92437aab2cd8d46e0@news.povray.org>
"Slime" <fak### [at] emailaddress> wrote:
> > How can I calculate '<0,  0.7071, -0.7071>' SurfaceNormal1 ?
>
> If all you have is a single triangle, you can use any vector for the normal
> of a vertex. Use what looks good.
>
> If you have multiple triangles connected at a single vertex, you typically
> use the average of all of the triangle's normals as the normal for that
> vertex. To do this, you take the normal of each triangle, which can be
> calculated by a cross product between the vectors forming two sides of that
> triangle:
>
> (triangle consists of v1, v2, v3)
> normal = vnormalize(vcross(v2 - v1, v3 - v1));
>
> To get the average of all the triangle's normals, add them together and
> vnormalize() the result.
>
>  - Slime
>  [ http://www.slimeland.com/ ]



Thanks for topiks. is this code correct?


global_settings {
  assumed_gamma 1.5
  max_trace_level 5
  ambient_light rgb< 0.99609375,0.99609375,0.99609375>


}

#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "woods.inc"
#include "shapes.inc"
#include "metals.inc"
#include "woodmaps.inc"
#include "stones.inc"
#include "skies.inc"

//*Işık
//--------------------------------------------------------------
//------------------------------------------------------------------------
  light_source {<-3.9,6.04020933313238,2.5>
        color rgb <1,1,1>*1
    fade_distance 2000
    fade_power 1
  }
//*camera //--------------------------------------------------------------
//------------------------------------------------------------------------
camera {
location  <-8.4612620107387,4.23118150919749,-2.71953991167386>
look_at   <-6.3,1.67916373510155,-0.7>
 }


 #declare Gri = material {
texture {
    pigment {  color rgbf <0.765625,0.765625,0.765625,0>}

 finish{
            ambient 0
            reflection {
            }
    }

}
}
#declare v1=<-6.3,1.67916373510155,-0.1>;
#declare v2=<-5.1,1.60116644662657,-0.1>;
#declare v3=<-4.4,0.327210734868637,0>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-7.2,0.561202600293564,0>;
#declare v2=<-6.3,1.67916373510155,-0.1>;
#declare v3=<-4.4,0.327210734868637,0>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-7.2,0.561202600293564,0>;
#declare v2=<-7.2,0.561202600293564,-0.8>;
#declare v3=<-6.3,1.67916373510155,-0.7>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-6.3,1.67916373510155,-0.1>;
#declare v2=<-7.2,0.561202600293564,0>;
#declare v3=<-6.3,1.67916373510155,-0.7>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-5.1,1.60116644662657,-0.1>;
#declare v2=<-6.3,1.67916373510155,-0.1>;
#declare v3=<-6.3,1.67916373510155,-0.7>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-5.1,1.60116644662657,-0.1>;
#declare v2=<-6.3,1.67916373510155,-0.7>;
#declare v3=<-5.1,1.60116644662657,-0.7>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-5.1,1.60116644662657,-0.1>;
#declare v2=<-5.1,1.60116644662657,-0.7>;
#declare v3=<-4.4,0.327210734868637,-0.8>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-4.4,0.327210734868637,0>;
#declare v2=<-5.1,1.60116644662657,-0.1>;
#declare v3=<-4.4,0.327210734868637,-0.8>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-5.1,1.60116644662657,-0.7>;
#declare v2=<-6.3,1.67916373510155,-0.7>;
#declare v3=<-4.4,0.327210734868637,-0.8>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}
#declare v1=<-6.3,1.67916373510155,-0.7>;
#declare v2=<-7.2,0.561202600293564,-0.8>;
#declare v3=<-4.4,0.327210734868637,-0.8>;
#declare n1=vnormalize(vcross(v2 - v1, v3 - v1));
smooth_triangle  { v1 n1 v2 n1 v3 n1
 material { Gri  scale 1 }

          no_reflection
}


Post a reply to this message

From: Tim Nikias
Subject: Re: Calculate normal vector?
Date: 8 Sep 2005 09:59:14
Message: <432043b2$1@news.povray.org>
As far as I can tell, the code is correct. But if your triangles are flat,
why not use "triangle" instead of "smooth_triangle"?

Like so:
> #declare v1=<-6.3,1.67916373510155,-0.1>;
> #declare v2=<-5.1,1.60116644662657,-0.1>;
> #declare v3=<-4.4,0.327210734868637,0>;
> triangle  { v1 v2 v3
>  material { Gri  scale 1 }
>           no_reflection
> }

It makes no sense to use smooth_triangle when you're not actually "bending"
the normals.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Hasan3
Subject: Re: Calculate normal vector?
Date: 9 Sep 2005 12:45:00
Message: <web.4321bba292437aab59546a660@news.povray.org>
"Tim Nikias" <JUSTTHELOWERCASE:timISNOTnikias(at)gmx.netWARE> wrote:
> As far as I can tell, the code is correct. But if your triangles are flat,
> why not use "triangle" instead of "smooth_triangle"?
>
> Like so:
> > #declare v1=<-6.3,1.67916373510155,-0.1>;
> > #declare v2=<-5.1,1.60116644662657,-0.1>;
> > #declare v3=<-4.4,0.327210734868637,0>;
> > triangle  { v1 v2 v3
> >  material { Gri  scale 1 }
> >           no_reflection
> > }
>
> It makes no sense to use smooth_triangle when you're not actually "bending"
> the normals.
>
> Regards,
> Tim
>
> --
> "Tim Nikias v2.0"
> Homepage: <http://www.nolights.de>


Because I want to make smooth surface like bicubic_patch. How can I do?


Post a reply to this message

From: Tim Nikias
Subject: Re: Calculate normal vector?
Date: 9 Sep 2005 13:54:45
Message: <4321cc65$1@news.povray.org>
Like Slime said. Take the vertices and look which triangles share that
vertex. Add the normals from those triangles together, and use vnormalize()
to normalize it. Then use that normal for the vertex. Repeat for all
vertices.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: here I am
Subject: Re: Calculate normal vector?
Date: 12 Feb 2008 00:00:01
Message: <web.47b1270192437aab3e2740f70@news.povray.org>
"Tim Nikias" <JUSTTHELOWERCASE:timISNOTnikias(at)gmx.netWARE> wrote:
> Like Slime said. Take the vertices and look which triangles share that
> vertex. Add the normals from those triangles together, and use vnormalize()
> to normalize it. Then use that normal for the vertex. Repeat for all
> vertices.
>
> Regards,
> Tim
>
> --
> "Tim Nikias v2.0"
> Homepage: <http://www.nolights.de>

hey I am in the middle of a project.

The problem is that I have a scene file with 15000 triangle which gives me flat
shading and to have smooth shading i have to implement smooth_triangle instead
of triangle at each traingle...which is not possible manually.

I am not sure how to implement that in a funtion or something.
I would appreciate if any one of you could help me out here.

Thanks


Post a reply to this message

From: Chris B
Subject: Re: Calculate normal vector?
Date: 12 Feb 2008 07:57:33
Message: <47b197bd$1@news.povray.org>
"here_I_am" <nomail@nomail> wrote in message 
news:web.47b1270192437aab3e2740f70@news.povray.org...
> "Tim Nikias" <JUSTTHELOWERCASE:timISNOTnikias(at)gmx.netWARE> wrote:
>> Like Slime said. Take the vertices and look which triangles share that
>> vertex. Add the normals from those triangles together, and use 
>> vnormalize()
>> to normalize it. Then use that normal for the vertex. Repeat for all
>> vertices.
>>
>> Regards,
>> Tim
>>
>> --
>> "Tim Nikias v2.0"
>> Homepage: <http://www.nolights.de>
>
> hey I am in the middle of a project.
>
> The problem is that I have a scene file with 15000 triangle which gives me 
> flat
> shading and to have smooth shading i have to implement smooth_triangle 
> instead
> of triangle at each traingle...which is not possible manually.
>
> I am not sure how to implement that in a funtion or something.
> I would appreciate if any one of you could help me out here.
>
> Thanks
>

For some reason I don't see your original post or the responses from Slime 
or Tim, either through Outlook or on the povray.general page on the web 
server, so I'm not sure exactly what's been covered so far.  I'll plow into 
the discussion anyway with appologies if I'm covering anything that's 
already been covered.

I think you would need to use the sort of technique above from within a 
macro or from a scripting language or a programming language. I see you've 
posted on both the newusers and the advanced-users newsgroups on the same 
day so it's difficult to judge whether you have any programming skills or 
POV-Ray Macro experience, but you're likely to need at least some such 
skills to be able to achieve this.

This processing is certainly possible using POV-Ray and, although it may not 
be your first choice of language for this sort of thing, it does have some 
very useful vector handling functions (such as the 'vnormalize' function 
mentioned above). If I was doing this in POV-Ray I'd probably approach it in 
the following way:
1. Use an editor to chop the top and bottom of the file away, saving just 
the triangles' corner vectors into a separate file.
2. Write a POV-Ray macro to process the file and generate a smooth triangle 
mesh. The macro would need to:
a) Use the POV-Ray 'read' function to read the data into an array of 
vectors.
b) Process the array, one triangle at a time, using nested loops to search 
through all of the other triangles to find triangles with edges that join 
onto the current triangle.
c) Calculate the normals for each corner of the current triangle (as 
mentioned above) and use the results to generate the smooth mesh.

Of course I assume you're unable to go back to the modeller source files and 
generate a smooth triangle mesh from the modeller or from your conversion 
utility.

Hope this helps
Regards,
Chris B.


Post a reply to this message

From: B  Gimeno
Subject: Re: Calculate normal vector?
Date: 25 Sep 2008 17:30:01
Message: <web.48dc017892437aaba5f67c3f0@news.povray.org>
Greetings,
I hope that no one feels annoyed about this repetitive question automatically
translated, but I'm stuck at the point of finding the normal to a given
triangle. I've read and re-read the answers given in this forum but I keep
stopping with this.

A triangle whose vertex are generated by a nested while-loop. (v1,v2,v3)

I attempt to find the normal by normalizing the product of vectors:

#local N = vnormalize(vcross( (v2 - v1) , (v3 - v1) ))  ;

Then I apply the normal obtained to a smooth_triangle, and the result is uh....
unsmoothed_triangles.

smooth_triangle {v1,N,v2,N,v3,N}


An example image is posted to p.b.i. under calculating normal vector FH topic

thanks in advance for any incoming help
B. Gimeno


Post a reply to this message

From: Warp
Subject: Re: Calculate normal vector?
Date: 25 Sep 2008 17:41:21
Message: <48dc0581@news.povray.org>
B. Gimeno <nomail@nomail> wrote:
> Then I apply the normal obtained to a smooth_triangle, and the result is uh....
> unsmoothed_triangles.

> smooth_triangle {v1,N,v2,N,v3,N}

  It's a flat triangle because all the vertex normals are pointing to the
same direction. You are thus telling POV-Ray that it's a flat triangle.

  For the triangle to be smooth the normals need to point to different
directions (more precisely, they should be normal vectors of the "actual
surface" which the triangle mesh is approximating).

  To get a completely smooth mesh, triangles sharing a vertex should all
have the same normal vector at that shared vertex.

  One common technique to auto-generate a vertex vector for a given vertex
in a completely smooth mesh is to average the normal vectors of the
triangles which share that vertex.

-- 
                                                          - Warp


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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