|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ Y# c# ?* r# o" W( @8 f
) b2 e7 j6 ]. ?! u# r" v
M0 c5 ?6 ~" o: d( U4 _
#include <math.h> * o; R% t' \2 E4 D# X/ D) w0 k
//矩阵复制
, e) r) Q' Y4 V5 f. ~8 C4 M+ evoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])7 |& Q% B# M2 r7 G; N9 ~/ D
{8 |1 J: c# l9 n0 m
int i,j;
5 @: F5 J. f* I0 a$ v: m4 g8 f. C. D; }4 n$ P
for(i=0;i<4;i++)/ Q1 u/ O8 {& c) L
for(j=0;j<4;j++)
( S; x) I, U1 P& H" w- r to_mtx[i][j]=from_mtx[i][j];2 i- u* t" d |/ ]0 c
}7 k( A9 d! W' g
//矩阵初始化7 l' v1 H) \/ [( w
void Project_Matrix_Identity(double mtx[4][4])3 e4 W4 E! v2 _0 l
{
: r; g; i& ~" a9 m- `# Q int i,j;
& D' Z2 R( |2 _; L
! _7 i! F- F" g* m) l for(i=0;i<4;i++)
% [: ~% D; b" G. Y for(j=0;j<4;j++)6 q! \; q; a) u
if(i==j)
' C9 V9 p6 ^, i$ E% `7 T$ |0 A5 [5 f mtx[i][j]=1.0;
! _) z, Z4 t- i% R! P! a else
* r1 D6 \/ y. l2 K c mtx[i][j]=0.0;. q( u" {0 }: u# ]# w& X
}2 r( j8 J8 E# P, R) T) l3 Y3 Z. M
//矩阵相乘3 q( f/ }. P, H9 k
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])8 C: w/ O m3 k& ~7 v7 w$ ` K6 C
{ G1 `+ e- B/ |9 f# P, V
7 _( O/ e/ g3 h6 l" t0 v7 _! J int i,j,k;- |# C- c) V: n( e% r4 h% u2 s
double left[4][4],right[4][4];/ d' W7 I9 L0 b
, K( c/ H' h8 C7 `- q( e Project_Matrix_Copy(left_mtx,left);
2 S9 N7 U" J+ Q* n Project_Matrix_Copy(right_mtx,right);
, h7 T" I- d" ^( p: v- z4 n( n for(i=0;i<4;i++) O( n( ?# Z6 P9 s/ L7 O
for(j=0;j<4;j++)9 n& j9 `* m1 l
{
/ i: s8 o; [# @2 ]+ s: D# z! w get_mtx[i][j]=0.0;% [) G2 S% i9 n p2 L
for(k=0;k<4;k++)
- x$ e; o( ^& W7 r% l get_mtx[i][j]+=left[i][k]*right[k][j];
4 J, m9 }2 N0 ~2 j, A2 M }
, r3 z2 `3 K- |/ e3 l}
- R- t+ M4 b- @" B8 @0 p) ~//转置矩阵. O" M: ?4 N! R! J7 o8 N
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
8 E3 v% ?% [6 ]% I B% k{
# G8 ?( a$ r- M7 S" r int i,j;
+ f/ I) f9 ^6 d# ~; w for(i=0;i<4;i++)
" E, p! M: k* v( o5 C8 R1 k- L6 q2 a' G" P {
, i0 L* [, W4 F8 A9 [ for(j=0;j<4;j++)' J) p2 O" ? z& g2 V/ ^
{: h1 z/ j5 \# Y* `' F/ n
transpose_mtx[i][j]=mtx[j][i]; l' _4 U2 k& q
}& E, H( B- V; W- _3 P
}
3 b+ z4 {: F, v* a) y2 m4 l3 d2 b! V; ]' T}
. Q* ]# q/ }' k1 w//从11元组获取变换矩阵% Z( [$ @' W* J2 }/ L5 ^: q8 @
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
& h2 I( q6 A2 F3 [& A) }* `; i' v8 J{# d% Q8 r: g4 f0 o. Z0 C2 ~
: o1 k; N' w# }' E //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
% c0 b1 `1 u$ W/ l' Y5 m# f) x9 ` int i,j;1 O1 Y% \$ E% ~% U( c/ x5 N
for(i=0;i<4;i++)+ W6 ]4 O* E0 s: A! o7 }
for(j=0;j<4;j++)+ P9 x+ y1 R& N4 S; h. Q [
if(i==j)/ l; t: A: P6 ~. ^1 g
pos[i][j]=1.0;
* b O1 K+ a1 H/ [8 Z- H else
3 q) J, J) @2 H0 N2 u& k$ y pos[i][j]=0.0;$ O4 [7 k3 j" A/ \; ~1 k, a
pos[3][0]+=translation[0];
4 {, s) Z: k& I. q5 M5 Y- | pos[3][1]+=translation[1];: U1 J( h Z: T, R# T7 J9 ^
pos[3][2]+=translation[2];4 ?# Y2 n$ f. ], d2 c5 l1 [
}- D' \" A# A" M1 S
//向量缩放
4 k7 M2 t3 U! x) Kvoid Project_Vector_Scale(double a[3],double scale,double b[3])4 V. z7 E8 [) D; ^3 R4 c% U! S' T
{" O6 E) E7 Y# S' C& W
b[0]=a[0]*scale;2 J7 M+ @! D& [
b[1]=a[1]*scale;) \& ^* m( K% N2 r
b[2]=a[2]*scale;, m k" ]2 L2 N- }& N
}
4 ?$ n" G& r. ^$ f! i
' k+ i, E% z Z7 z3 W* y |
|