|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! Z; r# x) t4 P* N
4 E# Z* k7 `& ^
3 M# P) {6 ]0 O$ w4 {#include <math.h> 7 c* c r, w- z2 w* Z2 G" r
//矩阵复制+ |5 N8 D+ P/ L
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
2 s5 }( V3 ]1 o! S0 \% j$ f! L, m{2 Q9 \! J! x- B: K; t9 Q
int i,j;/ g v) `! ^) ?. s
. q' ]/ A0 s. R* }' f% x for(i=0;i<4;i++)$ Z- D# Q3 R9 ?. {" j: n
for(j=0;j<4;j++)3 ^5 [4 [8 }- v1 W& V8 I* P1 v
to_mtx[i][j]=from_mtx[i][j];& ?# w' j; g; k; p' U
}( x) \2 ~$ h1 m" }% I
//矩阵初始化% w5 [0 {( E" @
void Project_Matrix_Identity(double mtx[4][4])6 r. N" b0 K3 P3 x
{5 P; Y3 B% E0 L; A0 ^; g
int i,j;) W* e0 m/ K+ W+ o1 G0 Q
# x' ]' t, O* ?4 h for(i=0;i<4;i++)0 p+ h* c# p* L% h' F' c
for(j=0;j<4;j++)! |) D2 v& Z6 {, b
if(i==j)
2 ~" d8 ~ x6 x9 f mtx[i][j]=1.0;! x* @" ?! }% ^. P: t4 [" P
else( J- e, _( `$ V: i5 e, a1 a
mtx[i][j]=0.0;, \- j! T; }) p. e i
}0 X1 @; o7 R( O+ v. ~, W- ?3 k3 o; K
//矩阵相乘8 o X% N2 R5 N- p
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])$ e) A6 Y1 ^" o$ l; D
{
4 R0 W5 j6 a' k }; u; i# `
6 W8 U U. ?, K0 S6 d5 N- f# ] int i,j,k;- J* R) V' f: @ q
double left[4][4],right[4][4];
: L3 b$ n4 }5 L& i+ }$ r& P5 G( q# i6 Z& }7 Z7 a
Project_Matrix_Copy(left_mtx,left);
, R- E5 Q5 D4 h5 ^, h! P Project_Matrix_Copy(right_mtx,right);7 V! n( J" D5 S& ]$ C" f
for(i=0;i<4;i++); I/ J: Q% q6 b2 g5 B2 m
for(j=0;j<4;j++)
6 Q% W( w3 ^7 y* Z" j1 P {
7 Y& @5 s3 u5 V& `# [7 y get_mtx[i][j]=0.0;
! e; Q% n/ n4 ^) g7 n7 L for(k=0;k<4;k++); p n5 T; T% H ]
get_mtx[i][j]+=left[i][k]*right[k][j];2 d8 M# W7 l/ z+ I8 B9 Q0 @
}
# j) A2 T% _4 ]$ ^}" z! ^, k* y8 T
//转置矩阵1 ^8 {; i9 B- k- M/ s
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])- c5 V1 y& A6 B- h- N
{- Y( Z% @1 j" ?3 i; N
int i,j;
9 E' ^' i% {* u- x7 _ for(i=0;i<4;i++)
4 `: q+ o% J2 f4 {, {6 v {8 J* J5 _% `) _3 \) b
for(j=0;j<4;j++)
( O3 `, H" E! \1 n; F" |9 \& I {
! t0 z9 ]' u I+ j( R, h! [4 c transpose_mtx[i][j]=mtx[j][i];
: _0 x! |0 N$ G# t }
7 @+ i5 {) [; G5 O" T+ ` }! p5 v% I- T' B2 P% {0 j/ c& O$ m
}! A" m2 f0 ?* z: z) Y
//从11元组获取变换矩阵/ b4 f G. z+ k& a
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])8 ] `& Q, Y) p* G- L# v$ p
{
2 u& u. p0 e4 V* p' [/ i8 i/ D, I8 j' W- J
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
( M. @1 K6 _! o7 w; G5 j int i,j;' z( P7 U$ Z* Z8 U' x+ d* `, j* H
for(i=0;i<4;i++)6 ?1 m& M1 K1 I& v i! j F/ P
for(j=0;j<4;j++)' H, Q5 G* ~# M2 D6 k7 d% Y
if(i==j)
+ Z$ [" M" U& k$ S, w pos[i][j]=1.0;
; \8 X1 f+ y* f1 s$ L0 B else
8 e; \ e* _/ f& v pos[i][j]=0.0;
* I$ K( \6 B9 ?( t$ n8 n4 x pos[3][0]+=translation[0];
3 G- f, C2 O: O l' n1 b pos[3][1]+=translation[1];
' w, c9 \& h; I* ~6 R! q5 ?; G pos[3][2]+=translation[2];
3 M1 \" m6 u; N) V: W' @( [}9 l0 [' b7 D8 e8 m1 l: }3 T! n$ U
//向量缩放4 v( T0 m. K; L* J0 y
void Project_Vector_Scale(double a[3],double scale,double b[3])
' M9 S: U5 E1 G{1 E" P) r. H# T4 k$ N+ m+ \
b[0]=a[0]*scale;
# N# `4 F* I; S b[1]=a[1]*scale;
$ y9 f0 ?/ }- ~3 d3 M" X0 i b[2]=a[2]*scale;
. X/ x" O7 M5 I1 B" R}( R" F2 x: W7 I) E6 l
: y( t" A4 h6 Z9 U, Q4 W, f+ P' r
|
|