|
|
What I asked above can of course be done with a lot of typing. So I did, now
here comes the real question:
Sitiuation: I have a object that has been located with this transformation
matrix somewhere in space:
matrix
<0.000934544,-0.000208202,-0.000288581,-0.000206635,-0.000977747,3.62463e-005,-0.000289705,2.5757e-005,-0.000956769,-1.
40094,-0.307333,2.40367>
Now I need to rotate that object 10 degrees around it's own Z-Axis and after
that 20 degrees around the new resulting Y-Axis.
I found out how to rotate objects around the world axis using matrixes, but I
need to rotate around the objects current axis system. How do I accomplish that?
Thanks,
Andi
Post a reply to this message
|
|
|
|
Le 18/03/2011 19:00, CAD-Andi nous fit lire :
> What I asked above can of course be done with a lot of typing. So I did, now
> here comes the real question:
>
> Sitiuation: I have a object that has been located with this transformation
> matrix somewhere in space:
>
> matrix
>
<0.000934544,-0.000208202,-0.000288581,-0.000206635,-0.000977747,3.62463e-005,-0.000289705,2.5757e-005,-0.000956769,-1.
> 40094,-0.307333,2.40367>
>
> Now I need to rotate that object 10 degrees around it's own Z-Axis and after
> that 20 degrees around the new resulting Y-Axis.
>
> I found out how to rotate objects around the world axis using matrixes, but I
> need to rotate around the objects current axis system. How do I accomplish that?
Translate the object to the origin, rotate, translate back.
translate -Pos
rotate 10*z
rotate 20*y
translate Pos
Post a reply to this message
|
|
|
|
"CAD-Andi" <nomail@nomail> wrote:
> Hi!
>
> 1. Is there a simple way to populate a matrix with an array?
> 2. Is there a simple way to multiply two matrixes with each other and have the
> result stored in an array?
Hi Andi
Perhaps the code below will answer those questions.
Tor Olav
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2011 by Tor Olav Kristensen, http://subcube.com
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#macro PrintArray(AA)
#local DimR = dimension_size(AA, 1);
#local DimC = dimension_size(AA, 2);
#debug concat("array[", str(DimR, 0, 0), "]")
#debug concat("[", str(DimC,0, 0), "] {\n")
#local CntR = 0;
#while (CntR < DimR)
#debug " { "
#local CntC = 0;
#while (CntC < DimC)
#debug str(AA[CntR][CntC], 0, -1)
#if (CntC < DimC - 1)
#debug ", "
#end // if
#local CntC = CntC + 1;
#end // while
#debug " }"
#if (CntR < DimR - 1)
#debug ","
#end // if
#debug "\n"
#local CntR = CntR + 1;
#end // while
#debug "}\n"
#end // macro PrintArray
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#macro TransformFromArray(AA)
transform {
matrix <
AA[0][0], AA[0][1], AA[0][2],
AA[1][0], AA[1][1], AA[1][2],
AA[2][0], AA[2][1], AA[2][2],
AA[3][0], AA[3][1], AA[3][2]
>
}
#end // macro TransformFromArray
#macro ArrayFromTransform(TT)
#local ProbeFn = function { transform { TT } }
#local vT = ProbeFn(0, 0, 0);
#local v0 = ProbeFn(1, 0, 0) - vT;
#local v1 = ProbeFn(0, 1, 0) - vT;
#local v2 = ProbeFn(0, 0, 1) - vT;
array[4][4] {
{ v0.x, v0.y, v0.z, 0 },
{ v1.x, v1.y, v1.z, 0 },
{ v2.x, v2.y, v2.z, 0 },
{ vT.x, vT.y, vT.z, 1 }
}
#end // macro ArrayFromTransform
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// A little test
PrintArray(
ArrayFromTransform(
TransformFromArray(
ArrayFromTransform(
transform {
translate <5, 6, 7>
scale <2, 3, 4>
}
)
)
)
)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The first matrix
#declare Angle1 = 10;
#declare Cos1 = cos(radians(Angle1));
#declare Sin1 = sin(radians(Angle1));
#declare T1 =
transform {
matrix <
1, 0, 0,
0, Cos1, Sin1,
0, -Sin1, Cos1,
0, 0, 0
>
}
//#declare T1 = transform { rotate Angle1*x }
#declare A1 = ArrayFromTransform(T1)
PrintArray(A1)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The second matrix
#declare Angle2 = 20;
#declare Cos2 = cos(radians(Angle2));
#declare Sin2 = sin(radians(Angle2));
#declare T2 =
transform {
matrix <
Cos2, 0, -Sin2,
0, 1, 0,
Sin2, 0, Cos2,
0, 0, 0
>
}
//#declare T2 = transform { rotate Angle2*y }
#declare A2 = ArrayFromTransform(T2)
PrintArray(A2)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Mmultiply
#declare T1T2 =
transform {
T1
T2
}
#declare T1T2 =
transform {
T1
T2
}
/*
#declare T1T2 =
transform {
rotate Angle1*x
rotate Angle2*y
}
*/
#declare A1A2 = ArrayFromTransform(T1T2)
PrintArray(A1A2)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The third matrix
#declare Angle3 = 70;
#declare Cos3 = cos(radians(Angle3));
#declare Sin3 = sin(radians(Angle3));
#declare T3 =
transform {
matrix <
Cos3, Sin3, 0,
-Sin3, Cos3, 0,
0, 0, 1,
0, 0, 0
>
}
//#declare T3 = transform { rotate Angle3*z }
#declare A3 = ArrayFromTransform(T3)
PrintArray(A3)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Multiply again
#declare T1T2T3 =
transform {
T1
T2
T3
}
/*
#declare T1T2T3 =
transform {
rotate Angle1*x
rotate Angle2*y
rotate Angle3*z
}
*/
#declare A1A2A3 = ArrayFromTransform(T1T2T3)
PrintArray(A1A2A3)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
|