|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 Q# u& d* }0 s3 `5 C- [9 r
/ e' `# ]6 [4 ]9 `. t; K$ [4 D0 ~4 o/ L
#include <math.h>
, S& k* m, n# Q/ ~* ~" h# L//矩阵复制$ t+ C, E& r& s
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
, T3 P9 J$ O# }9 t" ]" I: c{
1 {+ s/ l; J! R* D! {, @ N9 r int i,j;$ Z6 L+ J' L" l: {
9 {- F' g2 F" _4 c" _' H for(i=0;i<4;i++)
4 d1 |* o& Y8 v* _ for(j=0;j<4;j++)) Y# Q1 M$ A3 c( E3 z/ O8 D* \
to_mtx[i][j]=from_mtx[i][j];
7 v; x9 O# S; h; A}
/ h# a/ ?/ c7 n/ a0 @+ e//矩阵初始化
9 x# U: H7 N* W x) M1 p9 k+ Qvoid Project_Matrix_Identity(double mtx[4][4])
1 x' o1 ^9 Z; o7 z# c3 `4 N3 |{
; k9 N% m8 a4 R: R9 p; T int i,j;6 f$ Q! f" N8 J$ x% a, H* B' ^
6 ?. k! l, }8 t, ^( G2 Q5 f
for(i=0;i<4;i++)
1 y) N7 k9 N# u for(j=0;j<4;j++)
2 R" y7 q! \8 j- I if(i==j)
7 g# f' F7 c' T! ?: u: {1 x! [ mtx[i][j]=1.0;
- A5 R- t W* Y% T6 S else4 n1 i& m, [0 E% v) h# |" Y9 u6 `( U
mtx[i][j]=0.0;
3 D9 c4 I: f4 D6 g5 F) x6 S}
) t. A! K7 a0 e# O9 t1 \9 D3 h//矩阵相乘8 U3 I: T! o' ?7 r; ]/ b* X
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
! U8 r, d$ N9 d3 j, m{; P5 R+ x- z" U0 ?2 X
0 H. [1 `& i* v: E3 P/ s( F int i,j,k;! R4 t$ ?, w0 v9 z% M6 L
double left[4][4],right[4][4];
1 f( P: t8 i1 L7 A$ x; N% d
! T g" P: A& q% F# o Project_Matrix_Copy(left_mtx,left);
# y! w7 S- Z0 \/ \& |$ Z; G* S Project_Matrix_Copy(right_mtx,right);
1 a! x4 m; q! f for(i=0;i<4;i++)
* _% J' P, A4 r- { for(j=0;j<4;j++)' U& T& t6 A9 R/ h1 |
{, {% w' ^& V6 w6 A. q' f+ h. [) X
get_mtx[i][j]=0.0;: h- l. i% k* P7 q" a8 i
for(k=0;k<4;k++)! g) X6 |6 r) [. j1 O. }
get_mtx[i][j]+=left[i][k]*right[k][j];6 S& f9 Z2 |2 j1 p
}
" o9 Z( }3 n" I0 `/ }}1 [/ @" d& l, ^0 p& z( T/ R
//转置矩阵* }9 b) H) v& @4 m Z1 a
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
" x7 t. }: R# H) V" h$ F/ t: j{$ w" B# a, r2 h6 C" C3 c, I
int i,j;
2 p7 z$ V" D) ]5 o, l for(i=0;i<4;i++)
Q; G. F8 M- N4 v' W3 {6 \ {% b8 s6 t/ @. k# k r3 G
for(j=0;j<4;j++)
- J1 i0 J9 B2 c {
( {5 h; `4 L- @ transpose_mtx[i][j]=mtx[j][i];8 f3 y0 g3 ~: A# y4 M
}
& _* V% l* d' U9 Z# | }% q$ J. z- E" \+ q8 G1 C0 D8 i! G9 e
}" X3 |3 \" C5 C7 Y
//从11元组获取变换矩阵& W, g. t8 b9 p0 q( H& n
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
6 t( P4 q7 z1 \: z+ G; I( X& c1 m{3 l! m7 X. C% k2 `% h% A3 |
# C% T# x* Q$ f% J5 E; R
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);. F/ m5 J/ L, A& B4 M c# t5 {0 Z1 Z. a1 a
int i,j;% {3 m; _& i8 `; v
for(i=0;i<4;i++)
* Z# r4 H! S9 i- m7 j( M, G' W for(j=0;j<4;j++)
# }! p- Z2 p0 j( x if(i==j)) C1 v2 f! i s6 [2 G1 X) l, B0 B! q
pos[i][j]=1.0;& k/ u' G0 Q; Q5 E. n
else: P0 Q0 Z2 B4 T5 F! l9 g0 m
pos[i][j]=0.0;% s: F1 y* Q/ d9 |, f0 R H( B
pos[3][0]+=translation[0];& Q1 s- A/ X( Z d% f
pos[3][1]+=translation[1];
% q6 ]3 h# D. M$ m0 C- w pos[3][2]+=translation[2];7 U& r5 O" j! D8 F+ k4 f! Z! p/ A7 m. @
}8 F. v: M4 T' \; v& y* o2 q' E
//向量缩放
+ o# k7 f4 x2 Y$ S- P5 qvoid Project_Vector_Scale(double a[3],double scale,double b[3])- x( }0 ]% U) k& V+ U. f
{
6 A3 G+ z2 H0 g( Y: ? b[0]=a[0]*scale;
2 a* S/ q. H! O2 W' n b[1]=a[1]*scale;7 h# R. @! m: v9 x) k4 L( \
b[2]=a[2]*scale;
! T: y* ?5 }9 z1 F/ ?) I}9 y1 S; j2 f/ |0 t7 U; _
7 G1 z" R5 Z9 \: Q8 _ |
|