POV-Ray : Newsgroups : povray.newusers : Add twist to isosurface : Re: Add twist to isosurface Server Time
27 Jun 2024 17:20:18 EDT (-0400)
  Re: Add twist to isosurface  
From: StephenS
Date: 24 Jun 2012 17:45:01
Message: <web.4fe78a498a20243758ec92320@news.povray.org>
kurtz le pirate <kur### [at] yahoofr> wrote:
> Hello,
>
> I made a simple isosurface defined as a cylinder minus a groove :
>
>   function { sqrt(pow(x,2) + pow(z,2)) - Groove(x,z) }
>
> with :
>
>   Groove = function(a,b) { R + q - 2*q*abs(cos(ang(a,b)))}
>
>
> Now, a want to twist this isosurface along y axis. I found on Internet
> that, x and z must be modified with functions like this :
>
>   TwistX = function { x*cos(a*y) - z*sin(a*y) }
>   TwistZ = function { x*sin(a*y) + z*cos(a*y) }
>
>
> ok... but how to 'put' this twist's functions 'in' my main isosurface
> function ?
>
>
> this should be simple, but I can not do :(
>
>
> thanks.
> --
> klp
A working scene would be easier.

This is a scene I keep to help me with twisting.

****
// perspective (default) camera
camera {
  location  <0.0, 2.0, -5.0>
  look_at   <0.0, 0.0,  0.0>
  right     x*image_width/image_height
}
// create a regular point light source
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate <-20, 40, -20>
}
// sets the default texture that objects get when they have no texture specified
#default {
  texture { pigment {color red 1} finish{ambient 0.2} }
}

// Set a color of the background (sky)
background { color rgb< 1, 1, 1> }

// internal functions usable in user defined functions
// for example for isosurfaces and function pattern
#include "functions.inc"

box{<-1,-.5,-.5>,<1,.5,.5>
 //rotate<0,90,0> //for end view
 }

isosurface{
 function { max((x*x-2),(y*y-.25),(z*z-.25)) }
 contained_by { box{<-1,-1,-1>,<1,1,1>} }
 max_gradient 1.8
 //rotate<0,90,0> //for end view
 translate<0,1.5,0>
}

#declare N_turns=.125; // per pov unit
isosurface{
//function { max((x*x-2),(y*y-.25),(z*z-.25)) }
                                                    // replace y with
z*sin(x*2*pi*N) + y*cos(x*2*pi*N)
                                                    // replace z with
z*cos(x*2*pi*N) - y*sin(x*2*pi*N)
  function { max((x*x-2.),((z*sin(x*2*pi*N_turns) +
y*cos(x*2*pi*N_turns))*(z*sin(x*2*pi*N_turns) +
y*cos(x*2*pi*N_turns))-.25),((z*cos(x*2*pi*N_turns) -
y*sin(x*2*pi*N_turns))*(z*cos(x*2*pi*N_turns) - y*sin(x*2*pi*N_turns))-.25)) }
  contained_by { box{<-1,-1,-1>,<1,1,1>} }
  max_gradient 2.91
  //rotate<0,90,0> //for end view
  translate<0,-1.5,0>
}

#declare N_turns=-.125; // per pov unit, turn other direction
isosurface{
//function { max((x*x-2),(y*y-.25),(z*z-.25)) }
                                                    // replace y with
z*sin(x*2*pi*N) + y*cos(x*2*pi*N)
                                                    // replace z with
z*cos(x*2*pi*N) - y*sin(x*2*pi*N)
  function { max((x*x-2.),((z*sin(x*2*pi*N_turns) +
y*cos(x*2*pi*N_turns))*(z*sin(x*2*pi*N_turns) +
y*cos(x*2*pi*N_turns))-.25),((z*cos(x*2*pi*N_turns) -
y*sin(x*2*pi*N_turns))*(z*cos(x*2*pi*N_turns) - y*sin(x*2*pi*N_turns))-.25)) }
  contained_by { box{<-1,-1,-1>,<1,1,1>} }
  max_gradient 2.91
  //rotate<0,90,0> //for end view
  translate<2.5,-1.5,0>
}

#declare N_turns=.125; // per pov unit, also turn other direction
isosurface{
//function { max((x*x-2),(y*y-.25),(z*z-.25)) }
                                                    // replace y with
z*sin(x*2*pi*N) - y*cos(x*2*pi*N)
                                                    // replace z with
z*cos(x*2*pi*N) + y*sin(x*2*pi*N)
  function { max((x*x-2.),((z*sin(x*2*pi*N_turns) -
y*cos(x*2*pi*N_turns))*(z*sin(x*2*pi*N_turns) -
y*cos(x*2*pi*N_turns))-.25),((z*cos(x*2*pi*N_turns) +
y*sin(x*2*pi*N_turns))*(z*cos(x*2*pi*N_turns) + y*sin(x*2*pi*N_turns))-.25)) }
  contained_by { box{<-1,-1,-1>,<1,1,1>} }
  max_gradient 2.91
  //rotate<0,90,0> //for end view
  translate<-2.5,-1.5,0>
}
**** be carefull of word wrap.

for you, it might be....

//function { sqrt(pow(x,2) + pow(z,2)) - Groove(x,z) }

function { sqrt(
pow(x,2)
+ pow(z,2)
)) - Groove(x,z)
}

function { sqrt(
pow(x*cos(a*y) - z*sin(a*y),2)
+ pow(x*sin(a*y) + z*cos(a*y),2)
)) - Groove(x*cos(a*y) - z*sin(a*y),x*sin(a*y) + z*cos(a*y))
}


Hope this helps:-)

Stephen S


Post a reply to this message

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