POV-Ray : Newsgroups : povray.programming : math and trig question Server Time
28 Jul 2024 18:11:58 EDT (-0400)
  math and trig question (Message 1 to 9 of 9)  
From: Mike Weber
Subject: math and trig question
Date: 28 Mar 2000 15:21:41
Message: <38e11455@news.povray.org>
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.

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)

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.

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.

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

--
Mike

wk: mik### [at] pyxiscom  www.pyxis.com
hm: mwe### [at] sciticom  www.geocities.com/mikepweber


Post a reply to this message

From: ryan constantine
Subject: Re: math and trig question
Date: 28 Mar 2000 18:17:48
Message: <38E13E2A.A5EF47B0@yahoo.com>
sorry, no math help here, but why are you using disks?  wouldn't spheres work?
rotation wouldn't matter then would it?

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.
>
> 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)
>
> 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.
>
> 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.
>
> I certainly would appreciate any help.  I can provide pictures if needed.
>
> --
> Mike
>
> wk: mik### [at] pyxiscom  www.pyxis.com
> hm: mwe### [at] sciticom  www.geocities.com/mikepweber


Post a reply to this message

From: Mike Weber
Subject: Re: math and trig question
Date: 28 Mar 2000 19:34:53
Message: <38e14fad$1@news.povray.org>
I'm really using triangles, but to get the point across I use disc.
Triangles will be used to create the tube where one triangle's vertex will
be at a point on the circumference of the disc, and the two other vertices
of the triangle will be at two points on the circumference of the next disc
locate at the next point along the spline.

--
Mike

wk: mik### [at] pyxiscom  www.pyxis.com
hm: mwe### [at] sciticom  www.geocities.com/mikepweber


"ryan constantine" <rco### [at] yahoocom> wrote in message
news:38E13E2A.A5EF47B0@yahoo.com...
> sorry, no math help here, but why are you using disks?  wouldn't spheres
work?
> rotation wouldn't matter then would it?
>
> 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.
> >
> > 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)
> >
> > 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.
> >
> > 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.
> >
> > I certainly would appreciate any help.  I can provide pictures if
needed.
> >
> > --
> > Mike
> >
> > wk: mik### [at] pyxiscom  www.pyxis.com
> > hm: mwe### [at] sciticom  www.geocities.com/mikepweber
>


Post a reply to this message

From: Fabian BRAU
Subject: Re: math and trig question
Date: 29 Mar 2000 02:30:16
Message: <38E1B101.2D0E5474@umh.ac.be>
Your plugin is interesting! Send me more information, I will have
a look to this :).

Fabian.


> 
> 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.
> 
> 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)
> 
> 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.
> 
> 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.
> 
> I certainly would appreciate any help.  I can provide pictures if needed.
> 
> --
> Mike
> 
> wk: mik### [at] pyxiscom  www.pyxis.com
> hm: mwe### [at] sciticom  www.geocities.com/mikepweber


Post a reply to this message

From: James Barton
Subject: Re: math and trig question
Date: 1 Apr 2000 19:52:55
Message: <38e699e7$1@news.povray.org>
Love to help, thinking about it now...  I am half figuring it out, seeing
pictures would be good, emailing them directly to me fine.  Be
warned I'm not a programmer by nature, but a mathematics person, 
so don't be surprised if I have no idea what a bspline is.

I think you don't want rotation in the z direction, as if the disk is created in
X-Y, then rotating it about Z, just rotates the circle, which is a symmetrical
object.  You want some y rotation instead.  If this isn't right I'll need some
more info.

I'm, thinking about it at the moment, I don't think the above would cause
that kind of a problem.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: math and trig question
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

From: Mike Weber
Subject: Re: math and trig question
Date: 4 Apr 2000 00:38:51
Message: <38e971db@news.povray.org>
Tor,

Thanks for your input.
You POV code is similar to what I am doing. You are rotating only on the X
and Y axis and not the Z where I rotate only on the X and Z axis and not the
Y.  I'm  not familiar with the POV normalize instruction, but maybe I could
learn something from that.

Mike

Tor Olav Kristensen <tto### [at] onlineno> wrote in message
news: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
>
> Wouldn't you have to accumulate up the rotations that is needed when
> wandering from point to point in your spline?
>
Not sure what you mean by that??

Mike


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: math and trig question
Date: 4 Apr 2000 12:04:52
Message: <38EA1167.DC358C7B@online.no>
Mike Weber wrote:

> Tor,
>
> Thanks for your input.
> You POV code is similar to what I am doing. You are rotating only on the X
> and Y axis and not the Z where I rotate only on the X and Z axis and not the
> Y.  I'm  not familiar with the POV normalize instruction, but maybe I could
> learn something from that.

vnormalize multiplies the vector with a scalar
so that the length of the vector becomes equal
to 1.

This is done by choosing a scalar that is equal
to the reciprocal of the vectors current length.

I.e. if it is a 3D-vector:

1/sqrt(pow(Vector.x, 2) +
       pow(Vector.y, 2) +
       pow(Vector.z, 2))

Note that if Vector is a null-vector (e.g. <0, 0>
or <0, 0, 0>) then (in POV-Ray) vnormalize(Vector)
just leaves it as a null-vector.

While this expression would generate a warning
message if Vector is a null-vector (division
by zero):

1/(vlength(Vector))*Vector

If 3D-vectors were used, then my expression;

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

could be written like this:

#if(Vector.y > 0)
  #local Sign = 1;
#else
  #local Sign = -1;
#end // if

<-Sign*acos(Vector.x/sqrt(pow(Vector.x, 2) +
                          pow(Vector.y, 2))),
acos(Vector.z/sqrt(pow(Vector.x, 2) +
                   pow(Vector.y, 2) +
                   pow(Vector.z, 2))),
0>

The last part could also be written like this

<-Sign*acos(Vector.x/vlength((x+y)*Vector)),
acos(Vector.z/vlength(Vector)),
0>

But with these two expressions one would have to
check if the x and y components were both zero.

> Tor Olav Kristensen <tto### [at] onlineno> wrote in message
> news:38E8C44E.81C7E687@online.no...
> ...
> > Wouldn't you have to accumulate up the rotations that is needed when
> > wandering from point to point in your spline?
> >
> Not sure what you mean by that??
>
> Mike

When using rotate in POV-Ray, the rotations is
always done around origo.

If you calculated this rotation relative to the
previous point (as is my understanding of your
description) and then applied the rotation relative
to origo, believe it would end up with a wrong
rotation relative to the previous point.

But if you take a copy of the object as it is
when it's rotated to the "last point" and then
applies the new rotations to make it point to
the "next point" then (I guess) it will become
right.

And my idea was that instead of making a copy of
the object as it was after it had last been copied,
you could just add together all the rotations that
had been done until the "last point" and then add
the new rotations to these rotations before
applying them to a copy of the object as it was
when created in your XZ-plane.

But again I don't know if my assumptions about
what you are really doing, is right. :)

...And maybe all my "believes" and theories
don't hold...

Tor Olav

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


Post a reply to this message

From: Mike Weber
Subject: Re: math and trig question
Date: 4 Apr 2000 12:19:54
Message: <38ea162a$1@news.povray.org>
"Tor Olav Kristensen" <tto### [at] onlineno> wrote in message
news:38EA1167.DC358C7B@online.no...
>
>
> > Tor Olav Kristensen <tto### [at] onlineno> wrote in message
> > news:38E8C44E.81C7E687@online.no...
> > ...
> > > Wouldn't you have to accumulate up the rotations that is needed when
> > > wandering from point to point in your spline?
> > >
> > Not sure what you mean by that??
> >
> > Mike
>
> When using rotate in POV-Ray, the rotations is
> always done around origo.
>
> If you calculated this rotation relative to the
> previous point (as is my understanding of your
> description) and then applied the rotation relative
> to origo, believe it would end up with a wrong
> rotation relative to the previous point.
>
> But if you take a copy of the object as it is
> when it's rotated to the "last point" and then
> applies the new rotations to make it point to
> the "next point" then (I guess) it will become
> right.
>
> And my idea was that instead of making a copy of
> the object as it was after it had last been copied,
> you could just add together all the rotations that
> had been done until the "last point" and then add
> the new rotations to these rotations before
> applying them to a copy of the object as it was
> when created in your XZ-plane.
>
> But again I don't know if my assumptions about
> what you are really doing, is right. :)
>
> ...And maybe all my "believes" and theories
> don't hold...
>
No, you are correct.  Your ideas are very similar.  However, my object is
rotated at the origin (origo), then translated to the appropriate position.
The rotation is based on the angle between the the previous point and the
current point.

Mike


Post a reply to this message

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