|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( S4 S( W: r& l/ n& m# v8 }& i; k' g( H8 B' ^% l
& O+ D# W6 H# j' C: `#include <math.h>
2 f: @' [6 O$ l9 U//矩阵复制
: m) M5 X. U- Svoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])# x6 H! Z% _* |9 g7 A. i; Q3 L
{
# R; Y; S3 B2 H9 V. D: q0 i* P int i,j;' r* s6 D+ C" r" G( H4 @
; @6 j. ^% J1 t/ `6 S+ }
for(i=0;i<4;i++)" X6 k& R o+ n0 m! Y3 I
for(j=0;j<4;j++)5 g. E- \- h) b
to_mtx[i][j]=from_mtx[i][j];
7 b* L) I" T3 ?/ ` n! Q}
& W7 ~1 f: ~( L, K4 e! U//矩阵初始化
2 C8 V+ ]( D, G! ~! N& g: c" wvoid Project_Matrix_Identity(double mtx[4][4])
, B( b( M# I7 w; e. t V9 S{% i- o, q5 X: Z5 Z' q8 B, d
int i,j;* G9 t7 x4 a0 ?
7 i) X) s* a7 ] h' z! g. l9 l for(i=0;i<4;i++)
% x) G- ~# @7 X: d. O for(j=0;j<4;j++)
4 _; k; b( `3 j" G+ z; d) F1 z if(i==j)
& B2 X* ?2 B1 c; P3 `$ Q$ I* C1 r mtx[i][j]=1.0;6 d; d! f. B- t: _ g
else1 C. }, h) G. S7 N5 S
mtx[i][j]=0.0;) I5 K1 p! |& O. z0 w
}2 Z! _- h1 y6 n+ X: B
//矩阵相乘/ A! q3 j1 d5 O0 y9 o
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
: M) e0 [% c, g1 K1 [6 l& x2 f. D* E{2 L: {, l) _6 A! p9 E' h; [
9 L8 P ?& T8 ~! G% _
int i,j,k;- n: L( ?: E: z- \& E* h9 @
double left[4][4],right[4][4];1 |' a: w% u) Y1 b2 L8 j" `2 r
. L* V3 n& j! A4 D
Project_Matrix_Copy(left_mtx,left);
6 j5 g$ N/ w/ u. _ Project_Matrix_Copy(right_mtx,right);
! Z S8 p" A% Q) C: ~. } for(i=0;i<4;i++)2 L, v4 L9 V% L9 g; g2 u
for(j=0;j<4;j++)
6 ~( ?; { K' B) h9 J I {
' ^, F6 e, y: y& T s$ k* F8 z4 ~2 _ get_mtx[i][j]=0.0;2 u: \! C2 U; q* d7 y& K
for(k=0;k<4;k++)) Q! f, |7 P g X& c
get_mtx[i][j]+=left[i][k]*right[k][j];3 Z2 E) f7 d( Q# h
}0 ~' A' p( k; D0 j. E1 U. w1 k
}
' F$ Y7 y" z' K; c//转置矩阵1 d' M, v0 m# y1 f5 k2 l
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
- F' D8 {; x9 E. [- A& ~" G{% x8 `" |7 p( {5 f& `% y% h+ o
int i,j;' ^, C J1 `" V: e4 D9 q, t( \: h
for(i=0;i<4;i++)
8 k1 K& J/ w' l; |% c8 E {2 ^* c, R z) x2 A( M- F
for(j=0;j<4;j++)0 M0 r% P0 E: L# ?; [, g
{9 }: t4 ]8 i0 T) `
transpose_mtx[i][j]=mtx[j][i];
7 T* T. i9 g3 c8 i }5 h% B8 b/ k( f5 ~$ a4 @; U
}
) A4 B! L9 F& L9 [}
, J& U& u) i9 \6 L2 ~ E* S( r//从11元组获取变换矩阵
1 f4 d" I& r) }( Q9 o& lvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
/ n0 @! T0 F' d+ i6 a: K- R1 ^{
. F: h# U- G2 |/ h' i5 S: l- S( f+ a; e
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
2 x# f- ?8 b) Q( G int i,j;
3 T4 g( m2 k/ n6 R6 g( U, J for(i=0;i<4;i++)7 ?5 p- N* h" E2 K+ n4 v3 p
for(j=0;j<4;j++)! j% _4 m9 ~3 S) J) u+ W1 k6 X- y$ F
if(i==j)
% y1 ^: B l1 c8 L2 ? B8 } pos[i][j]=1.0;/ k, D! N- [4 J i6 I
else
2 `6 C* u4 i/ l+ f% y A! r) ^, U pos[i][j]=0.0;
: X' N# C5 T+ l7 J" H3 ` pos[3][0]+=translation[0];" R: a0 z A( c4 Y. s/ i
pos[3][1]+=translation[1]; ?, |+ b$ w& _4 Z2 R [
pos[3][2]+=translation[2];
0 O r p5 @ x& E, ~. Z. \0 R}
2 q- h }, d( Z' M, a% W6 V//向量缩放6 s3 I9 I8 j4 a1 n+ F0 d/ ~
void Project_Vector_Scale(double a[3],double scale,double b[3])
- q) ^1 p. q) v6 A) N{
1 s ~+ \4 L+ A- b5 |2 h b[0]=a[0]*scale;
+ R7 Q- u7 c& A' K b[1]=a[1]*scale;
+ C0 G; ]8 K# y2 ]; z7 |' d! B: S" J b[2]=a[2]*scale;
8 {$ Z- C( O; k}
$ b$ J5 E3 J* `% F
1 @4 a" ^9 \2 D- s/ h( l: ? |
|