|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 Y: d9 c1 n7 V; ]' J/ ?. b
5 t# ~4 R3 `# @1 N }$ m$ [6 @ S+ W2 i1 z4 o3 r
#include <math.h> " V! `+ u2 S; Y
//矩阵复制1 c8 E5 u- p+ d/ \( r* I5 ]
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
& {' [3 z/ G: ?+ C{) X4 ~! f2 u% d. K. {, R: q) \
int i,j;
5 Y# O+ @- z$ M( p. t/ @2 h4 m- [4 ^( M" ~/ R0 h& m
for(i=0;i<4;i++)/ w, H0 f _: @& ~4 u
for(j=0;j<4;j++)
: y6 y4 J8 V. y to_mtx[i][j]=from_mtx[i][j];
0 R3 U/ ^1 T. i% _ a) @& F. t. F* A/ B/ @}& }+ h: A8 ^+ I2 |( z8 L4 c
//矩阵初始化, R1 T E9 R% p# ? ?* p
void Project_Matrix_Identity(double mtx[4][4])$ ^, y# x+ R7 u! ?
{
- m- u3 k; l. |8 P: h5 b3 p! Y int i,j;0 d& e/ ^" w S+ v
D/ I( q, V/ W8 _% a for(i=0;i<4;i++)) t6 d( K- b/ J" u0 I
for(j=0;j<4;j++)
+ c/ T3 v" f8 a g3 t; o if(i==j)
% R7 N# ~+ T `# r2 _' P mtx[i][j]=1.0;
, J' Q" H! Y$ O \- v$ Z; S else w/ a1 c5 k' X1 K8 O
mtx[i][j]=0.0;
' e" @, P3 i+ Z! ~; g}' t( ]( H# l7 A; R% d
//矩阵相乘
' S5 A3 K9 G6 T3 O' X& r0 Pvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
. d- \+ M8 \/ i{% t! w1 n# p; c5 e: M
+ Z6 C7 A2 g2 y5 x/ I+ y
int i,j,k;/ `* L- y' Z0 \, h7 B5 X& X# L' b
double left[4][4],right[4][4];
# q* t$ I5 s! P3 C e
" [" ?6 A9 ~. ?3 M( T Project_Matrix_Copy(left_mtx,left);
5 M# C j: o+ s; B0 Q* p5 e/ r2 s Project_Matrix_Copy(right_mtx,right);
/ R1 {! J3 `# n- n for(i=0;i<4;i++)2 J, O8 e3 q0 U, M, N, j5 T
for(j=0;j<4;j++)0 S9 n3 K1 H/ I# ^/ ] F& T2 b
{
6 j4 E7 V# P( N1 }* E! v get_mtx[i][j]=0.0;
9 N7 j4 d9 v5 W- x# l for(k=0;k<4;k++)+ K& U0 d9 A$ Z+ Y& _
get_mtx[i][j]+=left[i][k]*right[k][j];% {% [5 o; C7 w% L9 K& x
}
, ~ r0 J, z- v: X& c% P/ g _6 [}
5 v( k9 ~& j0 R4 a8 \% ^" P/ @//转置矩阵
% ?" _2 e2 L6 \7 r) \; yvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])6 ?9 `) Y. J% q2 M6 _" v; t" j1 _0 i
{: ]2 K2 j+ w R1 A3 q
int i,j;
4 h. E1 l$ P. c+ e7 d6 v0 U for(i=0;i<4;i++)
8 V" w1 n _; k6 ]6 |( K {
3 d4 F/ d: I% J9 { y+ E for(j=0;j<4;j++)
4 c$ \: Y3 ~$ B# L& `/ o9 Y; M& n {0 Q6 |! i4 ?1 a L0 s3 L% ^
transpose_mtx[i][j]=mtx[j][i];9 R& p+ \. }& y& j3 G" j
}
1 f) e, Y: w' Q$ _7 I }
! V c T4 |' A% V# Z& R7 ~' W}+ L# [' @* N5 ^. g+ q, x
//从11元组获取变换矩阵 {" {$ s/ I' L5 ~; y, [
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4]) l, R J3 D& r. p& G# D
{
8 e9 y6 Y! [; A9 V8 D2 x+ `3 C7 A0 {, C4 @& ^. d* c4 P; s
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
( u' X+ Z9 s# o" I9 S8 ^ int i,j;
- r1 U3 b1 c( }5 g" d# _2 F& r for(i=0;i<4;i++)
( H- u* h/ c- j. _: {* T for(j=0;j<4;j++)
9 ?' Z1 H* {7 l! `; l if(i==j)* S7 S1 @5 ]3 x9 y1 [- y9 c* q
pos[i][j]=1.0;
. v2 W" k* g( u* H. K else, D7 q! D1 o' I0 }
pos[i][j]=0.0;
; y2 {: C: q& |1 F8 b pos[3][0]+=translation[0];
O* \- q6 F( L9 N' a pos[3][1]+=translation[1];6 k6 B% m4 N; q& A8 n2 [ V
pos[3][2]+=translation[2];
7 ~4 f4 t9 [$ @5 [$ p, T" e" N}
4 u$ q' b$ h) Y: s4 n) R$ e//向量缩放' M2 f8 l- B6 \0 m- R
void Project_Vector_Scale(double a[3],double scale,double b[3])
3 r3 m7 i8 P, V' G6 S8 q2 F+ v _{: j k# b# _$ w9 [8 l
b[0]=a[0]*scale;
4 T0 r1 F2 v$ C/ g4 }7 o2 X+ L& i b[1]=a[1]*scale;
; B4 w5 c( y' \/ V! F6 j+ D0 I8 W4 E b[2]=a[2]*scale;
3 {( N$ ]+ f5 |3 O" @}5 n4 b. O# x, _( M
) `5 a; T$ |6 y
|
|