|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 a4 B- [5 f6 U( g+ S
9 o0 H) j2 f ?2 l1 T! V' a
5 e; d0 Z, U( _, X+ o- m0 f1 t#include <math.h>
* b- \8 k5 q: q+ W//矩阵复制6 u; J: d) ^# J( K6 ], E1 C5 l( B
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
) d2 [( r/ z. a{" s& [' ~6 G, \/ k4 L% M
int i,j;$ ^' i7 s* E1 _+ h" v
5 S" ^" w9 P1 {# l" K! k( e9 r1 a
for(i=0;i<4;i++)
# z7 Q9 h" B* O/ _ for(j=0;j<4;j++)
( ]& w0 S! x8 m to_mtx[i][j]=from_mtx[i][j];3 d$ E" O. ]8 V2 u2 n* f
}5 }$ P% T2 d7 G4 J' R0 E& b2 E- E0 Q
//矩阵初始化
: `* F. s/ |' ]0 v' N ?void Project_Matrix_Identity(double mtx[4][4])
8 p. w2 A2 d7 P3 x6 w7 Y{
* x" t$ Q+ A" i3 v4 w% B int i,j;
: l6 n9 d, `7 r3 L/ Q
) U h7 b Z' c5 z; q2 t for(i=0;i<4;i++)
$ ?1 @0 ^6 w& _$ L- q- I for(j=0;j<4;j++)
4 P$ C* a) d% k7 { if(i==j)& }% d0 q5 n E- {! `5 h
mtx[i][j]=1.0;; B/ L+ `# f# L$ _
else
6 x. \6 [- d& `3 ]0 g6 W mtx[i][j]=0.0;
# @# V4 e) \/ h4 m7 F}3 W' h5 W8 E* m0 L2 ~, x$ i/ V8 [
//矩阵相乘% Q5 z! q( X$ A, l9 j" V
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])% S' I7 h1 X, `1 }' O: I; }
{
& o+ h9 I* Z, i9 p; L% J" l q, [) ~2 @ ~: d7 h
int i,j,k;
# L! x1 h% E1 m6 D double left[4][4],right[4][4];" G3 f- R6 b5 Y) v
7 S8 I) W7 l Z" m
Project_Matrix_Copy(left_mtx,left);1 X' ?4 X5 w' U: \9 y
Project_Matrix_Copy(right_mtx,right);
( \9 @* G) k: K5 H c for(i=0;i<4;i++)
# P% G. T/ {0 d8 }; \" z for(j=0;j<4;j++)
, V! M' x" I! M7 z! u& H& A$ I {, ~+ J1 r2 C0 b" \! q: n
get_mtx[i][j]=0.0;4 V6 Y& ?- d% R
for(k=0;k<4;k++)
! `! _, l1 q* W# |. ~3 c get_mtx[i][j]+=left[i][k]*right[k][j];
8 \9 Z) Q& l- f4 n* L# y }
* c3 H9 x- ?0 E2 @' n4 K}6 S" K; y$ d" B1 {
//转置矩阵' K7 V2 R# L4 k/ q+ T- \# r
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])1 S9 ~- G3 v* F1 r% ~
{
& m( y. Z3 W' Y+ H, _! A int i,j;
/ Z6 }: T' R& M for(i=0;i<4;i++)
( @+ K7 C: n2 H! {+ j5 t8 h) \ {
* ]/ |* I) \( H4 a! C8 [ for(j=0;j<4;j++)0 N- v9 x0 {( D9 V; i
{
8 N! \( W3 j+ n2 B$ _ transpose_mtx[i][j]=mtx[j][i];5 e. U, Q* ~2 J. R* v' K
}' f3 {; y( E" t5 r0 i" p* ^6 V' b. P
}. M2 f6 F" m; }! v& z
}
' C5 F# a( i; f4 A4 I( F. I) T//从11元组获取变换矩阵/ Q& W( L# h! B; @& M6 W
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4]): J1 e1 L" \3 g2 ^6 X
{
5 S2 p6 H6 b% @% \: ~3 }; U& ` W6 O9 u1 q5 F3 h) p
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
: [6 v' T# C/ h! { int i,j;6 r ?. B4 E5 V: v9 ]
for(i=0;i<4;i++)
* g# m( h5 F' V' r) ~4 r1 k for(j=0;j<4;j++)
' v1 _/ Z5 X6 V+ p if(i==j)1 u, R' { a% \6 ] U/ x8 o! E! J
pos[i][j]=1.0;% R+ A% m' s" g
else
- @# t! e! M2 v4 P pos[i][j]=0.0;
. j5 _% A/ C0 q pos[3][0]+=translation[0];
* y1 P) a: C7 m9 h pos[3][1]+=translation[1];: q0 k: \1 ^. ~5 ~- D% D
pos[3][2]+=translation[2];
5 x+ T+ g5 U& [& t( M" J5 S" ?6 J}
% U8 f, ~! L! U$ ~$ p0 f( R* s//向量缩放5 c; `8 t$ _4 Y# q |7 O2 _
void Project_Vector_Scale(double a[3],double scale,double b[3])
1 Z( ?7 P3 c- G3 c% I, S{
9 P, L7 U0 Z" q' \1 e b[0]=a[0]*scale;1 m7 d% O( y' s' G
b[1]=a[1]*scale;
- I! r1 @5 Y" K& D( [* D+ X b[2]=a[2]*scale;+ a9 B* u& F: |4 k/ v
}
2 g# Y* ], _ \+ h9 s/ B1 h- K) @# j
|
|