|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ }, i3 g4 h; [% A( M. h1 q; S! Y0 U4 }2 n
, H" w5 m8 v$ F3 U( C' P, ?2 q
#include <math.h> 1 S( x& C5 _" q5 o
//矩阵复制
* h$ U/ T& t: j# f$ Qvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])4 w6 ]5 G" Z+ z9 l- G& C+ e
{
6 @; J; v4 H0 k+ j int i,j;5 I: v# g; I, x0 z8 h$ A5 o
9 _' L+ ~% B( h0 c" T' P5 C4 k for(i=0;i<4;i++)
2 q. r1 b& a0 ^$ m- X0 Y$ O6 P7 e for(j=0;j<4;j++)( S* n% U2 Y* ^" a, }7 f: J
to_mtx[i][j]=from_mtx[i][j];
5 ^0 V& {; u7 r8 D( _5 i# }8 D}3 x9 w- L: ]8 M5 L7 B
//矩阵初始化! x# Q0 T0 @2 C
void Project_Matrix_Identity(double mtx[4][4]), D3 v% l y( Z( f8 {
{
1 w( _; A) r# c. n$ @ int i,j;8 `: R2 _9 j! _
7 m1 D) W. s$ f
for(i=0;i<4;i++)
" \4 f2 P6 q! u9 k; F- } for(j=0;j<4;j++)
1 T6 l+ x% w$ |6 _- _ if(i==j)
4 t" E- T) A4 z) ?/ _& ` mtx[i][j]=1.0;* ?' ]. f( v4 }) r f* }
else) o6 @; S0 T- C' X0 {: ]0 Y0 T
mtx[i][j]=0.0;
6 Q) V1 W/ d7 r! o6 J4 Y% F}/ C! k3 a* b& ^" q5 h" j
//矩阵相乘
# g- c$ s" u& j$ U0 E5 o8 q* T/ Uvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])2 O. L6 q0 z2 g V" T5 u1 R; ~
{' s, r# g+ v% z( y! p9 j) h; Y: P$ G
* T9 Z- Z( ?5 A% i' C
int i,j,k;
: c8 L6 \. c6 i3 L7 w( W/ x double left[4][4],right[4][4];
; @( H9 X. L4 g: k- }" y
% E K6 X: t) n: \! N* `& J- ]$ T Project_Matrix_Copy(left_mtx,left);8 j+ T- }9 K) Q' W6 J( I. i
Project_Matrix_Copy(right_mtx,right);6 t0 o! B! O. X$ X
for(i=0;i<4;i++)/ R2 u' w6 r ]! T1 ^
for(j=0;j<4;j++)* H9 r; j' F/ g% i9 g7 N
{8 P# T( V; d" y8 g
get_mtx[i][j]=0.0;
G+ A7 W. B. Y6 i for(k=0;k<4;k++)
4 b B5 Z6 ^( r get_mtx[i][j]+=left[i][k]*right[k][j];
! C( I1 J0 [6 U, l; o c }( ]# k: P5 a: t: ~2 G, V3 ?
}
' C0 t! t, M5 L. r) q//转置矩阵
, e: |# k4 k2 L; z1 w r Kvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])$ [) }2 w( ?$ Q- C% A. f/ J( @
{3 S3 N5 s t' `! X" E; H$ e# J
int i,j;
, ?" q9 |; _9 V0 j5 F% }" y# O5 l5 d for(i=0;i<4;i++)) Z8 t, r1 m C" ?
{
3 u8 Y) Q9 b0 ]7 N7 Q7 j9 D/ p6 Z: A for(j=0;j<4;j++)
! Y' X8 M$ d, X {
1 N* n1 H( i* m% n7 t transpose_mtx[i][j]=mtx[j][i];
1 f$ x J5 _/ {2 Y+ @ }
- M" n. \4 V; }+ n2 k6 x2 m C8 } }
" r2 g6 D) T1 }}1 x/ ? Y: ^- I# {+ v" \1 d+ {& H6 f
//从11元组获取变换矩阵
0 g% D9 e5 m$ a4 M9 O7 r" ~3 evoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
8 ?8 I7 H6 r' a# k- p0 |& z{
" `$ |4 a( {% m3 s/ _% A; B1 D
`% F# L/ c- V% D2 L4 ^3 U/ b //Project_Matrix_Get_Rotation(rotation,point,angle,pos);2 e6 B+ J( g5 D! ~" q" H2 E
int i,j;$ v3 p: u' I' c0 t9 d0 u
for(i=0;i<4;i++)
. b0 p" o6 K2 b) ? for(j=0;j<4;j++)
# L. X4 O! v9 z r" t if(i==j)$ b4 U3 D. @% S. x/ E' A. d
pos[i][j]=1.0;* l7 D, o0 P6 `+ a9 e
else8 ?8 K. Q/ L% y
pos[i][j]=0.0;
3 C \8 I' a1 I+ U: [ pos[3][0]+=translation[0];( N5 r. F% B% ^. y1 F. t5 A9 z, h
pos[3][1]+=translation[1];4 T: G9 E/ v) E' d: [, a
pos[3][2]+=translation[2];7 X0 ~- K4 h* |
}$ b1 | ?+ }' K6 h# ^* H
//向量缩放
5 X( d0 Y' [. }6 s. A) d- Lvoid Project_Vector_Scale(double a[3],double scale,double b[3])
& H2 c! ~. e2 a. R4 z0 W! i{
0 Z; _# d) R+ l' p- Y b[0]=a[0]*scale;
& V3 s8 {1 P; V# [1 t* C b[1]=a[1]*scale;5 k, l+ ]2 J C* l' _! F) H
b[2]=a[2]*scale;
8 _6 `$ S6 H' B}! t3 G* w8 D; g+ g
( v6 x( r1 O" U) E, a
|
|