|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 ]+ I3 j- M5 Y9 {7 T7 i+ o( U' o- O G( n: c
! o/ s% K6 d) Q; q1 ]#include <math.h>
, c% i4 V2 g* k9 ]//矩阵复制( P1 [2 n. x/ Q4 C7 M* ]' w
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4]): t, _- H5 q7 c6 ?7 w7 d" r: t
{
6 j3 p: D3 k/ `' @ a int i,j;
5 p7 q3 u4 E/ r5 b+ ]5 Q% |; x0 z
) e" f# y, j" U6 C for(i=0;i<4;i++)
9 d) I+ c v( r8 { for(j=0;j<4;j++)
) j% {, k: i9 d' {" a7 M' R. u2 j. J to_mtx[i][j]=from_mtx[i][j];( b# O; C8 Z3 i+ A' \1 C0 ?! l( c
}
, m4 \' x- G& J//矩阵初始化- @6 R1 X+ l. C/ r5 Y1 S5 U
void Project_Matrix_Identity(double mtx[4][4])
2 e7 U5 n: i! w( ~& u) u F{
/ o8 r0 N. V% b9 Y/ G% s) ^, z- y int i,j;
* R8 [/ Z/ g: B( i) q- P) m z2 i ( f, y% U, s7 s/ D1 r& O' p& f
for(i=0;i<4;i++)* R) i. l# {) d
for(j=0;j<4;j++) x9 y; q i1 X& w! l
if(i==j)
! W& l+ @- B9 S* @! h& M mtx[i][j]=1.0;
/ D G" W3 w. v: j( K8 L- T f) D else
7 W: q! W5 K& O8 n mtx[i][j]=0.0;) y7 M, h, J7 g I
}
# x1 ~/ E b3 ~+ j' F//矩阵相乘1 x( ?9 {% i {: Q& m- {& i0 g
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
* w3 c$ ^% i$ y0 z{
' \( s6 Q2 v/ ?" l/ Q1 G0 `
" [& K+ [2 _0 j: @6 Z2 }4 h int i,j,k;7 F) I9 f% N& H! R) O9 a* Q9 n
double left[4][4],right[4][4];4 P( I: [, {( Z3 j% ?4 V
+ T/ v% ~: I% \! p+ W Project_Matrix_Copy(left_mtx,left);
: x+ o2 f; e& K0 I, H$ D: ` Project_Matrix_Copy(right_mtx,right);6 y4 [( u& |8 F }$ u# {) k
for(i=0;i<4;i++)
) S. P3 i0 s; R3 {1 Q1 s% R for(j=0;j<4;j++)& J _9 z* i6 d6 G
{; \4 n) P, B5 V7 M# y; P
get_mtx[i][j]=0.0;
$ \4 m7 Y0 N# v- ^$ I for(k=0;k<4;k++)
! M, o. X& |$ Q get_mtx[i][j]+=left[i][k]*right[k][j];
) x$ S* {+ Y8 B; y6 F }
; {3 i* @ R* [! s, X% H% q}
+ r) a5 d; e% p( l- R' t//转置矩阵% L, s' T* q; b. @: |9 X" z2 n
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
! n" N4 s0 P6 ~. a" M{3 Z- S0 `: x# l$ b5 A
int i,j;
- a3 p3 P6 `: O for(i=0;i<4;i++)
0 J1 W; [7 D @" b' s# b, H {
3 B4 k4 S! X% ?3 s$ Z2 g for(j=0;j<4;j++): v; P( @: g' I, _" V
{2 c8 f# ~- n5 C; `9 j
transpose_mtx[i][j]=mtx[j][i];
- B a' [8 e, x: Z% H, y }* E7 Y }
, S3 V2 b( f6 k$ @. }6 A }1 z7 k( Z i. _( @7 Y3 S2 `
}) Y, ?, Q9 A! S8 I
//从11元组获取变换矩阵
2 W9 N# t& D) |9 Q0 j$ Vvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
" @3 \# k& q1 t4 |0 r3 C2 K' _3 v9 i% J8 M{
+ q) {' Z& o( o* c
& O# r% c, O1 ~ //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
6 r) j! T+ ~- \0 I; r/ p8 H. q int i,j;. a0 e3 Y" ?& P: a0 l
for(i=0;i<4;i++)6 L+ ?7 y! E, O2 [
for(j=0;j<4;j++)
/ o/ [ F. ]( v& Y: y: m if(i==j)/ p) J2 |) b6 G1 W* _5 Q. I+ e- v
pos[i][j]=1.0;
- U8 j' G) J6 |/ s" t. i: p else& Q" L7 R% }$ R
pos[i][j]=0.0;5 Z/ L8 k4 p2 ^ j s; j
pos[3][0]+=translation[0];
* k+ C4 K; A' ^ pos[3][1]+=translation[1];
# g7 h% v; }' O1 T4 u pos[3][2]+=translation[2];4 Y' L1 |" [+ N- Z# f7 D7 [$ n
}2 e: |; D3 A% z4 `) d
//向量缩放8 d7 H) E( m3 F/ J
void Project_Vector_Scale(double a[3],double scale,double b[3])
* M. s9 |1 V9 h @- {{% W O; [- a z- Z( O z$ _( ?
b[0]=a[0]*scale;7 e1 R7 j0 \$ f6 v. i$ g/ Z2 F
b[1]=a[1]*scale;
7 N& M. _- k) S L b[2]=a[2]*scale;
# S. |9 s; N" R7 h t}; b8 E! K5 M- s( A; L2 ~7 W
+ J9 o5 m4 q" c1 f4 ^ h |
|