POV-Ray : Newsgroups : povray.general : Rotating an object Server Time
31 Jul 2024 08:30:00 EDT (-0400)
  Rotating an object (Message 1 to 7 of 7)  
From: Ger
Subject: Rotating an object
Date: 4 Oct 2007 16:45:10
Message: <470550d6@news.povray.org>
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.

I know this is stupidly simple, but I guess I'm dumber :)

-- 
Ger


Post a reply to this message

From: Tim Attwood
Subject: Re: Rotating an object
Date: 5 Oct 2007 01:02:51
Message: <4705c57b@news.povray.org>
> The walls are created just fine and placed at the correct place 
> (Position1)
> but the rotation (rotate Angle) is wrong.

rotate moves an object around the origin,

from your code
OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
I deduce that you have a wall starting at <200,0,1200>
(Position1) and going to <200,0,800> (Position2)

So if you wish to rotate the wall around Position1 you'd
first translate the wall to the origin, then rotate it, then
put it back at Position1.

object {
     ThisWall
     translate -Position1
     rotate y * Angle
     translate Position1
}


Post a reply to this message

From: Ger
Subject: Re: Rotating an object
Date: 5 Oct 2007 01:27:55
Message: <4705cb5a@news.povray.org>
Tim Attwood wrote:

>> The walls are created just fine and placed at the correct place
>> (Position1)
>> but the rotation (rotate Angle) is wrong.
> 
> rotate moves an object around the origin,
> 
> from your code
> OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
> I deduce that you have a wall starting at <200,0,1200>
> (Position1) and going to <200,0,800> (Position2)
> 
> So if you wish to rotate the wall around Position1 you'd
> first translate the wall to the origin, then rotate it, then
> put it back at Position1.
> 
> object {
>      ThisWall
>      translate -Position1
>      rotate y * Angle
>      translate Position1
> }

The wall is created at the origin, then rotated and then translated.
Everything works okay except for the rotation angle.
-- 
Ger


Post a reply to this message

From: Bill Pragnell
Subject: Re: Rotating an object
Date: 5 Oct 2007 05:55:00
Message: <web.470609ce81b15673731f01d10@news.povray.org>
Ger <No.### [at] ThankYou> wrote:
> The wall is created at the origin, then rotated and then translated.
> Everything works okay except for the rotation angle.

I see two problems. Firstly, I think you should be using arc-tan, not
arc-sin (tan(a) = opposite/adjacent). Secondly, as you look along an axis,
negative rotation is clockwise, so I would use rotate -Angle*y.

If your wall is aligned on the z-axis, you will get a division by zero
error, which will need to be trapped. You will also need to modify this
technique if position2 is in the 2nd, 3rd or 4th quadrants relative to


Hope that helps
B


Post a reply to this message

From: John VanSickle
Subject: Re: Rotating an object
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

From: Ger
Subject: Re: Rotating an object
Date: 5 Oct 2007 22:35:04
Message: <4706f458@news.povray.org>
John VanSickle wrote:

> 
> 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

I had it figured out with a lot of #if's in it, but I tried your solution
anyway because it looks so much more elegant. 
But now a wall is rotated y * 90 from where it is supposed to be.

-- 
Ger


Post a reply to this message

From: John VanSickle
Subject: Re: Rotating an object
Date: 6 Oct 2007 12:09:05
Message: <4707b321$1@news.povray.org>
Ger wrote:
> John VanSickle wrote:
> 
> 
>>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
> 
> 
> I had it figured out with a lot of #if's in it, but I tried your solution
> anyway because it looks so much more elegant. 
> But now a wall is rotated y * 90 from where it is supposed to be.

If the wall is built along the x axis prior to is positioning, then use 
this code to calculate vX and vZ:

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

The matrix remains the same.

Regards,
John


Post a reply to this message

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