|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 }6 n0 P9 G3 Q" N5 f7 c$ e+ g8 k5 Y6 _- y0 i* F( c
9 {% U" U( M8 J; [
#include <math.h>
" {5 F, w% p( y4 `//矩阵复制
$ r) v" U3 a" S) h; Qvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
$ r* h7 A- }$ ?2 s6 A1 ^{7 |9 ^) r1 J* c$ r* s. K& U6 v
int i,j;
* `8 t1 m# a2 T3 O% I: c! x7 y: N; Q% q6 [
for(i=0;i<4;i++)4 Z9 T ^* o* B5 B
for(j=0;j<4;j++)
: V! s# `/ q' T7 }" R" }$ g to_mtx[i][j]=from_mtx[i][j];+ [: N6 n8 Z& V* I0 ?
}
' f$ W; C! |" s//矩阵初始化, d& X3 `/ O0 n4 x0 ~
void Project_Matrix_Identity(double mtx[4][4])
2 q3 }3 X" J B8 q" s: E; N" P{% V, g- @- \4 k' ?
int i,j;$ l: h# e# F# T3 ]2 i
/ C- x* f7 e' o- J2 Q6 U! m2 [
for(i=0;i<4;i++)
2 r6 J9 u' u* c for(j=0;j<4;j++)
+ P S) D0 t+ h$ b) g6 q; _ if(i==j)
* l2 @4 f, n; M2 s' q2 n mtx[i][j]=1.0;
" w% Y- z | f) f+ Z( f else3 F& U+ r8 m7 _! U3 j0 E
mtx[i][j]=0.0;( a& X/ {" H; p: q5 \0 M5 k
}- l$ T" i; q/ o8 v3 l- Q
//矩阵相乘
) v: x( f+ E8 X" K6 lvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
$ h- b1 g+ P, |/ X# q+ m3 m3 {% O{' N, _* {& K! C- C
' ^0 u% [! Y ?- q. H8 o
int i,j,k;4 \4 Y u3 J( t
double left[4][4],right[4][4];
6 N" G' L; q8 `- R
2 v9 g: t- r4 g Project_Matrix_Copy(left_mtx,left);
* a& h8 q Z; x. n1 U. P/ h Project_Matrix_Copy(right_mtx,right);
: N) O! e* S3 R6 V. g( l for(i=0;i<4;i++)5 T2 q" \) T& c+ {7 [2 | L
for(j=0;j<4;j++)
+ H- z; p) p# A' t {+ w5 e% Z. z) c2 q" v, @
get_mtx[i][j]=0.0;- U3 M' G" }2 D) a [* H
for(k=0;k<4;k++)/ ] A7 Q' k7 s' ~, s
get_mtx[i][j]+=left[i][k]*right[k][j];
. ?2 U) Z5 A" l+ r9 D0 V2 y ~ }6 y' c0 E$ A( C$ \4 d3 c
}
* H% K. m! D _. c7 B, Q//转置矩阵
2 a% w: E% {9 xvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
0 ~; |( S( j0 ]{
% z7 _! i% I& K: l3 Q: o' o5 ^ int i,j;; b9 p' L4 @5 j( K5 e7 F% d9 w( S
for(i=0;i<4;i++)# J7 q; ]% M' l/ |. r
{0 ^: J* s: @7 x7 @: E4 z
for(j=0;j<4;j++)
7 W4 d. h4 z+ ?- y# Y {* Y) p( n9 o9 P1 g4 g
transpose_mtx[i][j]=mtx[j][i];
# [. P6 b# I7 I4 {" b! c, X }6 j5 @2 p, p0 `) _
}
0 o) w6 S( h. G+ @}3 [/ c- |0 b6 j; A9 b
//从11元组获取变换矩阵" B7 e% l# E, o! ?
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
) j4 T# {" ^8 I. E6 L) g# Z; E9 u{4 i4 ?* H6 [1 o) Y7 {
& B8 h( `( f& p* y //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
; S* n ~: x# R9 c4 r int i,j;
/ @! c6 T" ~" Z* ^" T Q for(i=0;i<4;i++)) x* O- b' U) ~
for(j=0;j<4;j++)
' e3 Q* }' O, J9 c; W! ~ if(i==j). e6 |- r' m k0 e: q* f
pos[i][j]=1.0; R, K5 e. _" e- a
else- n1 s0 Q% L8 e+ @% s& ]- A
pos[i][j]=0.0;
- N5 X. m r7 J* D/ W* J0 @1 Z pos[3][0]+=translation[0];
' t$ [! E. `* A/ s pos[3][1]+=translation[1];- Y# O7 G( ]/ Z4 C+ {( p
pos[3][2]+=translation[2];8 z- U( N8 O7 _
}4 o) S0 N; }$ {$ _( E, Q! C3 ~
//向量缩放
! s0 {+ P4 A2 l% d1 q( d5 L" i0 ?void Project_Vector_Scale(double a[3],double scale,double b[3])
) C/ v/ ?# ~; I. U{8 c# |3 _- x9 e, S4 M) B1 }5 [4 N
b[0]=a[0]*scale;
6 h, _7 i- ~' T8 p* I7 i4 x; a b[1]=a[1]*scale;
! g$ P4 w7 k! N8 j0 K% {8 j% E) p0 O b[2]=a[2]*scale;
. D) R/ l$ D% E}" z( M3 U6 \. k+ \1 R$ s# K+ ?
$ J% H. \$ _+ e" W' }; W
|
|