POV-Ray : Newsgroups : povray.advanced-users : Speaking of Mathematics Server Time
27 Dec 2024 06:57:45 EST (-0500)
  Speaking of Mathematics (Message 1 to 7 of 7)  
From: Mike Raiford
Subject: Speaking of Mathematics
Date: 6 Dec 2004 14:01:32
Message: <41b4ac8c$1@news.povray.org>
Someone posted a scene involving a spline. It interested me, I played 
with it.... I liked it... it was neat, I hadn't messed around with 
splines much in the past, but natural spline seems to be nice.

Anyway, the critter (ever endearing spline critter, that is) inspired me 
to make some sort of arbitrary_object_sweep type object. I played around 
with it some more, banged my head against a few dozen brick walls, and 
finally threw up my hands.

All I wanted to do was take 2 points, get a vector, normalize it, and 
calculate the X,Y and Z rotations to reorient it..

this is what I had so far:

(d is the normalised vector

#local rx = degrees(acos(vdot(d, <0, d.y, d.z>)));
#local ry = degrees(acos(vdot(d, <d.x, 0, d.z>)));
#local rz = degrees(acos(vdot(d, <d.x, d.y, 0>)));

But... it still doesn't seem quite right.

-- 
~Mike


Post a reply to this message

From: Slime
Subject: Re: Speaking of Mathematics
Date: 6 Dec 2004 17:20:55
Message: <41b4db47@news.povray.org>
> #local rx = degrees(acos(vdot(d, <0, d.y, d.z>)));
> #local ry = degrees(acos(vdot(d, <d.x, 0, d.z>)));
> #local rz = degrees(acos(vdot(d, <d.x, d.y, 0>)));

I'm not sure exactly what you were trying to do here (I'm sure there's logic
to it but I'm just not following it), but chances are after you do the
rotate rx*x (if that's what you're doing), the ry and rz rotations are no
longer useful for the object's new position.

Another thing to consider is that only two rotations should be needed to
make an object point in a certain direction. (This is because a direction
can be represented as a point on the surface of the unit sphere, and the
surface of a sphere is 2 dimensional.) For instance, if an object is
pointing in the positive x direction, a rotation between -90 and +90 degrees
around the z axis, followed by a rotation between -180 and +180 degrees
around the y axis is enough to orient the object in any direction. (A
rotation around the x axis could be done before either of these to have
control over how the object is rotated around the axis it's going to point
in.)

In any case, there's no point (besides educational reasons) to go through
all this work, since you can just use the Reorient_Trans macro in
transforms.inc to do what you want. (The macro doesn't use rotations, it
instead creates a matrix transformation; this is a more straightforward way
of approaching the problem if you understand the math.)

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Captain Chemistry
Subject: Re: Speaking of Mathematics
Date: 7 Dec 2004 02:15:00
Message: <web.41b55745864be4ea301d03a70@news.povray.org>
"Slime" <fak### [at] emailaddress> wrote:
> > #local rx = degrees(acos(vdot(d, <0, d.y, d.z>)));
> > #local ry = degrees(acos(vdot(d, <d.x, 0, d.z>)));
> > #local rz = degrees(acos(vdot(d, <d.x, d.y, 0>)));
>
> I'm not sure exactly what you were trying to do here (I'm sure there's logic
> to it but I'm just not following it), but chances are after you do the
> rotate rx*x (if that's what you're doing), the ry and rz rotations are no
> longer useful for the object's new position.
>
> Another thing to consider is that only two rotations should be needed to
> make an object point in a certain direction. (This is because a direction
> can be represented as a point on the surface of the unit sphere, and the
> surface of a sphere is 2 dimensional.) For instance, if an object is
> pointing in the positive x direction, a rotation between -90 and +90 degrees
> around the z axis, followed by a rotation between -180 and +180 degrees
> around the y axis is enough to orient the object in any direction. (A
> rotation around the x axis could be done before either of these to have
> control over how the object is rotated around the axis it's going to point
> in.)
>
> In any case, there's no point (besides educational reasons) to go through
> all this work, since you can just use the Reorient_Trans macro in
> transforms.inc to do what you want. (The macro doesn't use rotations, it
> instead creates a matrix transformation; this is a more straightforward way
> of approaching the problem if you understand the math.)
>
>  - Slime
>  [ http://www.slimeland.com/ ]

I'm not adding anything new here, just saying that the Reorient_Trans marco
is good and it works.


Post a reply to this message

From: Mike Raiford
Subject: Re: Speaking of Mathematics
Date: 7 Dec 2004 07:49:03
Message: <41b5a6bf@news.povray.org>
Slime wrote:

>>#local rx = degrees(acos(vdot(d, <0, d.y, d.z>)));
>>#local ry = degrees(acos(vdot(d, <d.x, 0, d.z>)));
>>#local rz = degrees(acos(vdot(d, <d.x, d.y, 0>)));
> 
> 
> I'm not sure exactly what you were trying to do here (I'm sure there's logic
> to it but I'm just not following it), but chances are after you do the
> rotate rx*x (if that's what you're doing), the ry and rz rotations are no
> longer useful for the object's new position.
> 
> Another thing to consider is that only two rotations should be needed to
> make an object point in a certain direction. (This is because a direction
> can be represented as a point on the surface of the unit sphere, and the
> surface of a sphere is 2 dimensional.) For instance, if an object is
> pointing in the positive x direction, a rotation between -90 and +90 degrees
> around the z axis, followed by a rotation between -180 and +180 degrees
> around the y axis is enough to orient the object in any direction. (A
> rotation around the x axis could be done before either of these to have
> control over how the object is rotated around the axis it's going to point
> in.)
> 
> In any case, there's no point (besides educational reasons) to go through
> all this work, since you can just use the Reorient_Trans macro in
> transforms.inc to do what you want. (The macro doesn't use rotations, it
> instead creates a matrix transformation; this is a more straightforward way
> of approaching the problem if you understand the math.)
> 
>  - Slime
>  [ http://www.slimeland.com/ ]
> 
> 
The macro did work for me, except one small problem: there's a "twist" 
at one part in the spline that doesn't seem to make sense. Other than 
that, it worked as expected. I might have been overthinking the problem 
a bit, and .. yeah, it was a bit of an accedemic exercise for me, but, 
It started to bug me that there seemed to be no solution. (The rotations 
being null and void after a rotation occurred to me, but for some reason 
I felt that the effect could be negated by some mathematical "magic"

What I had done, or think I had done was get the angles from the X, Y 
and Z axes. The two other coordinates were left so the angle would be 
calculated from the same pane (axis, oriented in the direction of the 
remaining coordinates, that should get the angle from the plane, right?)

I've done similar stuff at work, but due to the nature of what I was 
doing it was always in 2-space, and thus doesn't suffer the exponential 
increase in problems that 3-space tends to.  (There's really only 1 axis 
of rotation in 2D, unless you consider perspective transforms to be 
another "axis")

-- 
~Mike


Post a reply to this message

From: Captain Chemistry
Subject: Re: Speaking of Mathematics
Date: 7 Dec 2004 17:50:00
Message: <web.41b632af864be4ea2d4ac62a0@news.povray.org>
Mike Raiford <mra### [at] hotmailcom> wrote:
> The macro did work for me, except one small problem: there's a "twist"
> at one part in the spline that doesn't seem to make sense.


I belive the twist occurs because the Reorient_Trans macro uses cross
products to get perpendicular vectors for it's new axes and there are
always two solutions that are perpendicular to any two vectors - one going
one way, and one going in exactly the opposite direction.

For some evil reason the macro chose the cross product vector in the
opposite direction - I have had this problem before too.

The only way I overcame it (but not the only way to fix the problem) was
that I designed the shape (or spline or whatever) to be fixed in one axis
(kind of).

For example, I made sure the shape never crossed the positive z axis and
stayed in the negative z axis area. I believe the direction changed when I
crossed the z axis.

What I have said does not give a solution to the problem but I hope it give
some insight into why the problem is occurring.

Nathan


Post a reply to this message

From: Mike Raiford
Subject: Re: Speaking of Mathematics
Date: 8 Dec 2004 08:06:33
Message: <41b6fc59$1@news.povray.org>
Captain Chemistry wrote:
> Mike Raiford <mra### [at] hotmailcom> wrote:
> 
>>The macro did work for me, except one small problem: there's a "twist"
>>at one part in the spline that doesn't seem to make sense.
> 
> 
> 
> I belive the twist occurs because the Reorient_Trans macro uses cross
> products to get perpendicular vectors for it's new axes and there are
> always two solutions that are perpendicular to any two vectors - one going
> one way, and one going in exactly the opposite direction.
> 
> For some evil reason the macro chose the cross product vector in the
> opposite direction - I have had this problem before too.
> 
> The only way I overcame it (but not the only way to fix the problem) was
> that I designed the shape (or spline or whatever) to be fixed in one axis
> (kind of).
> 
> For example, I made sure the shape never crossed the positive z axis and
> stayed in the negative z axis area. I believe the direction changed when I
> crossed the z axis.
> 
> What I have said does not give a solution to the problem but I hope it give
> some insight into why the problem is occurring.
> 
> Nathan

That makes sense. The point where I'm seeing the twist is right where it 
would cross +/- Z.

-- 
~Mike


Post a reply to this message

From: Captain Chemistry
Subject: Re: Speaking of Mathematics
Date: 8 Dec 2004 22:35:01
Message: <web.41b7c7a2864be4eac3fafbf50@news.povray.org>
Mike Raiford <mra### [at] hotmailcom> wrote:
> That makes sense. The point where I'm seeing the twist is right where it
> would cross +/- Z.

I suppose to fix it (maybe) you could create a modified version of
Reorient_Trans and when it does it's cross products, multiply one of them
by the sign of z so when z is positive, there is no change and when z goes
negative, one of the axis vecotrs gets reversed and the cross product
vector stays the same.

....or something like that.

Nathan


Post a reply to this message

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