|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; B5 }, z4 I7 s7 W( ^* D! I+ d6 @3 Q3 g p4 e8 ^ r# d
5 N3 k+ I6 z. v* y
#include <math.h> 9 J6 y4 f, D% n0 Y
//矩阵复制
- ~# y$ g7 }2 ]. i9 ~9 W: ~. Qvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
# T* e+ Q) s* P{
) P& t% ~! }; j int i,j;
; X5 X6 P' M* B/ p$ y, w+ g" \6 s& R, p$ `, [! R5 T3 J
for(i=0;i<4;i++): P7 G" X5 i. J [$ u7 U' m
for(j=0;j<4;j++)) L. u- a. Y) ]" x& d
to_mtx[i][j]=from_mtx[i][j];' s/ ]& |! N+ F
}2 f9 h ]: V( l- D
//矩阵初始化, K! d) J/ f7 h8 x
void Project_Matrix_Identity(double mtx[4][4])6 e# f8 i/ e: o1 ~# h$ J
{
* r' x$ v% w- P" C+ e int i,j;
$ f- o! S( y, j" z , I1 ^1 k" j8 y) ~' g
for(i=0;i<4;i++)
' K5 b7 b. I# J for(j=0;j<4;j++)! z& J3 U8 |5 c) ^8 A# z
if(i==j)
& K* K4 @" q! f _, h mtx[i][j]=1.0;
& [) o8 u3 U! i/ w F$ G+ I else
* Z9 U2 h; e* ^; |0 G$ c mtx[i][j]=0.0;
; z/ L- G( I x: a9 ~+ k}+ E$ s1 U$ x$ T+ V3 _
//矩阵相乘$ J6 n0 v2 e2 f, ~6 M; \
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])% W; P4 [) x3 g1 X7 v9 W, Z- m
{5 ?! o2 q- J9 q* z
! g. t7 X* a! z# W) i$ w6 M int i,j,k;5 t9 E2 Q3 h2 v6 M0 y
double left[4][4],right[4][4];
, C2 W( L+ R& r+ t; K n0 o, s9 z! U& H: b: F
Project_Matrix_Copy(left_mtx,left);
0 F; b$ L; T8 f# m2 _1 j Project_Matrix_Copy(right_mtx,right);
' m' _9 y+ @! t for(i=0;i<4;i++), t. w Z/ U; N2 D3 B8 _# E
for(j=0;j<4;j++)$ K9 C- s, d# {. S* n- n
{; o5 d/ p6 u6 @" h0 M
get_mtx[i][j]=0.0;( D7 {4 g8 k7 [( C1 ~) K
for(k=0;k<4;k++)9 J: s$ _& y0 B, @) x9 z
get_mtx[i][j]+=left[i][k]*right[k][j];
5 {# i3 j" E1 r, e1 R }2 b6 `+ ^0 k; c
}
/ B1 v# t$ H+ d- Z//转置矩阵% ^+ B% G- J$ J8 N9 S7 p
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
9 U- j* G& X9 g( _: Y0 G) Z5 n{" o/ o5 ~- @5 u! ~) K
int i,j;" k( t9 K. c' N$ _
for(i=0;i<4;i++)/ Y/ c7 V9 P& i. I) }6 e; z) f
{
: A! W, r7 q4 m6 p4 i9 U9 R for(j=0;j<4;j++)9 K* N0 K+ P3 u. z, p# ^0 q# Z
{+ Y. @' J% D) ]5 v
transpose_mtx[i][j]=mtx[j][i];
6 w9 M9 X% B, q: l7 a7 W }
* D. B& o8 _5 g- ^: _& F/ h }$ B7 \# G" ]- {6 b! [/ n& o1 Y
}
+ v' i* M6 Q5 j//从11元组获取变换矩阵
" c$ p' g. g% ?/ e! xvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
. Y1 D- x% A+ X{
. c* o, g) m9 D7 i+ ?
7 S" I9 K+ t7 o5 Y: \ //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
$ B7 K+ Z/ O0 J, }# @1 O int i,j;
/ G) D3 V) l. F4 h% o) y for(i=0;i<4;i++)6 P1 F2 d& Q: m$ T! @4 x
for(j=0;j<4;j++). s- C# e6 b& p O1 @$ D
if(i==j)/ l8 W! v4 q3 v. Z, x
pos[i][j]=1.0;: w+ _. E3 T1 a8 Q1 E
else4 t/ |' l" [0 ^$ O0 o( L
pos[i][j]=0.0; J$ I) S$ Z9 Y f" D( g1 H/ m
pos[3][0]+=translation[0];( d2 c0 s- I& m! S- H! x! {- t
pos[3][1]+=translation[1];
, ]& b7 i; [% ?$ C7 X9 x pos[3][2]+=translation[2];* r2 G* h. H% C% x4 o
}
7 M x6 {4 M4 x- {3 @8 c//向量缩放
9 ^) z5 g+ @9 s; g4 P3 \void Project_Vector_Scale(double a[3],double scale,double b[3]); N; x$ S3 p `. @: D( e4 L4 u1 |
{
, u. i3 u5 n& E- ?; \ b[0]=a[0]*scale;* B& n8 Z( K- o! t3 l: R6 Y
b[1]=a[1]*scale;) [- ~" M5 B( Y" q5 B1 O
b[2]=a[2]*scale;% C8 ?' K ^# ^# ^
}
) `5 L; l: U( H* ~2 s
. b) Z+ N+ f, A, e6 a1 } |
|