POV-Ray : Newsgroups : povray.advanced-users : Help me with matrix please... Server Time
30 Jul 2024 12:21:36 EDT (-0400)
  Help me with matrix please... (Message 1 to 7 of 7)  
From: TonyB
Subject: Help me with matrix please...
Date: 26 Sep 1999 10:44:10
Message: <37ee313a@news.povray.org>
Hello. Thank you for reading. I need help with my matrixing. I know
everybody else here understands them and/or owns a TI-86 and/or equivalent.
I have neither. I don't care about the calculator (the Casio fx-570s offers
everything I need), but I do care about matrix. I hope I can explain this.
Let me see... ok.

Given 2 points in 2D* or 3D space, A and B, how can I make an object rotate
to line itself up to the line AB? My intention is to give an object a path
to follow over an uneven surface, and using the trace() function on the
front and back of the object, generate the points A and B to help my object
avoid obstacles. A third trace() would be taken from the center of the
object, C, and the point (A,B or C) that has the highest y determines how
high the object is placed over the path.

Right now I am using (and it doesn't work right, so that's why I'm here) the
following macro:


#macro apunta(A,B)
 #declare X=vnormalize(B-A);
 #declare Z=vnormalize(vcross(X,y));
 #declare Y=vcross(Z,X);
 matrix
 <
  X.x,X.y,X.z,
  Y.x,Y.y,Y.z,
  Z.x,Z.y,Z.z,
  A.x,A.y,A.z
 >
#end


Given:


#declare A = <0,2,1>;
#declare B = <0,1,-1>;

sphere {A,1/2 pigment {rgb <1,1,0>}}
sphere {B,1/2 pigment {rgb <0,1,1>}}

box
{
 <1,1,2>,-<1,1,2>
 pigment {red 1}
 aim(y,B)
 translate y*(Y+2)
}


Why doesn't it work right?


* I say 2D, because sometimes I might write the points as in the example
given.

--
Anthony Bennett


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Help me with matrix please...
Date: 26 Sep 1999 11:48:35
Message: <37ee4053@news.povray.org>
In article <37ee313a@news.povray.org> , "TonyB" 
<ben### [at] panamaphoenixnet> wrote:

> Given 2 points in 2D* or 3D space, A and B, how can I make an object rotate
> to line itself up to the line AB?

You just want the rotation, so you need to find them one after each other.
In the following I will assume the left-handed coordinate system. I will
call your vector AB = V .

First, determine the rotation between needed to the vector will be in the
xz-plane. Doing so is easy:

r = vlength(V);

so you get

sin a = V.y / r

your first angle is

a = asin(V.y / r)       // Remember: POV-Ray returns asin in radians!


Next you want the angle of the newly fromed vector (or any vector with the
same direction) with the x-axis

M = <V.x, 0, V.z>

r = vlength(M);

g = asin(M.z / r)


Now you have to angles, I guess you can figure out the rest yourself :-)


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: David Wilkinson
Subject: Re: Help me with matrix please...
Date: 26 Sep 1999 11:50:35
Message: <6UDuNx9paZMoVnaRo+h0Aa9sVOA2@4ax.com>
On Sun, 26 Sep 1999 09:38:24 -0400, "TonyB" <ben### [at] panamaphoenixnet> wrote:
>
>Given 2 points in 2D* or 3D space, A and B, how can I make an object rotate
>to line itself up to the line AB? My intention is to give an object a path
>to follow over an uneven surface, and using the trace() function on the
>front and back of the object, generate the points A and B to help my object
>avoid obstacles. A third trace() would be taken from the center of the
>object, C, and the point (A,B or C) that has the highest y determines how
>high the object is placed over the path.
>
>Right now I am using (and it doesn't work right, so that's why I'm here) the
>following macro:
>
>
>#macro apunta(A,B)
> #declare X=vnormalize(B-A);
> #declare Z=vnormalize(vcross(X,y));
> #declare Y=vcross(Z,X);
> matrix
> <
>  X.x,X.y,X.z,
>  Y.x,Y.y,Y.z,
>  Z.x,Z.y,Z.z,
>  A.x,A.y,A.z
> >
>#end
>
>
>Given:
>
>
>#declare A = <0,2,1>;
>#declare B = <0,1,-1>;
>
>sphere {A,1/2 pigment {rgb <1,1,0>}}
>sphere {B,1/2 pigment {rgb <0,1,1>}}
>
>box
>{
> <1,1,2>,-<1,1,2>
> pigment {red 1}
> aim(y,B)
> translate y*(Y+2)
>}
>
From your example Tony I am not really clear what you are trying to do, but I think
that
what you want is one of John Van Sickle's macros - Reorient. Its on his web site:-
http://users.erols.com/vansickl/macs.htm

The input to his macro is two vectors.  The first is the existing axis of orientation
and
the second is the vector of orientation you are wanting.  Calling the macro generates
two
matrix definitions which will re-orientate your object. You then have to translate it
to
where you want it.

Hope this helps.
David
------------
dav### [at] cwcomnet
http://www.hamiltonite.mcmail.com
------------


Post a reply to this message

From: TonyB
Subject: Re: Help me with matrix please...
Date: 26 Sep 1999 12:04:20
Message: <37ee4404@news.povray.org>
Thank you. I was doing it with atan2(), with no success. That's when I tried
that other macro. I will try what you suggest later on today. Thank you
again.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Help me with matrix please...
Date: 26 Sep 1999 12:28:06
Message: <37ee4996@news.povray.org>
In article <37ee4053@news.povray.org> , "Thorsten Froehlich" 
<tho### [at] trfde> wrote:
> M = <V.x, 0, V.z>
>
> r = vlength(M);
>
> g = asin(M.z / r)

Ups, acos of course - sorry!


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Help me with matrix please...
Date: 26 Sep 1999 12:39:04
Message: <37ee4c28@news.povray.org>
Here the solution with example:


#version 3.1;

camera
{
  location  <20.0, 20, 20.0>
  direction 1.5*z
  right     4/3*x
  look_at   <0.0, 0.0,  0.0>
}

light_source
{
  <20.0, 20, -20.0>
  color red 1.0  green 1.0  blue 1.0
}


#macro apunta(A,B)

#declare My_V = B - A;
#declare My_a = degrees(asin(My_V.y / vlength(My_V)));
#declare My_M = <My_V.x, 0, My_V.z>;
#declare My_b = degrees(acos(My_M.z / vlength(My_M)));

rotate y * -My_b
rotate x * My_a

#end


cylinder
{
  <0, 0, 0>,  <6,5,4>,  0.2
  texture { pigment { color red 1 } }
}

cylinder
{
  <0, 0, 0>,  <6,5,4>, 0.15
  texture { pigment { color green 1 } }
  apunta(<0,0,0>,<6,5,4>)
}

cylinder
{
  -3*x,  10*x,  0.1
  texture { pigment { color red 0.5 } }
}

cylinder
{
  -3*y,  10*y,  0.1
  texture { pigment { color green 0.5 } }
}

cylinder
{
  -3*z,  10*z,  0.1
  texture { pigment { color blue 0.5 } }
}

plane
{
  y, 0
  texture { pigment { checker color rgbt <0, 0, 0.5, 0.2> color rgbt <0.5,
0, 0, 0.2> } }
}



____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: TonyB
Subject: Re: Help me with matrix please...
Date: 26 Sep 1999 14:32:05
Message: <37ee66a5@news.povray.org>
Oh, thank you so much Mr. Froehlich! Muchas gracias! Domou arigatou
gozaimasu! =Danke! It works perfectly. I was just about to do as you
suggested when it occurred to me to check in here.


Post a reply to this message

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