|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> I think the most useful thing to do at this point would be to ditch the
> isosurface renderings and simply start graphing the equations to see where
> things get out of joint.
So, here's a Desmos graph of what I was striving to implement in SDL.
We're going around in a circle, but we want to graph things in rectangular
coordinates, so we pretend x is theta, and take the cos and sin of "theta" to
give our "x" and y coordinates.
then we take the atan y/x (atan2(y, x) in SDL) to get the angle.
As you can see from the green lines, you go from -pi/2 to pi/2
Next, we add pi/2 to go from 0 to pi, and dive it all by pi to go from 0 to 1
(purple lines)
Multiplying by tau, we get a full 2*pi radians around the circle (red lines)
Applying the Helix function, we switch between radii of 0.5 and 1, based upon
using modulo to select () the number of grooves we want in our rifling (g)
(orange lines)
https://www.desmos.com/calculator/wa4avaopd1
- BW
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > This is pretty nice, and I will definitely be using your library, as it's the
> > only nice/efficient way to make some good barrel rifling.
>
> POV-Ray absolutely drives me mad - on many occasions.
>
> I have a nice rifling cross section function, but for some reason - as of yet
> unknown to me, it behaves very badly when x is negative - as shown to the left
> of the origin.
>
> I could fix/hack it - but I'd like to know WHY it occurs.
> Even more baffling is when the twist rate is set very high - then the helix
> disappears completely.
>
>
>
> #version 3.8;
> global_settings {assumed_gamma 1.0 }
>
> #include "math.inc"
> #include "functions.inc"
> camera {
> location <12, 0, -25>
> right x*image_width/image_height
> up y
> look_at <12, 0, 0>
> rotate -y*10
> }
>
> light_source {<10, 5, -10> rgb 1}
>
> sky_sphere {pigment {rgb 1}}
>
> #declare E = 0.00001;
>
> #declare Dia = 0.4;
>
> #declare Axis = 0.01;
> cylinder {<-30, 0, 0>, <30, 0, 0> Axis pigment {rgb x}}
> cylinder {<0, -Dia*2, 0>, <0, Dia*2, 0> Axis pigment {rgb y}}
> cylinder {<0, 0, -Dia*2>, <0, 0, Dia*2> Axis pigment {rgb z}}
>
> #declare fmod = function (Value, Modulo) {select (Value, 1 - mod (abs (Value),
> Modulo), mod (abs (Value), Modulo))} // this gives a mod function that remains
> consistant across the origin
> //#declare Theta = function {atan2 (y, z)+tau + x*tau}
> #declare Theta = function {((atan2 (y, z)+pi)/pi)*tau + x*tau} // adds a
> multiple of x to produce the helix
>
> #declare dist = function {sqrt (y*y + z*z)}
>
> #declare Helix = function {select (mod (Theta(x, y, z), tau/3) - tau/6, 0.308,
> 0.35)} // modulates the radius to produce the rifling
>
> #declare Rifling = function {dist (x, y, z) - Helix (x/12, y, z)}
>
> #declare IS =
> isosurface {
> function {Rifling(x,y,z)}
> contained_by { box { <-12, -Dia, -Dia>, <24, Dia, Dia> } }
> accuracy 0.0001
> max_gradient 50
> open
>
> texture {
> pigment {rgb 1}
> } // end texture
>
> interior_texture {
> pigment {rgb <1, 0, 0>}
> } // end texture
>
> } // end isosurface
>
> object {IS}
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
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, 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
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Chris R" <car### [at] comcastnet> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> First - let me start off by saying that your annotated summary render is
> absolutely beautiful.
> I don't know if you have a standard scene all rigged up for that kind of
> thing - but it's really nice.
Thanks! No, nothing special; I just set up a simple scene for your code (with
two lights in specific locations to see some particular details), made some
renders, then brought them into paint.net for assembly and annotation. A bit of
work, but fun.
Before seeing Chris R's comments, I had been going back over your code yet again
(for hours, ha). It's a really cool piece of work, that has a lot of uses
besides rifling.
> [Chris R:]
> 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}
>
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(?)
Post a reply to this message
Attachments:
Download 'be_vs_chris_r_theta__by_kw.jpg' (134 KB)
Preview of image 'be_vs_chris_r_theta__by_kw.jpg'
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
|
|