|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ i: f/ Y! [2 l/ \$ l+ p% H9 v
8 H: k7 |8 g$ j$ O- K C" K. K! e- Z" z9 n+ v( Z8 U0 H
#include <math.h> 6 f; ~- u! `, _ D
//矩阵复制
/ \8 y) |1 G1 l; E& ~: p1 kvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
% w! X% E4 W/ `9 y: ~( v% @{
) B4 t" a& a: L2 h1 g. j int i,j;
' D( G) p/ S) s" B
. E Q$ n" a4 h+ H# x2 Z; r for(i=0;i<4;i++)3 k6 X% h3 V: w
for(j=0;j<4;j++)
' e( g2 B2 c& p' U) Y8 P: }& q to_mtx[i][j]=from_mtx[i][j];
, \. o; G$ c7 ^9 V) b6 U$ v* N9 `}5 O7 J3 D; G- z. j. T3 }
//矩阵初始化6 [$ E; }9 Z3 s* h
void Project_Matrix_Identity(double mtx[4][4])
% z/ T0 [+ s8 W. {2 U{1 T2 I+ A. ~# F; N" u
int i,j;4 X. e# q0 `( I! |1 u& t
0 [. ^+ @" a/ F) d+ p- L! y y
for(i=0;i<4;i++)$ ^0 i( ?' `' d, Q" c! L/ @, h
for(j=0;j<4;j++)
8 R+ i. H3 Z& ^% s0 @5 J! C if(i==j)& `3 X! z- g$ X5 S9 P# x& P
mtx[i][j]=1.0;7 n5 F# h, L& F% k$ |$ f# w
else; q8 s$ D$ I ]9 [! J, M
mtx[i][j]=0.0;
- \+ Q- ]4 o" U0 k5 j* J}' M2 T7 d7 i7 ]8 \
//矩阵相乘
# K. R; V h$ Z/ [void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
$ t* N; t. J8 A- n; e0 _' M+ l+ M{
5 @( P* w# G7 g3 h: b" p: {* B1 @
g J7 k& [0 I! z7 G int i,j,k;
& a0 N U) n4 O7 _- Z% H4 q. `- q: a double left[4][4],right[4][4];
. N7 [7 A. `/ I
* L" A T( W7 o# t Project_Matrix_Copy(left_mtx,left);; [6 |4 ]8 F1 p/ K6 \* T+ `5 _5 n' o
Project_Matrix_Copy(right_mtx,right);9 k- e' ~6 f. u
for(i=0;i<4;i++)
& f: t9 @9 k2 S" Q, P0 m for(j=0;j<4;j++)
! k8 R5 }# g7 t: M3 k {
- E# W/ @. a# n+ [. v$ c3 u get_mtx[i][j]=0.0;. L/ N0 M9 l$ c
for(k=0;k<4;k++)
1 [5 x, U. b1 U$ m- [/ x get_mtx[i][j]+=left[i][k]*right[k][j];
# E) U2 U% ]3 p" | }8 z) M, G9 ^4 j" T3 R- X
}) s& s6 i' ~$ B' N
//转置矩阵( [. ?4 |' ?* I* w0 b) t
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])' `: F: U5 N, S
{# I) R2 }3 B T1 c
int i,j;
. }) l8 ^2 h. `/ \* B9 I& h for(i=0;i<4;i++)
. ]" V: t' O4 A {9 z/ s. n8 {. |& M2 i# {. ^. r4 A# n
for(j=0;j<4;j++)% X f; @& H$ M; i- P5 x
{
# i' a5 T# D, j+ I transpose_mtx[i][j]=mtx[j][i];
( Z8 Y0 |3 G, I8 ] }! D, d/ h! b$ }8 e5 f+ v
}
% P e1 D7 i, n, g}5 a. o: ~; }- _
//从11元组获取变换矩阵
* `7 H% y5 b; zvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])8 C. m. g( b$ V k
{
7 @8 Y, \( L8 ^( C; D
/ I* W1 W: ^9 g //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
3 Z6 X3 h/ [9 S9 `( Y int i,j;
/ Q! h9 g' N; x1 v' s" @ for(i=0;i<4;i++)
1 S& q. C1 `7 ~8 ]3 W! l for(j=0;j<4;j++)
! Y+ T9 i8 a( L U if(i==j)# w3 N2 V% W- i
pos[i][j]=1.0;/ w) j' J _9 W) F/ {
else
) q# ~( O6 c: Q4 a pos[i][j]=0.0;" O6 u$ _& u2 D) I- S9 V" ~' _
pos[3][0]+=translation[0];6 o( S' ?$ \+ S1 s
pos[3][1]+=translation[1];7 [% s% t; c @9 {$ h7 c
pos[3][2]+=translation[2];
- T: y7 M7 ]1 \! [& B2 S}
% P/ G% g4 e2 Q( M) O S6 { S//向量缩放
" q* k0 V9 }# V( s+ Evoid Project_Vector_Scale(double a[3],double scale,double b[3])1 m1 o) [0 |1 j0 o
{& n9 I% C6 }# J2 T2 I
b[0]=a[0]*scale;
' t4 `6 K! T2 S0 c$ w+ \5 C$ F6 @" w b[1]=a[1]*scale;
1 `" j1 Q( Q0 u$ R/ v b[2]=a[2]*scale;8 x6 S8 N- o7 \3 b1 r
}$ s! c! T L4 a. U6 D/ L8 S2 [9 A
$ G% G" s5 a8 d8 t- ^ |
|