POV-Ray : Newsgroups : povray.general : Vexing Vector Problem : Re: Vexing Vector Problem Server Time
7 Aug 2024 15:18:15 EDT (-0400)
  Re: Vexing Vector Problem  
From: Tor Olav Kristensen
Date: 30 Aug 2001 19:26:54
Message: <3B8ECB7D.571A4BE2@hotmail.com>
Dave Dunn wrote:
> 
> There is probably somehting simple that I am missing (besides a brain)
> but I am at a loss. I am trying to be able to define a line between two
> vectors, as with a cylinder or cone definition (lets say <1,2,3> to
> <3,4,5>). Now, I want to use that line as an axis, as if it were, say Y,
> (<0,-2,0>,<0,2,0> for example), and offset a parallel line from this set
> of vectors. (As in <2,-2,0>,<2,2,0>) and create a while loop that
> generates a ring of lines around the original axis. The application I
> have in mind will not allow creating the figure at the Origin and
> rotating into place. Any help would be appreciated.

I hope that the code below provides a 
solution to your problem.

You may also have a look my answer to Ben
Chambers' "Rotations..." thread 7. Aug in
this group:

news://news.povray.org/3b6f392f%241%40news.povray.org


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Copyright 2001 by Tor Olav Kristensen
// mailto:tor### [at] hotmailcom
// http://hjem.sol.no/t-o-k
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#version 3.1;
#include "colors.inc"

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

#macro ReorientMatrix(vAxis1, vAxis2)

  #local v1 = vnormalize(vAxis1);
  #local v2 = vnormalize(vAxis2);
  #local vU = vcross(v1, v2);
  #local Dot = vdot(v1, v2);
  #local v0 = vnormalize(vU);
  #local vW = (1 - Dot)*v0;
  #local vA = v0.x*vW;
  #local vB = v0.y*vW;
  #local vC = v0.z*vW;

  matrix <
    vA.x + Dot,  vA.y + vU.z, vA.z - vU.y,
    vB.x - vU.z, vB.y + Dot,  vB.z + vU.x,
    vC.x + vU.y, vC.y - vU.x, vC.z + Dot,
    0,                0,                0
  >
  
#end // macro ReorientMatrix

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

// Remote "axis" start and end points
#declare pR1 = <1, 2, 3>;
#declare pR2 = <3, 4, 5>;

#declare vRemoteAxisDirection = pR2 - pR1;
#declare vRemoteAxisOrigin = (pR1 + pR2)/2;

// Show remote axis
cylinder { pR1, pR2, 0.2 pigment { color Cyan } }

// Central "y-axis" start and end points
#declare pC1 = -2*y;
#declare pC2 =  2*y;

#declare ObjectToBeRotated =
box {
  -<4, 6, 1>/10, <4, 6, 1>/10
  translate 2*x
}

#declare ObjectToBeTilted =
union {
  #declare Angle = 0;
  #while (Angle < 360)
    object { ObjectToBeRotated rotate Angle*y }
    #declare Angle = Angle + 10;
  #end // while
}

#declare ObjectToBeTranslated =
object {
  ObjectToBeTilted
  ReorientMatrix(y, vRemoteAxisDirection)
}

object {
  ObjectToBeTranslated
  translate vRemoteAxisOrigin
  pigment { color Yellow }
}

/*
// Or doing it all in one step
union {
  #declare Angle = 0;
  #while (Angle < 360)
    box {
      -<4, 6, 1>/10, <4, 6, 1>/10
      translate 2*x
      rotate Angle*y
    }
    #declare Angle = Angle + 10;
  #end // while
  ReorientMatrix(y, vRemoteAxisDirection)
  translate vRemoteAxisOrigin
  pigment { color Yellow }
}
*/

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

background { color Blue/2 }

camera {
  location <-2, -1, 3>*2
  look_at vRemoteAxisOrigin
}

light_source {
  <1, 0, 3>*100
  color White
  shadowless
}

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


Post a reply to this message

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