|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
4 u. }( J' N7 z* \
; H7 I( y9 K. Y O" L. |$ w
) ?* \' a+ V( ?* U+ V0 j7 h9 j#include <math.h> % R- z7 ?0 O3 E2 ]( Y- R
//矩阵复制: A) F. L& ?! n' m( B
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])- M! s. L! u/ U8 a
{9 q' O8 |/ K- }% E9 D8 F' o' P
int i,j;
0 X8 H* l1 W9 J- _& s3 s+ I1 [$ F% B- o. [
for(i=0;i<4;i++)
' D2 r; l, o. P9 ^1 Y" K/ y for(j=0;j<4;j++)
) T5 v: \9 t" t to_mtx[i][j]=from_mtx[i][j];
- H- N5 [, ^6 i$ c}
, A+ `2 F, R D* u# f1 b: h: V//矩阵初始化
! m; `0 V# z" F% l) [7 S7 Y: c. bvoid Project_Matrix_Identity(double mtx[4][4]); f. C1 |% q' R& @6 a B9 e. N
{
8 b. ]! P( p/ ]8 T+ r8 ^" w- B5 ?0 ~ int i,j;# T; Q. }4 V, m3 s- C6 k' K
0 E! m7 _% E0 f- r/ n- y$ k for(i=0;i<4;i++)
4 c, U+ v3 W% N+ h' {6 s for(j=0;j<4;j++)
3 X- a: a$ G1 ~& [7 G0 ^5 D if(i==j)
0 ~; @- n" I2 ], {" C mtx[i][j]=1.0;
3 J8 c* H1 @" @ B) Q else! ~! W% x# i1 ~, h# d ~
mtx[i][j]=0.0;1 M" m8 W% T- y) [: f
}+ c+ |+ R; @( X
//矩阵相乘
( c" z5 k, n: u; _% q7 yvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])# Q' e! y5 r$ F' g7 M$ h
{
( B. r3 m, V+ i. y0 S' {; f
5 a/ P: [, o0 ^+ b int i,j,k;
E4 P% x- d! i! Z, q double left[4][4],right[4][4];( ~+ V7 \1 u w9 ~$ p& ^
. g/ ~; B( m7 M- ` Project_Matrix_Copy(left_mtx,left);
% l9 h1 A+ F$ k. q% P6 s; Q Project_Matrix_Copy(right_mtx,right);
4 c& \& T) M, @# p9 f" Z for(i=0;i<4;i++); V7 {% y" L2 e/ D9 J Z
for(j=0;j<4;j++): f. g4 E: j$ Y$ D# F, [7 k
{
5 K6 a6 G' N. g& V! i get_mtx[i][j]=0.0;: @: V! `9 f0 P$ ^" f1 L
for(k=0;k<4;k++)
. u+ W H: W# N" z( G$ e& L get_mtx[i][j]+=left[i][k]*right[k][j];
4 x" J6 _, b5 Q# q4 C# } }
- M' n$ w3 v2 L* _) S# h}
1 O4 Y9 b$ w/ v, t' Z0 n//转置矩阵4 P1 ]$ @) O% ^+ H$ _3 j
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4]) t9 v/ }4 b9 \" B* V' i( T
{
; m. C& x3 ^6 Q int i,j;+ ?3 a- I. L) O8 d% r2 X" @6 c
for(i=0;i<4;i++), V6 X5 V' Q) j2 @+ q/ q, `1 k* J
{ s6 j3 [! f3 E1 \, S8 z' L
for(j=0;j<4;j++)/ Z4 p3 Z6 G! l* F
{9 w1 M9 x# x- v2 K
transpose_mtx[i][j]=mtx[j][i];
! f( `' u) C& U9 O }
) x3 R4 x# _: s5 Y9 l } a( }' {' y) `/ n% h
}
( ?; b: y) \) v3 m; u* {5 W//从11元组获取变换矩阵
" m$ b! l: S8 i* `$ E Mvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
2 Z- K/ q; R, j+ I# S4 D{
; A! i$ L6 I- H, Z8 G- d# a, W
2 h7 l6 l/ ~5 T( K% I# ^6 \# k$ T& C U //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
. u# R$ d" w- W C int i,j;' U) {2 ?' s) c8 l$ m. I
for(i=0;i<4;i++)9 ^! p0 O) G5 d4 I" h
for(j=0;j<4;j++)# V; o9 H2 N( S4 m9 n0 x2 r, Q( c
if(i==j)
# Y# n$ M' [. ]2 I4 Z9 C pos[i][j]=1.0;/ n8 c- E& h% Y6 Q3 H3 v. D1 G h d
else
" ?& q( q, F7 \. @: ~: ^ pos[i][j]=0.0;
1 t4 e; n7 v( M" z pos[3][0]+=translation[0];9 E3 K% S R8 c( w
pos[3][1]+=translation[1];
" G$ W. s% R! G& U0 [& @( H5 q# x pos[3][2]+=translation[2];6 W( y/ R9 Y t3 J3 T
}
* _ l; T& |' ~4 S! T//向量缩放0 t2 G/ p! f. f& l9 v, A8 b
void Project_Vector_Scale(double a[3],double scale,double b[3])/ Q& s" j: r, ?4 [0 v
{& J# g" G; A' z: A! S
b[0]=a[0]*scale; N+ j( ]/ t7 ~ E2 ?" C
b[1]=a[1]*scale;# Q' n" W D7 P" x
b[2]=a[2]*scale;
( _ a( u0 ~/ q, }0 ^}. Y. Y& W% D2 [! d8 h
! T" {" O: L! E |
|