|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
I4 H7 B) }8 Q4 r; d g5 k. r" u! i3 Z
' P* I5 u) U U. C1 D+ n#include <math.h>
, Q. W, J/ A2 P1 P/ M; _9 X8 x//矩阵复制
" a6 x4 `+ X; D* B6 gvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
H4 ^$ i$ L6 W$ H8 q q{
9 c7 R; ?5 ]2 H5 ]7 P+ m int i,j;
$ T/ M* H3 E6 L0 z* Q+ C d# I5 O3 g8 A( H7 j
for(i=0;i<4;i++), I$ e2 Z* A# [5 p' P6 g
for(j=0;j<4;j++)5 e+ X, a; U1 C
to_mtx[i][j]=from_mtx[i][j];
! ~% C3 m# }/ c r6 g5 T5 {}
4 \! m0 r: K, q ~1 l8 W6 p//矩阵初始化
/ i0 U) a0 g/ X+ Z" U/ x$ Z; a( wvoid Project_Matrix_Identity(double mtx[4][4])% S# s5 G+ I6 {, R' H
{" `( U. t' v& J
int i,j;
0 K5 H+ m* A+ H) u2 o' y' z
8 e1 u+ i2 L' U1 [' | for(i=0;i<4;i++)9 U3 A3 m* K+ q1 t6 @8 u
for(j=0;j<4;j++)
. e! ]) `2 s# W4 q if(i==j)* h2 Y" S: Z' N, ]8 k) n. D' V( s3 x
mtx[i][j]=1.0;# L/ O2 T* V8 C
else
4 b3 Z( s: p5 l+ M2 e mtx[i][j]=0.0;$ f: W; i7 z' h. u
}
; O* m2 i, y, i//矩阵相乘
! [2 p7 P3 i# m% tvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
l3 S5 d; V3 W7 C2 \{$ s6 Z1 C8 c. H
3 G) W% L- }2 s; z F int i,j,k;9 `. g- o6 c/ g: z
double left[4][4],right[4][4];$ B5 o, @3 e. y) a/ f9 ?7 ]% N1 E
+ \: q5 Q$ ?3 F Project_Matrix_Copy(left_mtx,left);8 T ?& `+ X$ P8 s/ ~2 ?
Project_Matrix_Copy(right_mtx,right);+ \+ b2 M; P' N: T; q0 S
for(i=0;i<4;i++)4 e$ u6 q. ^, p! `
for(j=0;j<4;j++)
- I0 G: N0 m- U1 T: {. r; ? {
! f0 i; L% n4 y. \+ S9 j get_mtx[i][j]=0.0;
5 x1 o% N# T; y' R# O9 V for(k=0;k<4;k++)2 v/ ^# A J( z3 R2 l
get_mtx[i][j]+=left[i][k]*right[k][j];+ J5 e# {% i# B/ u
}
. c( k: g+ @2 E+ p- Q}8 [/ w1 m) V4 R" l
//转置矩阵
4 k3 i+ u4 G2 t, uvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])* l0 j! ~" {: n, ]
{
" ~' r$ u; H |$ E! l int i,j;
2 l/ @3 c9 J/ L5 `2 | for(i=0;i<4;i++)( d; z$ t' K9 O: L& P
{1 H8 B; C2 ^. V# l
for(j=0;j<4;j++)# E: P/ R; g. ]. G
{
. `' y3 L U S7 }! z7 T transpose_mtx[i][j]=mtx[j][i];3 K( k \# Z3 _
}6 ~$ i) o5 X$ ]8 Q* `5 P
}% r( p5 I/ Q$ v
}( @5 Z; c0 ^1 l
//从11元组获取变换矩阵! }, D& p4 p3 t. H* X
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])* D+ ~ C) m! K: b5 H; ~7 d
{2 g* _0 t6 i* P! `/ I
; F) s1 ^; r% [- k# x( q6 w //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
6 U5 }' M; E9 s/ k' @% x int i,j;
. {8 O5 U) W8 t for(i=0;i<4;i++)) C0 I4 f. n! R# C& A/ ?% \' G
for(j=0;j<4;j++)" k" B: P0 w. b$ l$ n* o/ A$ a
if(i==j)
h& h% c6 J& D# ~+ x pos[i][j]=1.0;# k+ h4 | A: e# G$ u
else8 ]9 H+ A0 {) E" ~
pos[i][j]=0.0;
* S2 W0 j4 m u4 S0 E6 H pos[3][0]+=translation[0];- O. {3 l: |0 v8 P7 R6 O% A" A
pos[3][1]+=translation[1];* y4 ? c; n5 J. c
pos[3][2]+=translation[2];7 | g% w) O6 ]2 I/ e! h% B8 u
}
& r t- d- G: p9 Y//向量缩放
- f X; `- T/ m# g7 ?2 x& yvoid Project_Vector_Scale(double a[3],double scale,double b[3])
8 y* e& c5 Z" J/ U{: t. x$ A9 b7 K7 i1 ?
b[0]=a[0]*scale;/ g0 g( t2 L4 h; U
b[1]=a[1]*scale;5 L+ m i3 z, J; A+ Q4 D
b[2]=a[2]*scale;# l. s J" x! O- A0 x; o
}5 ?; N6 F& y! ^ P+ f
( T5 q% c% d8 C0 z |
|