POV-Ray : Newsgroups : povray.general : Req: a #macro to reorient a vector : Re: Req: a #macro to reorient a vector Server Time
12 Aug 2024 17:08:46 EDT (-0400)
  Re: Req: a #macro to reorient a vector  
From: Jerry Anning
Date: 28 Jan 1999 03:06:34
Message: <36B01A89.2223A220@dhol.com>
Peter Popov wrote:
> 
> I am following myself here, as it seems I didn't state the problem
> clearly enough. What I need is a #macro that works like the "Reorient"
> #macro on #Macroscope, but is used with a vector. Why?
> 
> Suppose you have a point A rotating  around the origin in the xz
> plane.Move the poiont up at the same time and you get a helix. What I
> want to do is a helix whose axis is defined by a function (a #macro,
> actually), so that it can be coiled aroind a circle, sine wave, or
> whatever else. How?
> 
> Now let t be the variable of which the coordinates of A (x and z only,
> y=0) and the helix axis are functions A(t) and H(t) respectively. What
> I want to do is calculate A(t) and then reorient it along dH(t)/dt and
> then rtanslate it to H(t). I need the coordinates of the object, not
> the actual object transformed by a matrix, because I need them for
> texture uv mapping (that's the whole point).
> 
> With these things cleared out (I hope), can anyone help me? I will
> really appreciate it.

If I understand you correctly, I did something similar a while ago as part of a
collaboration with Jamis Buck.  The idea was to create a telephone cord by
wrapping a helix around (and along) a spline.  Instead of a spline and helix you
could use your "H(T)" and "A(T)" functions.  Quickly and untestedly translating
the guts of my work (based on VanSickle's 3.02 version Matrix Page), here is a
macro that should do what you want.  In essence, it is a specialized version of
the reorient macro in which the matrix transforms are done explicitly, "up" is
hardwired to the Y axis, it calls global A(T) and H(T) functions, and it adds
the eventual vector-pointing-to-the-position to the point along H to get the
(transformed) point along A if my quick late night UNTESTED translation is
accurate.  In any case, the basis is sound and you can probably fix any errors. 
Macro follows after my signature.

Jerry Anning
cle### [at] dholcom

// Begin POV code

#macro Vreorient(T)
  #local Ht = H(T);
  #local Vx2 = ((T = 0) ? 0 : vnormalize (H(Oldt) - Ht);
  #declare Oldt = T;
  #local Vx1 = <0, 1, 0>;
  #local Vy = vnormalize(vcross(Vx2, Vx1);
  #local Vz1 = vnormalize(vcross(Vy, Vx1);
  #local Vz2 = vnormalize(vcross(Vy, Vx2);
  #local At = A(T);
  #local A1 = vdot(At, Vx1);
  #local A2 = vdot(At, Vy);
  #local A3 = vdot(At, Vz1);
  #local Apos = <vdot(At, Vx1), vdot(At, Vy), vdot(At, Vz1)>;
  #local B1 = <Vx2.x, Vy.x, Vz2.x>;
  #local B2 = <Vx2.y, Vy.y, Vz2.y>;
  #local B3 = <Vx2.z, Vy.z, Vz2.z>;
  <vdot(Apos, B1), vdot(Apos, B2), vdot(Apos, B3)> + Ht
#end

// End POV code


Post a reply to this message

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