POV-Ray : Newsgroups : povray.programming : [Patch] Function-normal patch update -- and bug Server Time
28 Jul 2024 18:17:16 EDT (-0400)
  [Patch] Function-normal patch update -- and bug (Message 1 to 1 of 1)  
From: Lummox JR
Subject: [Patch] Function-normal patch update -- and bug
Date: 15 Jul 1999 00:47:47
Message: <378D6816.7A40@aol.com>
Thought people might be interested in how my new patch is going.
Although isosurfaces would benefit a lot from the ability to calculate
function normals, I ran into a snag when applying the patch to work with
isosurfaces (it already is used for the new isoblobs).

The snag, interestingly enough, is with atan2(), a function I added to
the repertoire myself. The function calculates just fine, in regular and
interval solving (and besides, I'm using method 2 to solve for the
intersections), but the function normal doesn't seem to work for some
reason. In the test scene, an item meant to look sort of like a string
of pearls (with noise added, it looks like rocks) has weird gaps in it;
and the gaps are symmetrical about the yz plane.
Here's where it gets weird. If I replace atan2(x,z) with atan(z/x), or
with acos(x/sqrt(sqr(x)+sqr(z))), it works just fine for the test scene
(which doesn't need to worry about extra accuracy). And if I go back to
the old method of finding an isosurface normal, it still works--so the
problem is with the normal calculation of with atan2().

This is the formula I'm basing atan2()'s normal on, which should work:

d(atan2(x,y)) = d(atan(y/x) = 1/[1+(y/x)^2] * d(y/x)
              = (x^2/(x^2+y^2)) * (x*dy - y*dx)/(x^2)
              = (x*dy - y*dx)/(x^2+y^2)

Makes sense, right? (I hope so! I'm going to go back into my old
calculus book to try to verify it.) Well, it doesn't always work. There
seem to be some spots where the function has "gaps"--gaps which aren't
really there, since the surface of the function is found just fine, but
it's just the normal that's the problem.
And here's the real kicker: Replacing the norm_atan2() code with code
that fudges atan2() by using one of the above substitutions (such as
atan(y/x)) doesn't ever seem to work right. The gaps are closed if I do
so, but one half of the output has the wrong normal, or some such. I
can't figure this out.
Since I don't know the atan2() function that's used internally
(int_atan2() is written to work with two different possible ways of
implementing the function, since I imagine it could be written
differently on different platforms), it's hard to work around the
norm_atan2() problem.

But at any rate, the patch works for most other functions--it should
certainly work for existing scenes (other than the one it's failing with
now), at any rate, since atan2() appears to be the only problem
function. I might have to try out some other people's Superpatch scenes
that use the isosurface, just to see how it handles those; any
volunteers?

Lummox JR


Post a reply to this message

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