POV-Ray : Newsgroups : povray.advanced-users : smooth_triangle normals Server Time27 May 2022 23:43:41 EDT (-0400)
 smooth_triangle normals (Message 1 to 6 of 6)
 From: Bald Eagle Subject: smooth_triangle normals Date: 26 Sep 2020 09:10:07 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5f6f3d5eca9fa6351f9dae300%40news.povray.org",
"dateCreated": "2020-09-26T13:10:07+00:00",
"datePublished": "2020-09-26T13:10:07+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
I've been rendering quite a few illustrations for

http://news.povray.org/povray.off-topic/message/%3Cweb.5f3045d617b7b05f1f9dae300%40news.povray.org%3E/#%3Cweb.5f3045d61
7b7b05f1f9dae300%40news.povray.org%3E

and have been mixing the very broad strokes with digging into the very detailed
bits.

At the moment, having some issues with smooth_triangles and want to verify a few
things, so I want to make sure everything is absolutely correct. Assume I'm
laying out a grid of squares made up of 2 triangles each.

All my flat triangles are fine, and I can see all of the individual triangles,
since all of the face normals are sufficiently different.

With smooth_triangles, even though the vertex coordinates are the same,
sometimes I get the degenerate triangle warning when working out the vertex
normal vectors.

When I use the corners of the square to calculate the normals, the edge between
the two triangles of the square softens/goes away, but the edges between all of
the squares are still pretty abrupt.
When I try to use a small dy or dx offset to calculate the normals, I get a lot
of the degenerate triangle warnings and few if any visible triangles.  Not sure
why.

So:

When calculating the normals, do I use the remaining two triangle vertices, or
the orthogonal edge vectors of the square?
Do I normalize the vectors before using vcross()?
Do I normalize the resulting vertex normal vectors?

Thanks
```
 From: Tor Olav Kristensen Subject: Re: smooth_triangle normals Date: 26 Sep 2020 19:15:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5f6fc9acaf8e23f96d7cc5a50%40news.povray.org",
"dateCreated": "2020-09-26T23:15:00+00:00",
"datePublished": "2020-09-26T23:15:00+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I've been rendering quite a few illustrations for
>
>
http://news.povray.org/povray.off-topic/message/%3Cweb.5f3045d617b7b05f1f9dae300%40news.povray.org%3E/#%3Cweb.5f3045d
61
> 7b7b05f1f9dae300%40news.povray.org%3E
>
> and have been mixing the very broad strokes with digging into the very detailed
> bits.
>
> At the moment, having some issues with smooth_triangles and want to verify a few
> things, so I want to make sure everything is absolutely correct. Assume I'm
> laying out a grid of squares made up of 2 triangles each.
>
> All my flat triangles are fine, and I can see all of the individual triangles,
> since all of the face normals are sufficiently different.
>
> With smooth_triangles, even though the vertex coordinates are the same,
> sometimes I get the degenerate triangle warning when working out the vertex
> normal vectors.
>
> When I use the corners of the square to calculate the normals, the edge between
> the two triangles of the square softens/goes away, but the edges between all of
> the squares are still pretty abrupt.
> When I try to use a small dy or dx offset to calculate the normals, I get a lot
> of the degenerate triangle warnings and few if any visible triangles.  Not sure
> why.
>
> So:
>
> When calculating the normals, do I use the remaining two triangle vertices, or
> the orthogonal edge vectors of the square?
> Do I normalize the vectors before using vcross()?
> Do I normalize the resulting vertex normal vectors?

There are several possible ways to create normals for a triangle mesh.
One of them is described in the first answer here:

"Calculating normals in a triangle mesh"
https://stackoverflow.com/questions/6656358/calculating-normals-in-a-triangle-mesh

A couple of the other answers also contain some useful information.
I would also suggest that you explore the "Linked" and "Related"

Some more ways to calculate the normals are described in this article:
"A Comparison of Algorithms for Vertex Normal Computation"

I think that there are even more sensible ways to calculate the normals,

--
Tor Olav
http://subcube.com
https://github.com/t-o-k
```
 From: Bald Eagle Subject: Re: smooth_triangle normals Date: 26 Sep 2020 21:15:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5f6fe75eaf8e23f91f9dae300%40news.povray.org",
"dateCreated": "2020-09-27T01:15:00+00:00",
"datePublished": "2020-09-27T01:15:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
Expecting this to be super helpful.  Maybe some of those will rectify the
visible tiling.

Still perplexed about why normal vector values would cause POV-Ray to report
degenerate triangles.

Just for reference:
#ifdef () doesn't preempt negative subscript or subscript out of range errors.

One should likely protect code with index < 0 or index > dimension_size-1
checks.

Thanks, Tor.

-BW
```
 From: Tor Olav Kristensen Subject: Re: smooth_triangle normals Date: 28 Sep 2020 12:15:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5f720b18af8e23f9468a310e0%40news.povray.org",
"dateCreated": "2020-09-28T16:15:01+00:00",
"datePublished": "2020-09-28T16:15:01+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Expecting this to be super helpful.  Maybe some of those will rectify the
> visible tiling.
>
> Still perplexed about why normal vector values would cause POV-Ray to report
> degenerate triangles.

Have you verified that none of the normal vectors are zero vectors or have a
very short length ?

Does POV-Ray accept the triangles in the mesh when you do not add the normal
vectors ?

> Just for reference:
> #ifdef () doesn't preempt negative subscript or subscript out of range errors.
>
> One should likely protect code with index < 0 or index > dimension_size-1
> checks.

- Or write code that does not create out of range indices...

--
Tor Olav
http://subcube.com
https://github.com/t-o-k
```
 From: Leroy Subject: Re: smooth_triangle normals Date: 30 Sep 2020 18:50:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5f750906af8e23f9279beb8e0%40news.povray.org",
"dateCreated": "2020-09-30T22:50:00+00:00",
"datePublished": "2020-09-30T22:50:00+00:00",
"author": {
"@type": "Person",
"name": "Leroy"
}
}
"
> When calculating the normals, do I use the remaining two triangle vertices, or
> the orthogonal edge vectors of the square?
You lost me here with the "orthogonal edge vectors of the square".
I would always use triangle vertices.

> Do I normalize the vectors before using vcross()?
I never do.

> Do I normalize the resulting vertex normal vectors?
Yes! Well, I usually do mesh2, I add all the normals for a point togather then
normalize that.

How are you filling the smooth_triangle.
From the sound of it, a normal and a triangle values may be switched.

Hope this helps some.

Have Fun!
```
 From: Bald Eagle Subject: Re: smooth_triangle normals Date: 1 Oct 2020 16:35:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5f763c8daf8e23f91f9dae300%40news.povray.org",
"dateCreated": "2020-10-01T20:35:01+00:00",
"datePublished": "2020-10-01T20:35:01+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:

> > Still perplexed about why normal vector values would cause POV-Ray to report
> > degenerate triangles.
>
> Have you verified that none of the normal vectors are zero vectors or have a
> very short length ?

I have not - I was mostly just trying to get the code to _work_ in the short
blocks of time I had available to struggle with it.   I did not think it was
possible or probably, as the normal vector was calculated as a _sum_, implying
that the sum of all the vectors would have had to be very small or zero.  And I
was adding more vectors to code that previously worked....

But it had occurred to me to do that and I should do the checks.
I was just surprised that the normal triggered a degenerate triangle warning.

> Does POV-Ray accept the triangles in the mesh when you do not add the normal
> vectors ?

Yes.  In terms of the fact that I was using union {}, not mesh {}.

> - Or write code that does not create out of range indices...

That's just a patently absurd assertion.  ;P
```