POV-Ray : Newsgroups : povray.programming : math and trig question : Re: math and trig question Server Time
28 Jul 2024 16:31:08 EDT (-0400)
  Re: math and trig question  
From: Tor Olav Kristensen
Date: 3 Apr 2000 12:23:33
Message: <38E8C44E.81C7E687@online.no>
Hello Mike

If I have understood your problem right, then I have had
similar problems myself.

I have tried to modify two of my POV-macros so that they
suit your problem.

See the code below for my solution.

If this is not what you need, then I will need more
information to solve your problem.

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Mike Weber wrote:

> I have a question for a problem relating to 3D rotations.
> I'm working on a bspline plug-in dll for Moray.  Its very close to being
> ready for release once I get this small problem fixed.

Because I don't master the C-language, my code is POV-ray syntax,
which is not very suited for a dll.

> So here it is:
>
> I'm creating a tube like object for the spline by using a series of 'discs'
> along the path of the spline and orientating its surface or normal to point
> to the next joint or point along the spline.  Using the following math and
> trig functions that Sean Worle provided:
>
>   rz = atan2(dx, dy);
>   rx = atan2(sqrt(dx*dx + dy*dy), dz);
>
> atan2 = arctangent of y/x (in radians)

I think you need to keep track of which quadrant you are in before you
apply the rotations. As far as I can see it, you loose that information
when you apply the formulas above.

> where dx, dy, dz are the differences between the current point and the next
> point in the spline.
> rz and rx are the amount to rotate the disc in the z and x axis.  The disc
> is created in the X-Y plane.

Are you sure that it is wise to create your objects in the X-Y plane?

The torus object in POV-ray is always created in the X-Z plane.
And this may create problems for you if you want to "string up" toruses
instead of discs.

My original macros were made for tilting objects "created" in the X-Z
plane. (If you look in my recent posting to povray.text.scene-files
"Bumpy CSG-sphere" you will find these macros under the names:
vtilt & VectorAngles)

> The problem is when I create a b-spline object along the Z axis, which looks
> like a straigt cylinder (or tube) - it is fine.  But if one of the points
> moves in the x direction, then the disc is rotated by 90 degrees along the Z
> axis which is not good.  But it does this because when using atan2 and the
> dx goes negative it returns -90.

Wouldn't you have to accumulate up the rotations that is needed when
wandering from point to point in your spline?

> I certainly would appreciate any help.  I can provide pictures if needed.

#macro VA(Vector)
// Vector Angles

  <acos(vnormalize((x+y)*Vector).x)*(Vector.y > 0 ? -1 : 1),
   acos(vnormalize(Vector).z),
   0>

#end // macro VA


#macro VT(Thing, TVector)
// Vector Tilt

  #local RotateAngles = VA(TVector);

  object {
    Thing
    rotate  degrees(RotateAngles.x)*z
    rotate  degrees(RotateAngles.y)*y
    rotate -degrees(RotateAngles.x)*z
  }

#end // macro VT


#declare dx = 0.2;
#declare dy = -0.3;
#declare dz = 0.5;

#declare TiltDirection = <dx, dy, dz>;

#declare OneBox = box { <6, 3, -1>/6, <-6, -3, 1>/6 }

#declare TiltedBox = VT(OneBox, TiltDirection)

object {
  TiltedBox
  pigment { color Red }
}


Post a reply to this message

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