POV-Ray : Newsgroups : povray.advanced-users : rotating parallel to surface normal Server Time
25 Nov 2024 05:27:34 EST (-0500)
  rotating parallel to surface normal (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: Doug Eichenberg
Subject: rotating parallel to surface normal
Date: 25 Jul 2003 19:48:13
Message: <3f21c1bd$1@news.povray.org>
Let's say I have an object "A" at the origin, and a known surface normal
<x,y,z>.  I want to find the rotation vector <Rx,Ry,Rz> of the surface
normal <x,y,z>, such that when I rotate "A":

object{ A rotate<Rx,Ry,Rz> }

it lies along the surface normal.

I tried doing this as follows:

object{ A rotate<atan2d(Norm.y,Norm.z), atan2d(Norm.x,Norm.z),
atan2d(Norm.x,Norm.y)>

but I seem to be getting strange results.

Anyone have code they used for doing this?  Or know how in general?
Thanks for the help.

--
Doug Eichenberg
www.getinfo.net/douge
dou### [at] nlsnet


Post a reply to this message

From: Florian Brucker
Subject: Re: rotating parallel to surface normal
Date: 26 Jul 2003 10:24:23
Message: <3f228f17$1@news.povray.org>
Hey Doug!

Perphaps the "Reorient_Trans"-macro from "transforms.inc" could help you?
Check out its description at http://www.povray.org/documentation/view/281/

HTH,
Florian


Post a reply to this message

From: Doug Eichenberg
Subject: Re: rotating parallel to surface normal
Date: 26 Jul 2003 13:43:09
Message: <3f22bdad$1@news.povray.org>
Thanks for the response Florian.  Not sure if that macro would work or
not... I may have found another solution.  My mistake (I think) was in
revolving around the x-axis... no need to do that.  Instead I do one
rotation on the z-axis, then another on the y-axis, then translate the
object.  Basically, this seems to mimic spherical polar coordinates.
Testing it now to see if it works.

--
Doug Eichenberg
www.getinfo.net/douge
dou### [at] nlsnet


Post a reply to this message

From: Doug Eichenberg
Subject: Re: rotating parallel to surface normal
Date: 26 Jul 2003 21:46:19
Message: <3f232eeb$1@news.povray.org>
Okay that doesn't seem to work either :P  Gonna set it aside awhile and work
on something else.

--
Douglas C. Eichenberg
dou### [at] nlsnet
http://www.getinfo.net/douge


Post a reply to this message

From: Chris Amshey
Subject: Re: rotating parallel to surface normal
Date: 27 Jul 2003 02:35:01
Message: <web.3f23726b90a9c3a61b99e900@news.povray.org>
Doug Eichenberg wrote:
>Let's say I have an object "A" at the origin, and a known surface normal
><x,y,z>.  I want to find the rotation vector <Rx,Ry,Rz> of the surface
>normal <x,y,z>, such that when I rotate "A":
>
>object{ A rotate<Rx,Ry,Rz> }
>
>it lies along the surface normal.
>
>I tried doing this as follows:
>
>object{ A rotate<atan2d(Norm.y,Norm.z), atan2d(Norm.x,Norm.z),
>atan2d(Norm.x,Norm.y)>
>
>but I seem to be getting strange results.
>
>Anyone have code they used for doing this?  Or know how in general?
>Thanks for the help.

Without checking your trigonometry, I can see you have fallen prey to one of
the most popular - and my first - error of trigonometric transformation.
Try 'object { A rotate &lt degrees(atan2(Norm.y,Norm.z), ... etc.) &gt }'
The problem is the inverse trig functions return radians, and rotate
expects degrees. Forward trig functions also -take- radians, so, pretty much
any time you want to use the trig functions you have to constantly use the
radians() and degrees() functions as well.

Good luck!

--Chris


Post a reply to this message

From: Doug Eichenberg
Subject: Re: rotating parallel to surface normal
Date: 27 Jul 2003 15:15:58
Message: <3f2424ee$1@news.povray.org>
Hmm, I was thinking that atan2d returned degrees.  Gonna have to go back and
check. Thanks for the reply!

--
Douglas C. Eichenberg
dou### [at] nlsnet
http://www.getinfo.net/douge


Post a reply to this message

From: Doug Eichenberg
Subject: Re: rotating parallel to surface normal
Date: 27 Jul 2003 16:42:31
Message: <3f243937$1@news.povray.org>
Okay I tried it both ways, and I am getting the same result.  I think I see
where my problem is though.  If I only rotate on one axis, a view down that
axis looks right.  As soon as I put another axis into the rotation, it gets
messed up.  What I need to do is create a new axis after the first rotation
that is perpendicular to the vector after the initial rotation, then rotate
around that (if any of that makes any sense, my technical speaking skills
suck).  Anyhow, off to try that approach now.

--
Douglas C. Eichenberg
dou### [at] nlsnet
http://www.getinfo.net/douge


Post a reply to this message

From: Warp
Subject: Re: rotating parallel to surface normal
Date: 27 Jul 2003 19:38:28
Message: <3f246273@news.povray.org>
Check the Rotate_Around_Trans() macro in transforms.inc.
  Section 7.19 of the help file.

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Doug Eichenberg
Subject: Re: rotating parallel to surface normal
Date: 27 Jul 2003 21:39:00
Message: <3f247eb4$1@news.povray.org>
Yeah I looked into that, but the object being rotated was already placed at
the origin, so I don't think that macro would make any difference.  However,
in desperation, I tried Reorient_Trans... using the axis the object was
defined along (y-axis) as the first argument, and the surface normal as the
second argument. Running a test now, and it seems to work.

--
Doug Eichenberg
www.getinfo.net/douge
dou### [at] nlsnet


Post a reply to this message

From: Steve Cavilia
Subject: Re: rotating parallel to surface normal
Date: 28 Jul 2003 16:50:12
Message: <3f258c84$1@news.povray.org>
I wrote this code to work with the geodesic macro. it takes a position 
vector and rotateds an object (here a torus) so it's y axis is along 
that vector. the position vector is on a sphere centered at the origin, 
so it is exactly the same as a surface normal. Uses trig to get z and y 
euler angles.

#macro do_corner(position)

#local a = position.x;
#local b = position.y;
#local c = position.z;

// union
// {
  torus
  {
   .08,.035
   pigment {color rgb <1,1,0>}
// }
// cylinder
// {
//  <0,-.2,0>,<0,.2,0>,.04
//  pigment {color rgb <1,0,0>}
// }
   #local thetaz = asin(b);
   #local thetay = asin(c);

   #if (a<0)
   #local thetaz = pi-thetaz;
   #end
   #if (a>0)
   #local thetay = -thetay;
   #end

   rotate 90*z
   rotate z*thetaz*(180/pi)
   rotate y*thetay*(180/pi)

   translate position
  }

#end


Doug Eichenberg wrote:
> Let's say I have an object "A" at the origin, and a known surface normal
> <x,y,z>.  I want to find the rotation vector <Rx,Ry,Rz> of the surface
> normal <x,y,z>, such that when I rotate "A":
> 
> object{ A rotate<Rx,Ry,Rz> }
> 
> it lies along the surface normal.
> 
> I tried doing this as follows:
> 
> object{ A rotate<atan2d(Norm.y,Norm.z), atan2d(Norm.x,Norm.z),
> atan2d(Norm.x,Norm.y)>
> 
> but I seem to be getting strange results.
> 
> Anyone have code they used for doing this?  Or know how in general?
> Thanks for the help.
> 
> --
> Doug Eichenberg
> www.getinfo.net/douge
> dou### [at] nlsnet
> 
>


Post a reply to this message

Goto Latest 10 Messages Next 3 Messages >>>

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