POV-Ray : Newsgroups : povray.general : Couple of macros Server Time
9 Aug 2024 19:42:01 EDT (-0400)
  Couple of macros (Message 1 to 5 of 5)  
From: Pabs
Subject: Couple of macros
Date: 15 Jun 2000 01:30:15
Message: <39486A14.B104D32B@hotmail.com>
The first rotates an object such that if it oriented in the <from>
direction vector then after the rotation it will be oriented in the <to>
direction vector
The first relies in the second.

The second rotates an object around an axis <axis> by the angle <ang>
and was obtained from the src for the function vaxis_rotate (why wasn't
this type of rotation included in POV code) - hope the team don't mind :
)
This calculates a matrix for rotation.

eg cylinder{0,y,.1 lookat(y,<-0.5, 0.23, 0.342>) }
eg cylinder{0,y,.1 translate <0,0.5,.1> axis_rotate(x,45)}

#macro point(from, to)
 #local axis = vcross(from,to);
 #local axis = vnormalize(axis);
 #local ang = acos(vdot(to,from)/vlength(to)/vlength(from));
 axis_rotate(axis, ang)
#end

#macro axis_rotate(axis, ang)
 #local cosx = cos(ang);
 #local sinx = sin(ang);
 matrix<
  axis.x * axis.x + cosx * (1.0 - axis.x * axis.x),
  axis.x * axis.y * (1.0 - cosx) + axis.z * sinx,
  axis.x * axis.z * (1.0 - cosx) - axis.y * sinx,

  axis.x * axis.y * (1.0 - cosx) - axis.z * sinx,
  axis.y * axis.y + cosx * (1.0 - axis.y * axis.y),
  axis.y * axis.z * (1.0 - cosx) + axis.x * sinx,

  axis.x * axis.z * (1.0 - cosx) + axis.y * sinx,
  axis.y * axis.z * (1.0 - cosx) - axis.x * sinx,
  axis.z * axis.z + cosx * (1.0 - axis.z * axis.z),
  0,0,0
 >
#end

Hope these are of some use

Pabs


Post a reply to this message

From: Warp
Subject: Re: Couple of macros
Date: 15 Jun 2000 05:40:01
Message: <3948a470@news.povray.org>
Pabs <pab### [at] hotmailcom> wrote:
: The first rotates an object such that if it oriented in the <from>
: direction vector then after the rotation it will be oriented in the <to>
: direction vector

  Sounds a lot like VanSickle's Reorient macro.

: The second rotates an object around an axis <axis> by the angle <ang>

  Sounds a lot like his AxisRotate macro.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: David Fontaine
Subject: Re: Couple of macros
Date: 15 Jun 2000 13:10:06
Message: <39490CC0.7163A302@faricy.net>
Warp wrote:

> Pabs <pab### [at] hotmailcom> wrote:
> : The first rotates an object such that if it oriented in the <from>
> : direction vector then after the rotation it will be oriented in the <to>
> : direction vector
>
>   Sounds a lot like VanSickle's Reorient macro.
>
> : The second rotates an object around an axis <axis> by the angle <ang>
>
>   Sounds a lot like his AxisRotate macro.

I needlessly wrote redundant macros for these long before Pabs! :-) It is good
experience though.

--
David Fontaine     <dav### [at] faricynet>     ICQ 55354965
Please visit my website: http://www.faricy.net/~davidf/


Post a reply to this message

From: Warp
Subject: Re: Couple of macros
Date: 15 Jun 2000 13:12:43
Message: <39490e8b@news.povray.org>
David Fontaine <dav### [at] faricynet> wrote:
: I needlessly wrote redundant macros for these long before Pabs! :-) It is good
: experience though.

  That's certainly true. When you write the macro yourself you have to
understand how the math works and you will probably learn something. It's
never wasted time (at least not for yourself).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Pabs
Subject: Re: Couple of macros
Date: 18 Jun 2000 21:41:17
Message: <394D7A6E.130AD8A0@nospam.hotmail.com>
Warp wrote:

>   Sounds a lot like VanSickle's Reorient macro.
>
>   Sounds a lot like his AxisRotate macro.

Oops


Post a reply to this message

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