|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Kenneth" <kdw### [at] gmailcom> wrote:
> Hey guys, what I'm seeing is that this and the original version of Theta look
> the same in the isosurface-- or else I'm totally mistaken about what B.E.'s
> original problem was?? I thought it was the truncated spirals in -x, where they
> abruptly stop at y=0. Take a look at my comparison image.
>
> Sorry if I totally misunderstood the problem(?)
Nope - you got it.
I had a few spare minutes last night and pasted Chris' fix into my scene and it
worked as claimed.
Maybe start with a fresh copy of my scene and make the minimum necessary
correction.
(comment out my Theta function, and just paste Chris' 2 functions in after
that.)
I'm guessing that you have something in your scene that snuck in that you
haven't undone.
- BW
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
> >
> > Sorry if I totally misunderstood the problem(?)
>
> Nope - you got it.
> I had a few spare minutes last night and pasted Chris' fix into my scene and it
> worked as claimed.
>
> Maybe start with a fresh copy of my scene and make the minimum necessary
> correction.
> (comment out my Theta function, and just paste Chris' 2 functions in after
> that.)
>
> I'm guessing that you have something in your scene that snuck in that you
> haven't undone.
>
Interesting! I need to take another look at that. Admittedly, my eyes and brain
were starting to fuzz over from hours of 'ultra concentration' (although I
thought I double-checked everything before posting...)
Meanwhile...
I came up with this little change for your own code, using 'clamp'. It might be
considered a 'hack', but it solves two problems at once: no more truncated
spirals; and the rifling is now continuous in both +x and -x (with no glitch at
x=0.)
#declare Helix = function {select (mod (Theta(clamp(x,0,1.0),y,z),
tau/3) - tau/6, 0.25, 0.35)}
Limitations:
clamp's 'max' value needs to be 1.0 (or any integer multiple of 1.0; it doesn't
seem to matter.) But no fractional part.
The first tau's divisor: any integer of 1.0 or greater, no fractional part.
The second tau's divisor can be anything > 1.0, any float value.
Post a reply to this message
Attachments:
Download 'rifling_for_be_3__kw.jpg' (261 KB)
Preview of image 'rifling_for_be_3__kw.jpg'
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Chris R" <car### [at] comcastnet> wrote:
>
> > I got it to work by making the following change:
> >
> > #declare natan2 = function(a,b) { select(a, 2*pi+atan2(a,b), atan2(a,b)) }
> > #declare Theta = function {((natan2 (y, z))/pi)*tau + x*tau}
> >
> > The problem is that atan2 has that discontinuity where it jumps from pi/2 to
> > -pi/2, which happens along the edge you are looking at, and is made visible by
> > the switch in sign of the x value (x*tau). The natan2 puts that discontinuity
> > at opposite ends of the value range, rather than in the middle and makes all of
> > the resulting angles positive (0-2*pi), and thus there is no abrupt switch when
> > x goes negative.
> >
> > -- Chris R
>
> Most Excellent, fine Sir!
> Some days I can see what needs to be done - other days it's more . . . opaque.
>
> I'm officially voting that such be made an internal function, or at least
> something available in functions.inc
>
> This could save a lot of people a lot of trouble in the future.
>
> Thank you,
>
> - BW
No problem. I don't know how many times I have been tripped up by how atan2
works.
If you grab my libfn.inc from GitHub, https://github.com/carath63/povlibrary I
have defined f_normalized_atan2(x,y) already. It would be good to have as a
builtin in a future version of pov-ray, but in the meantime, if you are using
any of my code in your scenes, it is already defined there.
-- Chris R
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Chris R" <car### [at] comcastnet> wrote:
>...
> I got it to work by making the following change:
>
> #declare natan2 = function(a,b) { select(a, 2*pi+atan2(a,b), atan2(a,b)) }
> #declare Theta = function {((natan2 (y, z))/pi)*tau + x*tau}
>
> The problem is that atan2 has that discontinuity where it jumps from pi/2 to
> -pi/2, ...
Hi Chris
I think that should be "from +pi to -pi".
I would also suggest that you define your new atan2() function like this;
#declare natan2 =
function(a, b) {
atan2(a, b) + select(a, 2*pi, 0)
}
;
It makes what happens a little bit clearer at the expense of an extra addition.
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "Chris R" <car### [at] comcastnet> wrote:
> >...
> > I got it to work by making the following change:
> >
> > #declare natan2 = function(a,b) { select(a, 2*pi+atan2(a,b), atan2(a,b)) }
> > #declare Theta = function {((natan2 (y, z))/pi)*tau + x*tau}
> >
> > The problem is that atan2 has that discontinuity where it jumps from pi/2 to
> > -pi/2, ...
>
> Hi Chris
>
> I think that should be "from +pi to -pi".
>
> I would also suggest that you define your new atan2() function like this;
>
> #declare natan2 =
> function(a, b) {
> atan2(a, b) + select(a, 2*pi, 0)
> }
> ;
>
> It makes what happens a little bit clearer at the expense of an extra addition.
I just noticed that both these variants have a little problem:
They have a discontinuity at a = -0
natan2(+1e-100, -1) = +3.141592653589793
natan2( +0, -1) = +3.141592653589793
natan2( -0, -1) = -3.141592653589793
natan2(-1e-100, -1) = +3.141592653589793
This variant does not have this problem:
#declare natan2 =
function(a, b) {
mod(atan2(a, b) + 2*pi, 2*pi)
}
;
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > "Chris R" <car### [at] comcastnet> wrote:
> > >...
> > > I got it to work by making the following change:
> > >
> > > #declare natan2 = function(a,b) { select(a, 2*pi+atan2(a,b), atan2(a,b)) }
> > > #declare Theta = function {((natan2 (y, z))/pi)*tau + x*tau}
> > >
> > > The problem is that atan2 has that discontinuity where it jumps from pi/2 to
> > > -pi/2, ...
> >
> > Hi Chris
> >
> > I think that should be "from +pi to -pi".
> >
> > I would also suggest that you define your new atan2() function like this;
> >
> > #declare natan2 =
> > function(a, b) {
> > atan2(a, b) + select(a, 2*pi, 0)
> > }
> > ;
> >
> > It makes what happens a little bit clearer at the expense of an extra addition.
>
> I just noticed that both these variants have a little problem:
> They have a discontinuity at a = -0
>
> natan2(+1e-100, -1) = +3.141592653589793
> natan2( +0, -1) = +3.141592653589793
> natan2( -0, -1) = -3.141592653589793
> natan2(-1e-100, -1) = +3.141592653589793
>
> This variant does not have this problem:
>
> #declare natan2 =
> function(a, b) {
> mod(atan2(a, b) + 2*pi, 2*pi)
> }
> ;
>
> --
> Tor Olav
> http://subcube.com
> https://github.com/t-o-k
Good catch!
I actually modified f_normalized_atan2 as follows:
#declare f_normalized_atan2 = function(x,y) {
select(x,
tau + atan2(x,y),
pi,
atan2(x,y)
)
}
It's infinitesimally more efficient because you don't have to calculate
atan2(+/-0,N), and gets rid of the mod arithmetic and addition where it isn't
needed.
-- Chris R
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Chris R" <car### [at] comcastnet> wrote:
>...
> Good catch!
>
> I actually modified f_normalized_atan2 as follows:
>
> #declare f_normalized_atan2 = function(x,y) {
> select(x,
> tau + atan2(x,y),
> pi,
> atan2(x,y)
> )
> }
>
> It's infinitesimally more efficient because you don't have to calculate
> atan2(+/-0,N), and gets rid of the mod arithmetic and addition where it isn't
> needed.
Sorry Chris,
It looked promising, but f_normalized_atan2(0, 1) returns pi instead of 0.
Rewriting it like this will solve that problem:
#declare f_normalized_atan2 =
function(x, y) {
select(
x,
atan2(x, y) + 2*pi,
select(y, pi, 0),
atan2(x, y)
)
}
;
Note that all these rewrites of the atan2() function does not trigger a "Domain
error", like atan2(0, 0) does when called outside a function.
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Below are the results of some atan2-tests I just did.
Some constants:
pi/2 = 1.570796326794897
pi = 3.141592653589793
3*pi/2 = 4.712388980384690
2*pi = 6.283185307179586
tau = 2*pi
Z = 1e-100
Here the functions are given valid arguments:
The results for atan2() are all in the closed interval [-pi, +pi]
atan2(-0, -1) = -3.141592653589793
atan2(-Z, -1) = -3.141592653589793
atan2(-1, -Z) = -1.570796326794897
atan2(-1, -0) = -1.570796326794897
atan2(-1, +0) = -1.570796326794897
atan2(-1, +Z) = -1.570796326794897
atan2(-Z, +1) = -0
atan2(-0, +1) = -0
atan2(+0, +1) = +0
atan2(+Z, +1) = +0
atan2(+1, +Z) = +1.570796326794897
atan2(+1, +0) = +1.570796326794897
atan2(+1, -0) = +1.570796326794897
atan2(+1, -Z) = +1.570796326794897
atan2(+Z, -1) = +3.141592653589793
atan2(+0, -1) = +3.141592653589793
Atan2_Fn =
function(a, b) {
mod(atan2(a, b) + tau, tau)
}
The results for Atan2_Fn() are all in the half-open interval [+0, +tau)
Atan2_Fn(-Z, +1) = +0
Atan2_Fn(-0, +1) = +0
Atan2_Fn(+0, +1) = +0
Atan2_Fn(+Z, +1) = +0
Atan2_Fn(+1, +Z) = +1.570796326794897
Atan2_Fn(+1, +0) = +1.570796326794897
Atan2_Fn(+1, -0) = +1.570796326794897
Atan2_Fn(+1, -Z) = +1.570796326794897
Atan2_Fn(+Z, -1) = +3.141592653589793
Atan2_Fn(+0, -1) = +3.141592653589793
Atan2_Fn(-0, -1) = +3.141592653589793
Atan2_Fn(-Z, -1) = +3.141592653589793
Atan2_Fn(-1, -Z) = +4.712388980384690
Atan2_Fn(-1, -0) = +4.712388980384690
Atan2_Fn(-1, +0) = +4.712388980384690
Atan2_Fn(-1, +Z) = +4.712388980384690
n_atan2 =
function(a, b) {
atan2(a, b) + select(a, tau, 0)
}
The results for n_atan2() should all be in the half-open interval [+0, +tau)
n_atan2(-Z, +1) = +6.283185307179586 <--- NB
n_atan2(-0, +1) = +0
n_atan2(+0, +1) = +0
n_atan2(+Z, +1) = +0
n_atan2(+1, +Z) = +1.570796326794897
n_atan2(+1, +0) = +1.570796326794897
n_atan2(+1, -0) = +1.570796326794897
n_atan2(+1, -Z) = +1.570796326794897
n_atan2(+Z, -1) = +3.141592653589793
n_atan2(+0, -1) = +3.141592653589793
n_atan2(-0, -1) = -3.141592653589793 <--- NB !!!
n_atan2(-Z, -1) = +3.141592653589793
n_atan2(-1, -Z) = +4.712388980384690
n_atan2(-1, -0) = +4.712388980384690
n_atan2(-1, +0) = +4.712388980384690
n_atan2(-1, +Z) = +4.712388980384690
f_normalized_atan2 =
function(a, b) {
select(
a,
atan2(a, b) + tau,
select(b, pi, 0),
atan2(a, b)
)
}
The results for f_normalized_atan2() are all in the half-open interval [+0,
+tau)
f_normalized_atan2(-Z, -1) = +3.141592653589793
f_normalized_atan2(-0, -1) = +3.141592653589793
f_normalized_atan2(+0, -1) = +3.141592653589793
f_normalized_atan2(+Z, -1) = +3.141592653589793
f_normalized_atan2(-Z, +1) = +6.283185307179586 <--- NB
f_normalized_atan2(-0, +1) = +0
f_normalized_atan2(+0, +1) = +0
f_normalized_atan2(+Z, +1) = +0
f_normalized_atan2(+1, -Z) = +1.570796326794897
f_normalized_atan2(+1, -0) = +1.570796326794897
f_normalized_atan2(+1, +0) = +1.570796326794897
f_normalized_atan2(+1, +Z) = +1.570796326794897
f_normalized_atan2(-1, -Z) = +4.712388980384690
f_normalized_atan2(-1, -0) = +4.712388980384690
f_normalized_atan2(-1, +0) = +4.712388980384690
f_normalized_atan2(-1, +Z) = +4.712388980384690
Here the functions are given invalid arguments:
Atan2 =
function(a, b) {
atan2(a, b)
}
Atan2(-0, -0) = -3.141592653589793
Atan2(-0, +0) = -0
Atan2(+0, +0) = +0
Atan2(+0, -0) = +3.141592653589793
Atan2_Fn =
function(a, b) {
mod(atan2(a, b) + tau, tau)
}
Atan2_Fn(+0, +0) = +0
Atan2_Fn(+0, -0) = +3.141592653589793
Atan2_Fn(-0, -0) = +3.141592653589793
Atan2_Fn(-0, +0) = +0
n_atan2 =
function(a, b) {
atan2(a, b) + select(a, tau, 0)
}
n_atan2(+0, +0) = +0
n_atan2(+0, -0) = +pi
n_atan2(-0, -0) = -pi <--- NB !!!
n_atan2(-0, +0) = +0
f_normalized_atan2 =
function(a, b) {
select(
a,
atan2(a, b) + tau,
select(b, pi, 0),
atan2(a, b)
)
}
f_normalized_atan2(+0, +0) = +0
f_normalized_atan2(-0, +0) = +0
f_normalized_atan2(-0, -0) = +0
f_normalized_atan2(+0, -0) = +0
When looking at the results from both the valid and invalid arguments, it seems
to me that POV-Ray's built in atan2() gives the most consistent results,
followed by Atan2_Fn().
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> Below are the results of some atan2-tests I just did.
>
> Some constants:
>
> pi/2 = 1.570796326794897
> pi = 3.141592653589793
> 3*pi/2 = 4.712388980384690
> 2*pi = 6.283185307179586
>
> tau = 2*pi
>
> Z = 1e-100
>
>
> Here the functions are given valid arguments:
>
> The results for atan2() are all in the closed interval [-pi, +pi]
>
> atan2(-0, -1) = -3.141592653589793
> atan2(-Z, -1) = -3.141592653589793
>
> atan2(-1, -Z) = -1.570796326794897
> atan2(-1, -0) = -1.570796326794897
> atan2(-1, +0) = -1.570796326794897
> atan2(-1, +Z) = -1.570796326794897
>
> atan2(-Z, +1) = -0
> atan2(-0, +1) = -0
>
> atan2(+0, +1) = +0
> atan2(+Z, +1) = +0
>
> atan2(+1, +Z) = +1.570796326794897
> atan2(+1, +0) = +1.570796326794897
> atan2(+1, -0) = +1.570796326794897
> atan2(+1, -Z) = +1.570796326794897
>
> atan2(+Z, -1) = +3.141592653589793
> atan2(+0, -1) = +3.141592653589793
>
>
> Atan2_Fn =
> function(a, b) {
> mod(atan2(a, b) + tau, tau)
> }
>
> The results for Atan2_Fn() are all in the half-open interval [+0, +tau)
>
> Atan2_Fn(-Z, +1) = +0
> Atan2_Fn(-0, +1) = +0
> Atan2_Fn(+0, +1) = +0
> Atan2_Fn(+Z, +1) = +0
>
> Atan2_Fn(+1, +Z) = +1.570796326794897
> Atan2_Fn(+1, +0) = +1.570796326794897
> Atan2_Fn(+1, -0) = +1.570796326794897
> Atan2_Fn(+1, -Z) = +1.570796326794897
>
> Atan2_Fn(+Z, -1) = +3.141592653589793
> Atan2_Fn(+0, -1) = +3.141592653589793
> Atan2_Fn(-0, -1) = +3.141592653589793
> Atan2_Fn(-Z, -1) = +3.141592653589793
>
> Atan2_Fn(-1, -Z) = +4.712388980384690
> Atan2_Fn(-1, -0) = +4.712388980384690
> Atan2_Fn(-1, +0) = +4.712388980384690
> Atan2_Fn(-1, +Z) = +4.712388980384690
>
>
> n_atan2 =
> function(a, b) {
> atan2(a, b) + select(a, tau, 0)
> }
>
> The results for n_atan2() should all be in the half-open interval [+0, +tau)
>
> n_atan2(-Z, +1) = +6.283185307179586 <--- NB
> n_atan2(-0, +1) = +0
> n_atan2(+0, +1) = +0
> n_atan2(+Z, +1) = +0
>
> n_atan2(+1, +Z) = +1.570796326794897
> n_atan2(+1, +0) = +1.570796326794897
> n_atan2(+1, -0) = +1.570796326794897
> n_atan2(+1, -Z) = +1.570796326794897
>
> n_atan2(+Z, -1) = +3.141592653589793
> n_atan2(+0, -1) = +3.141592653589793
> n_atan2(-0, -1) = -3.141592653589793 <--- NB !!!
> n_atan2(-Z, -1) = +3.141592653589793
>
> n_atan2(-1, -Z) = +4.712388980384690
> n_atan2(-1, -0) = +4.712388980384690
> n_atan2(-1, +0) = +4.712388980384690
> n_atan2(-1, +Z) = +4.712388980384690
>
>
> f_normalized_atan2 =
> function(a, b) {
> select(
> a,
> atan2(a, b) + tau,
> select(b, pi, 0),
> atan2(a, b)
> )
> }
>
> The results for f_normalized_atan2() are all in the half-open interval [+0,
> +tau)
>
> f_normalized_atan2(-Z, -1) = +3.141592653589793
> f_normalized_atan2(-0, -1) = +3.141592653589793
> f_normalized_atan2(+0, -1) = +3.141592653589793
> f_normalized_atan2(+Z, -1) = +3.141592653589793
>
> f_normalized_atan2(-Z, +1) = +6.283185307179586 <--- NB
> f_normalized_atan2(-0, +1) = +0
> f_normalized_atan2(+0, +1) = +0
> f_normalized_atan2(+Z, +1) = +0
>
> f_normalized_atan2(+1, -Z) = +1.570796326794897
> f_normalized_atan2(+1, -0) = +1.570796326794897
> f_normalized_atan2(+1, +0) = +1.570796326794897
> f_normalized_atan2(+1, +Z) = +1.570796326794897
>
> f_normalized_atan2(-1, -Z) = +4.712388980384690
> f_normalized_atan2(-1, -0) = +4.712388980384690
> f_normalized_atan2(-1, +0) = +4.712388980384690
> f_normalized_atan2(-1, +Z) = +4.712388980384690
>
>
> Here the functions are given invalid arguments:
>
> Atan2 =
> function(a, b) {
> atan2(a, b)
> }
>
> Atan2(-0, -0) = -3.141592653589793
> Atan2(-0, +0) = -0
> Atan2(+0, +0) = +0
> Atan2(+0, -0) = +3.141592653589793
>
>
> Atan2_Fn =
> function(a, b) {
> mod(atan2(a, b) + tau, tau)
> }
>
> Atan2_Fn(+0, +0) = +0
> Atan2_Fn(+0, -0) = +3.141592653589793
> Atan2_Fn(-0, -0) = +3.141592653589793
> Atan2_Fn(-0, +0) = +0
>
>
> n_atan2 =
> function(a, b) {
> atan2(a, b) + select(a, tau, 0)
> }
>
> n_atan2(+0, +0) = +0
> n_atan2(+0, -0) = +pi
> n_atan2(-0, -0) = -pi <--- NB !!!
> n_atan2(-0, +0) = +0
>
>
> f_normalized_atan2 =
> function(a, b) {
> select(
> a,
> atan2(a, b) + tau,
> select(b, pi, 0),
> atan2(a, b)
> )
> }
>
> f_normalized_atan2(+0, +0) = +0
> f_normalized_atan2(-0, +0) = +0
> f_normalized_atan2(-0, -0) = +0
> f_normalized_atan2(+0, -0) = +0
>
>
> When looking at the results from both the valid and invalid arguments, it seems
> to me that POV-Ray's built in atan2() gives the most consistent results,
> followed by Atan2_Fn().
>
> --
> Tor Olav
> http://subcube.com
> https://github.com/t-o-k
Nice analysis of the various options!
I have adopted your updated f_normalized_atan2, which I find works well with my
isosurfaces. Others may have different expectations and use a different
implementation.
My question would be, (and I should look at the pov code at some point to
check), when an isosurface is being evaluated, are there cases where -0 is
supplied to the isosurface function?
-- Chris R
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 12/27/24 09:27, Chris R wrote:
> My question would be, (and I should look at the pov code at some point to
> check), when an isosurface is being evaluated, are there cases where -0 is
> supplied to the isosurface function?
Might be. It depends on the function(s) being used in the isosurface and
what x,y,z values you might see given, environmental-usage of the
isosurface. Also, potentially, on the build compile for the executable.
Using the f_boom() inbuilt in the yuqk fork:
//--- Should be the f_sphere() version of this will run in v3.8 beta 2
#version 3.8;
#include "functions.inc"
isosurface {
function { f_boom(x/-2,y,z,0/-2,0,0) }
//function { f_sphere(x/-2,y,z-1,0.1) }
contained_by { box { -2.0,2.0 } }
threshold 0
accuracy 0.0005
max_gradient 1.1
finish { emission 1.0 }
}
//---
f_boom
1(x) -> -0,
2(y) -> 0,
3(z) -> 0,
4(0) -> -0,
5(1) -> 0,
6(2) -> 0
Bill P.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|