|
|
Marcus Fritzsch wrote:
>Hi,
>
>i wrote a simple triangulation algo for a noise program to generate
>something like a hieghtfield, and i wanted to use this with
>smooth_triangles, does anybody knows how to calculate the normals of the
>three points from the known triangle?
>
>greetings, Marcus
>
to get the normal (N) of a straigh triangle, if your vertexes points are V0,
V1, V2,
#declare N= vcross(V1-V0,V2-V0);
the to make it a unit vector (Nu) try,
#declare Nu = vnormalize(vcross(V1-V0,V2-V0));
For a smooth Triangle each vertex will have a differant normal, in that case
you'd have to find two vectors that are tangent with the surface at the
vertex (just as V1-V0 and V2-V0 are). If you know of two other points
close to the vertex then you could get a normal that is close. Best is to
take the derivites at the vertex (which is what the others are talking
about).
Tony
Post a reply to this message
|
|
|
|
Tor Olav Kristensen <tor### [at] hotmailcom> wrote:
>>...
>>(because the
>>dot-product of the two edges of a triangle gives a normal vector which
>>length is equal to the area of the triangle,
>>...
> Its length is equal to twice the area of the triangle.
Oops, you are right. What was I thinking?
(Well, it doesn't matter with respect to the sum of all normals...)
--
#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
|
|
|
|
Tony LaVigne wrote:
Marcus Fritzsch wrote:
>>Hi,
>>
>>i wrote a simple triangulation algo for a noise program to generate
>>something like a hieghtfield, and i wanted to use this with
>>smooth_triangles, does anybody knows how to calculate the normals of the
>>three points from the known triangle?
>>
>>greetings, Marcus
>>
>
>to get the normal (N) of a straigh triangle, if your vertexes points are
V0,
>V1, V2,
>#declare N= vcross(V1-V0,V2-V0);
This is almost correct. A more complete description would be:
To obtain the normal at any vertex, take the cross product of the two
vectors defined by the two adjacent sides. That is, for V0, V1 and V2,
labeled clockwise, you would obtain the normals N0, N1 and N2 thusly:
N0 = vcross(V2 - V0, V1 - V0);
N1 = vcross(V0 - V1, V2 - V1);
N2 = vcross(V1 - V2, V0 - V2);
Of course, since a triangle is a planar object, all three normals would
point in the same direction and would be parallel lines (except for the
degenerate case. Of course, if this were true, you could not obtain the
vector cross product). Note: It does not matter if you use a left-handed
or right-handed coordinate system as long as the same system is used for
all the vector operations on any single object. I also do not think the
handedness has any relation to POV-Ray's left-handed coordinate system.
>the to make it a unit vector (Nu) try,
>#declare Nu = vnormalize(vcross(V1-V0,V2-V0));
This is true, but may not be what is desired. When grouping triangles
together into a mesh, keeping the magnitude of the cross product instead
of normalizing it will lend bias for each of the triangles' normals that
share a common vertex. This information is lost in the normalizing process.
The definition of a vector cross product C = A X B is: The magnitude of the
resulting vector equals the product of the magnitudes of the two vectors to
be crossed times the sine of the angle between them. The direction of the
result is perpendicular to the plane containing the two vectors. It points
in the direction determined by the order and the handedness of the system.
Hence, A X B does not equal B X A. The magnitudes are the same, but the
directions are opposite. Switching handedness reverses this relationship.
So, for small sides and small angles (or very obtuse angles), the effect
may be small. For angles that are nearer to perpendicular and long sides,
the effect may be large. YMMV. This may be what is desired.
>
>For a smooth Triangle each vertex will have a differant normal, in that
case
>you'd have to find two vectors that are tangent with the surface at the
>vertex (just as V1-V0 and V2-V0 are). If you know of two other points
>close to the vertex then you could get a normal that is close. Best is
to
>take the derivites at the vertex (which is what the others are talking
>about).
The way POV-Ray obtains many of its surface effects is not by actually
changing the shape of the object (blob, height_field and some newly added
primitives excepted), but by changing the NORMAL to the surface at the
point of intersection with a ray. If you put waves on a plane and look at
that plane end on, all you will see is a line (if anything). The third
dimension does not exist. If you made a sphere out of smooth triangles,
like a geodesic dome, as the number of vertices is reduced the straight
edges would become apparent even though the shading might not look that
bad. Manipulating the surface normals to affect the incident and/or
reflected and/or refracted ray(s) is how the effects are obtained, and
the results are somewhat illusory. So it really does not make sense to
determine the tangent(s) or derivitive(s) explicitly at any given point.
(Actually, the tangent IS the derivitive at any point, but in the case
of an object that is not smooth, as in the case of boxes, triangles and
the results of some CSG objects, the edges are sharp and the derivitive
at some arbitrary point along those edges does not exist.)
What you probably want is to determine the cross product (normal) for
each triangle that meets at a specified vertex, average all of those
vectors, normalize them and then use that result for the normal of
each smooth_triangle that contains that vertex. It can be a lot of
calculation, but the results are probably more in line with what you
want. I wrote an include file several years ago to produce the threads
of a machine screw that used this technique. If anybody wants it, just
send me an email. I am listed in the community in the USA area if my
email address can't be found here.
Tip: Be VERY meticulous about keeping track of all the signs and order
of all the vectors, as a single error might ruin the object and the
cause can be VERY hard to find. Be sure of what you are doing and debug
as you write.
I hope this helps.
Bob
Post a reply to this message
|
|