|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: V& ]. j' P! `
- w& y- {- T! w& ]$ b9 |. _# m( A& `$ l: P7 }
#include <math.h>
* M1 W6 A5 Z$ h! r; g9 B//矩阵复制) @! J! S: H$ t b3 j5 u
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])* B7 P; l# n3 {4 ~4 @4 k( L
{" _1 L7 N, y' g3 y: r" z6 d
int i,j;! V1 H, s3 F, F! {6 ~
% j" M. m% f+ m
for(i=0;i<4;i++)- U& c/ x" Q' ]# `" W
for(j=0;j<4;j++)
' J* I5 U( L. ?' o, \: q to_mtx[i][j]=from_mtx[i][j];. D3 h5 C9 d" V& M7 Y
}% P% f: ]" t7 `4 ~
//矩阵初始化
: E' A1 E6 w g# F2 S7 e" P0 C/ pvoid Project_Matrix_Identity(double mtx[4][4])
- b" n# y) T( j( h$ _, @{
0 j& f' J& r, `( S2 e+ \1 ] int i,j;
. V: C, D; `* u ! \1 r& B) ]* r
for(i=0;i<4;i++)# I( u8 T- B: I% G) H
for(j=0;j<4;j++)
7 M$ d" W9 z8 v: e6 [0 _' |; E if(i==j)4 t8 B+ Q! l. D% ^" I
mtx[i][j]=1.0;" G- h3 y7 K O7 @* M/ n$ T v6 l i* h3 s
else
1 e3 P! ^1 c5 e# }; K) X0 e% O mtx[i][j]=0.0;
! J4 Z+ `& |. y* _! _. L( t3 p}
" y4 ?! A2 t0 c: u# \//矩阵相乘
. a6 q8 L1 `+ N& s. U" y9 ?# pvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
& [& c/ _6 L* o% y0 G) c5 {; j6 _9 z{& o v* i5 L5 M" Q
$ _- _- Y5 B/ X; k9 X; K
int i,j,k;
' }( y& V a+ L7 |, Y/ [ double left[4][4],right[4][4];
, l |* ~. k9 h' M: j- Q; K2 M9 `/ L, z
Project_Matrix_Copy(left_mtx,left);
+ F2 N) Z1 o9 P/ N5 x0 J4 k4 f7 v Project_Matrix_Copy(right_mtx,right);
4 h$ C) k: Q$ [: H" n# o( P for(i=0;i<4;i++)
7 @, r) k$ {6 b+ k; J for(j=0;j<4;j++)" H2 G) A# U' h; b m
{
7 k1 _7 e; k% s, d get_mtx[i][j]=0.0;0 s5 x1 M2 T) c$ n) ^
for(k=0;k<4;k++)$ \) i% h6 P& E9 E3 U7 y
get_mtx[i][j]+=left[i][k]*right[k][j];
4 b0 J) r; k9 J }0 O1 J/ V6 S9 U; F9 M( D
}
5 U, z+ S; U3 u" q# s5 U* Z//转置矩阵- E5 \ W+ Q. y
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4]), K. Z* j# Q3 c$ L Z! i
{- m( y! b, ~5 q. p& B7 q5 H. H+ _
int i,j;
# C6 u( i! W) L4 S" u+ `# N for(i=0;i<4;i++)
" X0 A" H; D M" ] {6 }" I; b. {* f( g3 R5 N
for(j=0;j<4;j++)+ g }( v5 ]3 o. M
{4 s( f$ y* Y0 X; F2 O' s
transpose_mtx[i][j]=mtx[j][i];+ G3 Y1 f& D6 n' Y6 v
}
9 {4 x1 u3 h; ]4 [ }( n. k" Z8 p- H
}; d2 K$ U/ a6 A3 i7 ~
//从11元组获取变换矩阵
( d- R; Y! s) S2 Q4 m/ Lvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])$ o- O1 v# k7 o8 W# m
{
3 H" y/ J0 r! c. P4 Z
5 l, J2 q& ]. c' t //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
0 f1 h, _0 C- @ int i,j;
5 G1 H8 A' a$ L7 _+ {3 N for(i=0;i<4;i++)
" a6 ]9 w8 H/ @) c, Z for(j=0;j<4;j++)9 m% K! L, _1 W3 n% t
if(i==j)- U7 O% q/ I C' W+ h) I# h5 n
pos[i][j]=1.0;5 {! x* I. _+ \5 `
else. X/ G* k9 p6 R7 s, }1 e8 y& K
pos[i][j]=0.0;
* k1 d( J/ ]. N U3 V0 K pos[3][0]+=translation[0];. O5 J5 [1 |, o. b
pos[3][1]+=translation[1];3 P; P: k9 u, Z2 f4 m7 j
pos[3][2]+=translation[2];
. {! n4 b/ L: k. E/ `. r}
6 f a3 I: Q* D! N8 j1 s. Q: t//向量缩放
" n( i$ v& R: C1 A3 r& P3 [void Project_Vector_Scale(double a[3],double scale,double b[3])
' \7 p( ~- |9 r. p u{8 ?4 y' n. E6 A& S- _
b[0]=a[0]*scale;
$ p5 R1 u/ T' @3 \0 g9 V b[1]=a[1]*scale;0 a. c6 M$ v/ y
b[2]=a[2]*scale;
- K5 C% T( P- I6 c}
$ Y% d" s0 ^8 q/ _9 {. ~3 T0 j8 B) R% `) o
|
|