|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- L A; Z; F' N' l7 e. e! A
; K. A$ W' S' W) }% y
* W, |/ [4 t* N#include <math.h>
; x& {4 p) Y2 P/ H//矩阵复制
! C# f8 ~+ u4 P- u* Q u, Evoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
8 u t! Q/ n4 G{4 O( _: Q3 S x# x& {
int i,j;" C5 K6 D* Z( }0 W4 l3 A
# }) ?0 N* q& ]; U4 R6 Z9 @, F1 k! p
for(i=0;i<4;i++)
j8 Q0 Q, c2 O, `" ?! h" Y; |* N for(j=0;j<4;j++)
" q& | K R" b: A& E to_mtx[i][j]=from_mtx[i][j];
& C' a3 L! x5 h9 A8 r, _}: C# E8 c! J: J Z: c H; m" t
//矩阵初始化
, G" ~1 F2 @7 k+ C" d8 zvoid Project_Matrix_Identity(double mtx[4][4])* N6 i4 b5 m$ E) T6 D, \
{
$ Z% ^) D# j' q5 ^8 n+ ?# b int i,j;
9 x R7 a3 W/ q% h0 \0 C1 [1 { 4 t! P* w! Z( T! p0 y$ [) R0 y
for(i=0;i<4;i++): i* E$ w3 A# _; j0 G0 e
for(j=0;j<4;j++)
+ n2 ^" X& _( E G if(i==j)* c# [" k" @" m- Z" g: v
mtx[i][j]=1.0;7 n0 n; Q& I1 W/ E$ W
else3 f9 ]# I9 k$ q
mtx[i][j]=0.0;
) t6 @0 n% s3 _( E& A5 j6 m}
& l" [$ @! f, |6 V9 w v+ g//矩阵相乘. e5 x- r- I& X! d- Y7 p6 Z
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4]) S1 P$ Q6 o, }* o, C
{; j8 d6 B6 z) V7 S
" c Y3 T3 ]2 b) Y- Z$ ] int i,j,k;2 u5 u' X" j. }$ m( S; w; K
double left[4][4],right[4][4];
F0 R7 O O$ X# g5 i' N& N+ I0 F" T. a1 ]
Project_Matrix_Copy(left_mtx,left);+ t+ ?- v" W' k
Project_Matrix_Copy(right_mtx,right);( G) e- J* n8 T
for(i=0;i<4;i++): z- G9 D. U" I+ E
for(j=0;j<4;j++)
) k+ N6 L$ _: U. s \+ X" B {. [9 P- l1 ?) m$ c
get_mtx[i][j]=0.0;# |( Z* G. T) I1 O2 M; K
for(k=0;k<4;k++)& j- E! k0 {6 D6 v' V7 Y
get_mtx[i][j]+=left[i][k]*right[k][j];
* |% U1 L. v9 x- ?* I# X }2 i. S f) {$ x9 T
}
; [( O: v% n" U3 Z//转置矩阵
1 I9 y) N" p# {1 o! cvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4]) _8 Z- B/ `) y- i& w
{
5 I' R A+ V7 s) `; u3 ^- E int i,j;# X- S: P; w5 R6 X* Q2 N- c
for(i=0;i<4;i++)3 b Y. s* v' ?3 U- @6 D
{$ c2 }. {1 w; ?3 U8 Z5 o' Z
for(j=0;j<4;j++)
3 E! ^+ N- T( \' S {
, d( ~( |4 q- G4 O6 k transpose_mtx[i][j]=mtx[j][i];
7 i* U& U! C$ c) A+ o }3 b& j7 S3 A: K, j+ ^+ ~
}! Y, b3 c7 n4 |' `: p$ i
}4 J5 a' z4 ~* |( T1 x
//从11元组获取变换矩阵
& K0 r+ B D, [- F8 ^void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
& H/ R9 K! f0 u, K: L6 L! |{; C0 F. z( C4 ~
: p$ x* w* q( u7 }5 R. P- U //Project_Matrix_Get_Rotation(rotation,point,angle,pos);% S, h9 `! r) a; Z
int i,j;. y5 Q* J- D' G1 L' `% l0 T
for(i=0;i<4;i++)
% v ^# [4 C" x+ K- O for(j=0;j<4;j++): f- e! R: U# {/ |/ y
if(i==j), I; w8 f# t* ?, h/ _
pos[i][j]=1.0;
, A# A, O# w! ~+ W. h4 S B else
6 N/ i( p- k9 L; ]$ B3 }# i pos[i][j]=0.0;0 j, A P7 _. N/ O8 P
pos[3][0]+=translation[0];
4 H/ S& J0 U. h1 b1 K pos[3][1]+=translation[1];% }" k; ]5 y6 X
pos[3][2]+=translation[2];7 ~' `5 e2 Y4 r* V9 r
}
: s7 L1 P: M7 l: |//向量缩放
" ^$ ^3 H& f4 P5 xvoid Project_Vector_Scale(double a[3],double scale,double b[3])+ [4 I' M$ @/ M9 g$ v- ?+ n+ j
{# V( S9 {; Z7 `, q
b[0]=a[0]*scale;
# I4 Y- L9 c; \- x( I b[1]=a[1]*scale;
: [( H# ?- q8 i0 @0 o b[2]=a[2]*scale;
5 C2 r& |* Q9 F. u. o}
# \7 Y* i8 N/ q. E5 Q
& c! L: f# r3 a4 {, U( P6 u; C |
|