POV-Ray : Newsgroups : povray.general : Rotating an object : Re: Rotating an object Server Time
31 Jul 2024 06:17:11 EDT (-0400)
  Re: Rotating an object  
From: John VanSickle
Date: 5 Oct 2007 19:12:52
Message: <4706c4f4@news.povray.org>
Ger wrote:
> I have a #macro that creates a wall :
> 
> 
> #macro OutSideWall(Position1,End1,Position2,End2)
> // ---------- for testing purpose only
> cylinder{Position1,Position1+<0,400,0>,30 pigment { red 1 }}
> cylinder{Position2,Position2+<0,450,0>,25 pigment { blue 1 }}
> // ----------
>   #local XLength = Position2.x - Position1.x;
>   #local ZLength = Position2.z - Position1.z;
>   #local WallLength = VDist(Position1,Position2);
>   #local Angle = degrees(asin(ZLength/WallLength));
> 
>   #local LogCounter = 0;
>   #declare ThisWall =
>     union {
>     #while ((LogCounter * HtHLogDistance) < OutsideWallHeight)
>       object { Log(WallLength,End1,End2) translate y * HtHLogDistance *
> (LogCounter+0.5) }
>       #local LogCounter = LogCounter + 1;
>     #end
>     }
> 
>   object { ThisWall rotate y * Angle translate Position1 }
> #end
> 
> so I can do this
> 
> OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
> OutSideWall(< 200,0,800>, true,< 400,0, 800>, true)
> 
> for a whole building
> 
> The walls are created just fine and placed at the correct place (Position1)
> but the rotation (rotate Angle) is wrong.

You really don't need to do this arcsin and rotation stuff.

The better way to do it is:

#local vZ=vnormalize(Position2-Position1);
#local vX=vnormalize(vcross(y,vZ));

and replace the rotate and translate with this:

matrix < vX.x,        vX.y,        vX.z,
          0,           1,           0,
          vZ.x,        vZ.y,        vZ.z,
          Position1.x, Position1.y, Position1.z>

It may help you with this to also read

   http://www.geocities.com/evilsnack/matrix.htm ,

which is tutorial I wrote about the matrix transform.

Regards,
John


Post a reply to this message

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