 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |