|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
4 m9 ^% E( [7 p. f
0 D+ \2 I! ?& V$ m0 _7 X) R" t" d- h; {! o4 a
#include <math.h> 3 R, O! h) ~. j7 q, X3 K5 I
//矩阵复制: Y4 _; z5 P! ~: D( B0 M; Y
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])& C N/ v1 ~! A
{
- x9 h0 E+ ~0 o" g0 p int i,j;# M' D) ?4 o, A& a3 L
" m) t. x$ n0 ^ for(i=0;i<4;i++)
' G7 I- }' }$ v9 }! ^: ` for(j=0;j<4;j++)& I" Q! O1 l+ A8 g2 k
to_mtx[i][j]=from_mtx[i][j];
- l* D7 N5 `* \/ W6 r1 @}
& f0 Q2 k; d5 e& P2 ^: B) f//矩阵初始化9 `" J) D% `/ M! |' M& G
void Project_Matrix_Identity(double mtx[4][4])8 R( r) c, o$ H/ j1 F* K( G
{; A f9 P+ g4 A+ g$ e
int i,j;9 g, z+ l ]2 i* K+ o; }
& j I% h! w8 f: ?/ I: }4 b2 q for(i=0;i<4;i++)
1 J, ]" ]# [9 Y1 H for(j=0;j<4;j++)9 x, U! u+ P6 z& e+ r5 g! i
if(i==j)
& p1 l* G) {/ G( |$ M mtx[i][j]=1.0;* T* g" v F" F4 z5 s0 U% e! x
else) R+ k9 V4 ?2 C# U9 X
mtx[i][j]=0.0;1 |3 D E* O( } H% U! A1 t
}, P# Y/ O0 y) n5 ?6 r# T
//矩阵相乘' G4 A8 D: G) ]
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])7 G( d" T6 o" R, A* c D4 l0 s
{& c8 l8 C& x9 s
) b- c2 J, s; i6 [% m& m
int i,j,k;4 G. _9 l% j* ]
double left[4][4],right[4][4];; [- H& V. _! e) H0 C
# `" q6 T% O2 t, C: d$ Y4 v
Project_Matrix_Copy(left_mtx,left);
9 K2 q8 i8 o6 U! v& j5 f+ ^; l Project_Matrix_Copy(right_mtx,right);
2 J- X$ S& z, E1 n* Z for(i=0;i<4;i++)4 E3 k5 s, f8 g4 g- k8 B* O$ o
for(j=0;j<4;j++)
& m+ `3 n- [+ I' w- F- D {2 Z7 H+ ^/ G6 D4 D( P
get_mtx[i][j]=0.0;
5 k/ V) x6 @' |" T for(k=0;k<4;k++) f, k+ |% G3 ?. P( s
get_mtx[i][j]+=left[i][k]*right[k][j];
6 k* M B0 q5 P# a, T }8 b( z: y4 F# {0 }: b
}# Z+ S3 O# b& K
//转置矩阵' {( t7 ]( h6 j, i& I' U' w. C
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])4 v4 } @# \, _7 B4 q5 U4 h
{
, Z6 ~% x* B5 I1 U& G! M7 ]3 Z3 J int i,j;
* H- J( J0 v- D7 K* `! o for(i=0;i<4;i++)9 B5 ^% a# ]( Q% O/ u
{
h1 J5 B0 j# d& S O1 G6 y for(j=0;j<4;j++)
' K T% g! R7 M& k% m+ r {
! \5 V0 |4 ]5 r9 Y, f. d transpose_mtx[i][j]=mtx[j][i];0 [! q' ~" Z# t4 T" O$ l# ~
}
$ M# K `! H5 C3 ?% B X! O4 { }7 H7 W- J) D8 p+ S6 ]4 i
}
7 j/ W& A1 e# q' A, G L//从11元组获取变换矩阵: i& e6 D; T6 p+ Y! l l; J+ U; D9 e+ `- k
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])6 U: C0 [" n+ U2 d/ K; h0 b& s" y
{! _% G3 b& s4 K- A# B
3 E3 L7 n2 ~4 x2 z( E* Q7 @
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);9 {- A1 _, [/ i1 q% |$ C
int i,j;
) p0 y' V! c! ~ M8 K for(i=0;i<4;i++)+ l, [7 o j4 n
for(j=0;j<4;j++)
3 R1 G, Y* y# e v; Y- a if(i==j)
: Z. U+ j& ` n$ d" U4 ^ pos[i][j]=1.0;
( T& g& Z5 J" K else1 b% ?# ^3 q/ ?' J' G
pos[i][j]=0.0;
* R, C/ H$ ~9 E; u8 i- g' r9 y9 f: ~ pos[3][0]+=translation[0];
7 G$ v. S2 K2 M; N) \, b pos[3][1]+=translation[1];
1 b" v3 W$ f# G" U* W7 l pos[3][2]+=translation[2];
* j5 h9 S( B0 y7 E}
7 G4 Z9 f! U) P! i//向量缩放' U) A8 K- J# p- Z
void Project_Vector_Scale(double a[3],double scale,double b[3])" G" G9 v! G9 Y' G; s6 |- ^$ ?
{
% U# C' t) {6 {6 ? b[0]=a[0]*scale;
5 l2 e& r: r$ F! d2 b; j b[1]=a[1]*scale;
, O* Y5 T1 f4 m. s$ r# b5 ?4 f b[2]=a[2]*scale;
* Z* j* B: z Y5 _4 [' c3 f/ N$ r, d}
. A0 E0 j0 V% F: p, N
0 g& Y, r3 f6 a1 M8 L |
|