|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! I6 U4 k# x7 a9 ~1 p2 K
) C- g8 \7 k8 l$ v4 _; q; e
% Z2 K ?, i9 x4 e0 `#include <math.h>
' v4 e6 v+ I0 J& s//矩阵复制
8 _2 V3 Y4 Z; {" pvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
& ?9 m% j$ b, @. f5 G{
# a* a- D/ f& d3 U int i,j;
9 c; {9 G1 t+ z/ u. a; e5 ~/ e. S
3 K, f* M1 c$ [# C" w0 `- K for(i=0;i<4;i++)
2 I" }0 W9 C8 p* E: W S for(j=0;j<4;j++)
7 e' L2 x' }5 \) D1 t to_mtx[i][j]=from_mtx[i][j];+ D. n3 u9 s( v5 s9 X: |9 o" W" }
}4 {: v) H$ L3 O
//矩阵初始化
) S9 W* \. H5 evoid Project_Matrix_Identity(double mtx[4][4])
+ D" Z0 K3 \1 m9 ?6 E8 t{
9 C& |( @4 I# M% k5 W9 Y1 v int i,j;
% @, y v8 g1 i) S1 X& i
# ?7 E0 W7 \& p# L6 C3 h# ^ for(i=0;i<4;i++)
5 W: U, L" L& B+ p) T/ _0 w# {$ l6 M for(j=0;j<4;j++)
4 I" ~2 Q8 D7 O+ Q7 o6 T w+ q$ ^ if(i==j)3 M3 R/ d! C ?% B7 R% }
mtx[i][j]=1.0;1 ]+ Y; |% G a
else. r) K7 Q& l- i
mtx[i][j]=0.0;
; k8 H6 Y( I p6 T; w$ ]}
' s8 O" w# F- _! L& E% g//矩阵相乘
6 f8 A9 z- G3 q' ~3 ^# svoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
& f2 O) O+ X- G5 V; Y2 u3 w{, I1 r% G& g$ ]9 a7 N
5 |0 J' c: q2 O# \
int i,j,k;/ j) n. N6 l; T. `$ R/ f. @: n
double left[4][4],right[4][4];
& Z i5 d z7 _& D7 c
8 \0 T1 M7 V$ R: g! S+ ~ e2 u! g Project_Matrix_Copy(left_mtx,left);
" y! n4 p* y! \3 [ Project_Matrix_Copy(right_mtx,right);
, l+ m% y1 @& c$ `1 B9 Z for(i=0;i<4;i++)$ v. [# [6 R7 l& e7 D7 U
for(j=0;j<4;j++)
9 M' @6 M. ]: \3 i$ r {
& y# s( g$ U4 g3 X get_mtx[i][j]=0.0;
9 J+ e. z# S- o. I3 Z& f: S" x for(k=0;k<4;k++)- {% |4 k! X9 j! \0 [
get_mtx[i][j]+=left[i][k]*right[k][j];
4 k6 t: l) v; w+ Y' F }1 l* l2 V: p$ }1 `
}9 m: W% f$ }% c/ q
//转置矩阵
4 ~% `/ U1 B# `1 w* j$ x# {6 wvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])% `) [: d0 K/ f
{+ q7 K0 X8 u6 B( K9 N" v
int i,j;
- }+ ~: X, q- `) u3 B for(i=0;i<4;i++)
2 m! ^2 ?5 @% M) E1 E# D { i! q, i- A4 e6 j$ B
for(j=0;j<4;j++)6 \8 F) x# I I9 F; d: T' g
{
6 n1 v9 M5 O6 D' ? transpose_mtx[i][j]=mtx[j][i]; N6 [! q. \ u' u T. u$ N
}
2 n) ~, [' I @% d$ U9 B9 O" q3 E }3 V7 B% F/ t* T8 G5 \" O
}
! ~+ a- o( z# v% \( q/ o7 q$ w//从11元组获取变换矩阵
1 z' R( y o5 j; W/ {void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])" G6 D. D9 V) D# Y% K5 p8 z4 W
{* [7 i& t. V1 ~
' s8 L* @- L* V& ?5 U4 q/ H9 Y
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);, a9 L* R r8 z
int i,j;2 i- F7 T2 b8 b" W8 I! d
for(i=0;i<4;i++), T- ?3 a. R M6 \, d7 v6 `5 R, {
for(j=0;j<4;j++)! u) D% G) R* j; }$ \2 j* W
if(i==j)7 w) n1 J' J8 x
pos[i][j]=1.0;; \3 i" K! L1 [% F
else& \1 M6 g2 W; Y: Q! D
pos[i][j]=0.0;
" K3 R& `# H4 D; w% H4 O pos[3][0]+=translation[0];
% {( o3 Y, R" B& s pos[3][1]+=translation[1];- h/ T/ m2 U$ n C3 P
pos[3][2]+=translation[2];
- U+ X! ^" ` D% Y% G) n}* I1 X6 r! n3 ?. Y. w' T
//向量缩放5 _7 j/ I0 P% X
void Project_Vector_Scale(double a[3],double scale,double b[3])" q4 c# z5 H: a( m2 f
{+ v8 F% i1 U5 X4 H6 X" J$ C, H
b[0]=a[0]*scale;8 {7 _3 ^- D3 x N( f
b[1]=a[1]*scale;+ H% U- b! E% L; I) _) V9 U
b[2]=a[2]*scale;
0 j v; }* O5 L$ j; u6 R0 R: n} X0 G" a# J/ t0 H& E: o0 u
. A) K+ y0 T+ b( m) L; r. _
|
|