POV-Ray : Newsgroups : povray.general : Calculate normal vector? Server Time
1 Aug 2024 18:29:08 EDT (-0400)
  Calculate normal vector? (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
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

From: Thorsten Froehlich
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 02:12:58
Message: <48dc7d6a$1@news.povray.org>
B. Gimeno wrote:
> 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}

What do you expect if all normals are identical? - For a single triangle 
this will never be different...

	Thorsten


Post a reply to this message

From: alphaQuad
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 13:55:01
Message: <web.48dd20ef92437aab8ea364160@news.povray.org>
everyone has explained it, here's my 2 cents. I have had to do this twice but
not in pov script (yet)

the normal for the vertex is the addition of the normals of all triangles that
share it. but you want a condition that supports limiting to an angle variable,
ideally.

first the triangle normal

#macro normal_vector(A,B,C)
 #local result = vcross(C-B,A-B);
 result
 // 1
 // |
 // 2__ 3 vz points at you (neg) unless reverse y like pov, then
 //
 // 2__ 3
 // |
 // 1
#end

vcrossing 2 vectors is almost never a length of one, unless it is.
normalize for a length of 1.

pov renders 2-sided, so reverse normals are seldom an issue but do it right the
first time, if you want outside vectors, input is clockwise


Post a reply to this message

From: alphaQuad
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 14:40:01
Message: <web.48dd2b4d92437aab8ea364160@news.povray.org>
the angle function

#macro _clamp(a,n,m)
   #local result = a;
   #if (a < n) #local result = n;  #end
   #if (a > m) #local result = m;  #end
   result
#end

#macro radang2(A,B)
  #declare result =
    acos(_clamp(vdot(vnormalize(A),vnormalize(B)), -1.0, 1.0));
   result
#end
#macro radang3(A,B,C)
   // input is 3 points in 3D -- points to A and C, angle at B
   #declare result =
     acos(_clamp(vdot(vnormalize(A-B),vnormalize(C-B)), -1.0, 1.0));
   result
#end

 parameter range for acos() is -1 to 1, _clamp handles user input error.

angle of 2 vectors:
#if (degrees(radang2(nA,nB)) < "somenumber") add nB to tally for this vert(nA),
normalize.


Post a reply to this message

From: alphaQuad
Subject: Re: Calculate normal vector?
Date: 26 Sep 2008 14:50:00
Message: <web.48dd2e6592437aab8ea364160@news.povray.org>
angle of 2 vectors:
#if (degrees(radang2(nA,nB)) < "somenumber") add nB to tally for this vert(nA),
normalize.

nA was initialized to "this" triangle normal before comapring to adjacent
triangle/planes

AN important part of this variable angle logic, hope this helps in the long run.

nested triangle loops comparing all triangles for adjacency, 3 times for each
vert in ea triangle. If not compiled this would be slow for large objects.


Post a reply to this message

<<< Previous 4 Messages Goto Initial 10 Messages

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