|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! X& V) R2 }9 A% \4 E% B
) l4 V6 t8 |- f6 I- @* n* G! y3 F% r% U7 Z3 c2 w( }
#include <math.h> 1 u0 g9 i4 F8 X0 I
//矩阵复制
4 Y% G9 j; Q: j0 }7 Evoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])# Q$ T8 |2 u' W8 |+ G! f
{0 a1 x) _ l& g/ b! N) D
int i,j;
% Y6 e/ u( ?' k+ q' ~
$ r9 w) }& \5 Q r% J; ] for(i=0;i<4;i++)# _$ Z" Q4 l$ t- U$ U M: U& m9 k
for(j=0;j<4;j++)
( m v9 V0 v5 A0 h2 r# D to_mtx[i][j]=from_mtx[i][j];
$ p* }6 b1 W. Z! S. ?% Q4 w/ x}
) g; G# W( r( Y//矩阵初始化 C8 q+ {# E( ^+ o; j; F) E! r$ T
void Project_Matrix_Identity(double mtx[4][4])
( E0 R5 [: e% w6 C3 W0 `. {- N' U{7 x) K/ H0 w; ~: z
int i,j;
{% h) ]- n; `! d- ]' X' I ( s- ]7 V6 S1 R- _9 C
for(i=0;i<4;i++)
N! w9 Q( ]8 e5 O& m1 p+ @ for(j=0;j<4;j++)4 U& i# c- A% ^- c. |5 G8 \
if(i==j)
/ I. j1 E, o6 Z9 @& E# I6 d mtx[i][j]=1.0;/ z$ U; X* D) H6 {$ I- ^
else
% p' s8 P( h$ j6 ? mtx[i][j]=0.0;( c; V% c, m$ G1 S; h& ~
}
p U2 n. y( Q% L//矩阵相乘1 w- E) k% e$ ^
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
! ^3 V& x1 A9 _4 x1 |# h+ B{! O' ^# Y/ G! j9 l
% \. ^$ @ v1 \' B" s- q int i,j,k;$ ~4 _9 K- ]$ i2 f; T7 h
double left[4][4],right[4][4];
( U6 m% N, t8 t! R
" \4 n. ]$ i* {: C Project_Matrix_Copy(left_mtx,left);, @6 O( W* d- g/ j
Project_Matrix_Copy(right_mtx,right);
. z5 F9 ], V5 r& Y( p for(i=0;i<4;i++). s% ]1 C9 s( w% N
for(j=0;j<4;j++)
4 \% V; B$ W. ? {
" J }6 ]3 D4 J' K7 |% X get_mtx[i][j]=0.0;5 w. E) L% D$ g" h8 M+ U
for(k=0;k<4;k++)
+ T7 T- z; D2 y" k% k" h7 a' M* { get_mtx[i][j]+=left[i][k]*right[k][j];
# n5 i' C. d7 c8 k: c }) ^* C2 q$ j: m9 ]) E1 ?
}
9 @3 U U- G7 q//转置矩阵5 R5 ?* V% t3 D
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])( D. ?6 r3 }3 b+ {
{1 N) u3 Z! G+ G' c6 ^( V6 G, a0 ~# A
int i,j;1 Y J1 F3 P5 _. o6 T. r* K# {
for(i=0;i<4;i++)$ i- b' W8 H) p5 ?8 G* E9 W0 ?
{) p: g2 h' k( r' l: s
for(j=0;j<4;j++)
! A" q, ^3 C! i+ H; V {4 W. O, u5 |8 \; F4 ?1 `, z a" n
transpose_mtx[i][j]=mtx[j][i];
& f; J: L' q8 K }
/ ?/ u2 b) u6 n; n7 ^ }
3 W' n& p/ l8 T# b) e2 D1 b* W}5 `! _2 y) i3 G, g. n* j
//从11元组获取变换矩阵
8 w% L6 b4 }, R2 Y7 avoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
1 k, G+ F4 \" \& s' p1 V" l& R5 ~{
6 s$ Y0 v4 K2 ~* n" Y( r7 x: \; T+ S8 z
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
, n+ W7 S' x) ], S int i,j;$ z; \" E6 L4 ~
for(i=0;i<4;i++)
+ h R* f& t1 I( y% t, k for(j=0;j<4;j++)7 \. f% A( C: N* `7 S+ C+ v4 ?
if(i==j)
1 o. ~- _) K! Y1 `' v) t w y pos[i][j]=1.0;
c$ Y: O+ r4 \. l( D( x4 i/ [+ F# t else( N/ U+ ^3 A. n3 k' V6 \. T
pos[i][j]=0.0;( h5 {6 ~0 @. \1 l; S1 G2 u+ {8 X
pos[3][0]+=translation[0];8 r8 D8 q- _/ K- a: `: X
pos[3][1]+=translation[1];" ^! r; `4 O$ ?# y% X5 B5 ?
pos[3][2]+=translation[2];$ b- S9 z- k/ ~- T
}
9 d8 Q! I/ Y* r1 j: Y$ R//向量缩放8 ?: U( R2 Y: F" Y( ^) v
void Project_Vector_Scale(double a[3],double scale,double b[3])( p, p0 r9 q4 {3 F8 _
{9 g1 Y1 e* J* G8 a
b[0]=a[0]*scale;
! v. ]- F' k4 W8 S0 B. }6 @ b[1]=a[1]*scale;5 j4 K) i( S! D
b[2]=a[2]*scale;) z( `, {: L, `- R
}
7 f3 T1 [; X6 P" {* ?1 a' t1 Z0 z0 G4 z# o
|
|