POV-Ray : Newsgroups : povray.newusers : Help - very difficult when it should be easy : Re: Help - very difficult when it should be easy Server Time
20 Apr 2024 10:50:24 EDT (-0400)
  Re: Help - very difficult when it should be easy  
From: Trevor G Quayle
Date: 16 Nov 2016 13:35:01
Message: <web.582ca614ba97f5c181c811d20@news.povray.org>
To do this I usually just use some basic trig and reorient one axis at a time.

The box is made along the x-axis, so first rotation is to apply a twist about
that x-axis if you want it, otherwise it remains upright through rotations.

Next rotation is to rotate away from the x-z plane by rotating around the
z-axis.
Final rotation is to rotate to final position around the vertical y-axis.



Just the #for Loop portion:

#for (Test, 0, min(dimension_size (StartArray, 1), dimension_size
(EndArray,1))-1 )

  #debug concat( " Test = ", str(Test, 3, 1), "\n")

  #declare Point1 = StartArray [Test];
  #declare Point2 = EndArray [Test];

  #declare Vec = Point2 - Point1;       //Direction vector to orient to
  #declare StrutLength = vlength(Vec);  //LENGTH OF BOX

  //Twist rotates the box around the long axis first
  #declare Twist = 45;

  //RotZ and RotY reoorient the box to align to the vector
  #declare RotZ = degrees(atan2(Vec.y,vlength(<Vec.x,0,Vec.z>)));  //ROTATION
ABOUT Z-AXIS
  #declare RotY = degrees(atan2(Vec.z,Vec.x));                     //ROTATION
ABOUT Y-AXIS

  #declare IBeam = box {<0, -Strut/2, -Strut/2>, <StrutLength, Strut/2,
Strut/2>}

  sphere {Point1 0.5 pigment {Orange*0.5} }
  sphere {Point2 0.5 pigment {Violet*0.5} }

  #declare NewIBeam =
    object {
      IBeam
      rotate Twist*x
      rotate RotZ*z
      rotate RotY*y
      translate Point1
    }

  object {NewIBeam pigment {Blue} }

#end // end for Test


Post a reply to this message

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