POV-Ray : Newsgroups : povray.newusers : translation/rotation : Re: translation/rotation Server Time
30 Jul 2024 02:23:44 EDT (-0400)
  Re: translation/rotation  
From: Chris B
Date: 14 Nov 2004 15:49:02
Message: <4197c4be$1@news.povray.org>
"Stephen" <pen### [at] shawca> wrote in message
news:41976317$1@news.povray.org...
>
> I would like to animate a piston type of instrument and am not sure of the
> simplest math to do the translation so I'm asking for help.
>
> If you think of a circle with a connecting rod attached at a point on the
> circumference e.g. 270 degrees or at "west" on a compass circle, and fixed
> along a vertical slider located below the circle (south of south) such
that
> point will move only up and down, then when the circle rotates clockwise
for
> the first 90 degrees (from 270 to 360) the connecting rod will move up at
> the lower end and move up and clockwise at the upper end.
>
> How can the angular movement of the connecting rod be modeled simply?
>
> One answer is to define the end points and calculate for each degree of
the
> circle rotation the new points along the circle and the vertical slider
path
> and redraw the connecting rod at the new points.
>
> Can this be accomplished through rotation/translation of an existing
> connecting rod?
>

Hi Stephen,

You can calculate the rotation and translation using the sin and cos
functions. The math.inc file includes these functions in degrees (whereas
the built in functions use radians).

I don't know how your trigonometry is, but if you think of a line from the
centre of your circular path to the point on the circumference, then the
horizontal distance of the point from the y axis is given by
circleRadius*sin(rotationAngle), where the rotationAngle is the angle
between straight up (+Y) and your radial line (sine of an angle in a right
angle triangle = length of opposite edge/ length of hypotenuse).

The same horizontal distance is the distance the top of your connecting rod
is from the y axis, so it's also equal to rodLength*sin(rodRotation), where
the rodRotation is the angle between straight up and your connecting rod.

So ... rodLength*sin(rodRotation)=circleRadius*sin(rotationAngle), and
therefore ... rodRotation =
arcsin(sin(rotationAngle)*circleRadius/rodLength.

You can use cosines to work out the distance from the centre of the circle
to the bottom of the connecting rod because the y component of the rodLength
is rodLength*cos(rodRotation) and the y component of the point on the
circumference is given by circleRadius*cos(rotationAngle).

So ... rodHeight = rodLength*cos(rodRotation) -
circleRadius*cos(rotationAngle).

Here's a simple example:

camera {location <0,1,-5> look_at   <0,0,0>}
light_source { <0, 10, -8>  color rgb <2, 2, 2> }

#include "math.inc"

#declare circleRadius = 0.7;
#declare rodLength = 1.8;

cylinder {<0,0,0><0,0,0.1>,circleRadius pigment {color rgb <1,1,1>}}

#declare connectingRod = cylinder {<0,0,0><0,rodLength,0>,0.01}


#declare rotationAngle = 5;
#while (rotationAngle < 360)
  #declare rodRotation = asind(sind(rotationAngle)*circleRadius/rodLength);
  #declare rodHeight   =
rodLength*cosd(rodRotation)-circleRadius*cosd(rotationAngle);

  object {connectingRod
    rotate rodRotation*z
    translate -rodHeight*y
    pigment {color rgb
<rotationAngle/360,1-(rotationAngle/360),rotationAngle/360>}
  }

  #declare rotationAngle = rotationAngle + 20;
#end


Post a reply to this message

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