POV-Ray : Newsgroups : povray.general : Vector calculation/rotation problem : Re: Vector calculation/rotation problem Server Time
31 Jul 2024 00:33:42 EDT (-0400)
  Re: Vector calculation/rotation problem  
From: Tor Olav Kristensen
Date: 17 Feb 2008 19:53:12
Message: <47b8d6f8@news.povray.org>
Severi Salminen wrote:
> Thanks, but I'm actually interested in general solution without
> resorting to functions provided by PovRay. As it is probably OT here,
> I'll post the question to OT.

The code below is based on John's solution (but with some
simplifications). Most of the functions special to POV-Ray
has been replaced by common functions.

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#declare vN = <2, 1, 3>;
#declare SS = seed(6457);
#declare Cnt = 20;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare vY =
   vN/sqrt(vN.x*vN.x + vN.y*vN.y + vN.z*vN.z);
#declare vX =
   <vY.z, 0, -vY.x>/sqrt(vY.x*vY.x + vY.z*vY.z);
#declare vZ =
   <vX.y*vY.z - vX.z*vY.y, vX.z*vY.x - vX.x*vY.z, vX.x*vY.y - vX.y*vY.x>;

cylinder { 0*y, vX, 0.03 pigment { color rgb <2, 1, 1> } }
cylinder { 0*y, vY, 0.03 pigment { color rgb <1, 2, 1> } }
cylinder { 0*y, vZ, 0.03 pigment { color rgb <1, 1, 2> } }

#declare I = 0;
#while (I < Cnt)
   #declare sN = rand(SS);
   #declare sL = sqrt(1 - sN*sN);
   #declare Angle = -2*pi*rand(SS);
   #declare vResult = sN*vY + sL*(cos(Angle)*vX + sin(Angle)*vZ);
   cylinder { 0*y, vResult, 0.01 pigment { color rgb <1, 1, 1> } }
   #declare I = I + 1;
#end // while

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color rgb <0.0, 0.0, 0.5> }

light_source { <1, 1, 1>*100 color rgb <1, 1, 1> }

camera {
   location <3, 1, 2>
   look_at <0, 0, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


-- 
Tor Olav
http://subcube.com


Post a reply to this message

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