|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
9 K, r0 O' ^# p n+ c/ O' S+ B
8 L* `; J1 g. S, V7 a& [$ b$ V+ I4 e# w) q7 f7 T1 U! }
#include <math.h> . U# i1 Z4 l+ ?3 J! _. m
//矩阵复制
" `: c. ^" Y( B9 R K$ C2 Jvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
& A6 @* c1 q$ I; l! d- ~6 J3 f{
, K" K; o/ |+ L4 n6 X0 I int i,j;0 J; f: L+ r& w" l+ J
. A: f" f* ^! G4 f% ] for(i=0;i<4;i++)( g/ ]6 K- E8 ^% K2 h7 t/ Y# ^
for(j=0;j<4;j++)
9 F3 h Z. }% y& O+ l to_mtx[i][j]=from_mtx[i][j];
, I b# g4 k- d' L}
! a: u1 v. p" `0 M2 ]; ~//矩阵初始化
( J: }$ `$ V) B; w$ e1 a/ evoid Project_Matrix_Identity(double mtx[4][4])/ \) d& V! w, j% Y: q2 `; Q
{
# |" O" _! q+ m0 t+ @ { int i,j;$ W1 A) a0 S- \3 l: a" J0 R2 _
% l- @. Y9 i# D/ Q. p for(i=0;i<4;i++)4 {0 Q$ r1 l: `9 ?4 U1 X" h
for(j=0;j<4;j++)
5 Q1 P1 `, D- f8 C. L- ^ if(i==j)& h9 ~) F' `, p
mtx[i][j]=1.0;* M# `6 d' ~! I
else
M2 T' a v5 T mtx[i][j]=0.0;- a, v* X1 z/ U$ c5 a& N
}5 I; i6 v& p/ V3 I s9 k/ N
//矩阵相乘% m( P+ _* q; U2 ]7 `: W: a! ^
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])" h) _5 |# \8 f [+ x8 I- V+ W
{
+ @7 f" I) ?2 ^, g- [. c" z% |* T" `
int i,j,k;% _/ A0 |" F2 E. Z# [2 a
double left[4][4],right[4][4];) L3 H# N c ~5 |
* v" U. V6 {% E& n# \' W Project_Matrix_Copy(left_mtx,left);
: W" G% f* f/ m, N, t- L Project_Matrix_Copy(right_mtx,right);% g: ~0 Z8 a' y
for(i=0;i<4;i++)1 ~# ~" G$ {6 _6 H% C0 T6 ^
for(j=0;j<4;j++) E3 m; X4 Z# z, x+ Y
{
3 v2 d/ p. Z+ D, z1 y- S% e get_mtx[i][j]=0.0;" O2 i) `3 A' e0 [1 z9 J; y7 G
for(k=0;k<4;k++)
# W0 t; v5 Z, s" O get_mtx[i][j]+=left[i][k]*right[k][j];
2 `: `1 m8 ^/ N }8 |- N6 d4 Q, k7 W/ F0 X
}# L! ?3 {" p4 l$ `: B; o. _. d2 f. J
//转置矩阵
^. }; t# m6 ?% [; V+ uvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
5 d1 y1 S5 X; I. A8 }2 T{2 c* [$ Y$ `* Z2 r, x
int i,j;: ` ^0 j9 \6 q8 e
for(i=0;i<4;i++)4 e& Q3 G- A, g- _. B1 h
{
& A1 ?- [7 T( @1 [0 B# g: ]7 H- g for(j=0;j<4;j++)1 p- k% {9 M2 x; h- w
{) ~$ h* U5 x" m. O4 D1 R
transpose_mtx[i][j]=mtx[j][i];+ f: {9 I# Q7 `3 D: c. g; p
}0 K4 B+ g& V) V5 n
}3 l; m& U7 P1 g; p. a& X ^/ D
}( p/ f0 @2 _) E1 p. k1 @
//从11元组获取变换矩阵6 A" q7 _) k. L f) f9 p% F
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])+ S/ k$ ]( r# |' L
{/ A5 T/ j% N9 e B! Z% W Z/ p" z
) [' [2 g& G, P! {: G6 ] //Project_Matrix_Get_Rotation(rotation,point,angle,pos);7 [; v- h# e; b$ X$ V7 E
int i,j;+ P8 h# P& }! N, W* i3 P8 W
for(i=0;i<4;i++)
# P$ Y* z: L" H! m for(j=0;j<4;j++)+ f8 f. o" r0 w- n
if(i==j)0 S1 S5 J3 p9 f3 |
pos[i][j]=1.0;8 i3 t, A d5 U) }- ~. P
else; `; Z( {0 B. h6 p
pos[i][j]=0.0;
$ _9 X, [5 R3 M. P; V pos[3][0]+=translation[0];
! @& O- U% i$ m6 p/ J8 F4 h+ i pos[3][1]+=translation[1];4 E+ {( Z, l9 a% ^
pos[3][2]+=translation[2];, I, x! P1 S$ U \9 j1 u4 I
}
7 u# f" b D" R) p+ ^0 L//向量缩放0 o3 m1 y0 R* ?" q/ u3 z9 y: M8 K
void Project_Vector_Scale(double a[3],double scale,double b[3]); i" _0 T f6 l/ o4 ~
{
# ^, Q/ h* T! ?. R! _ b[0]=a[0]*scale;2 g# g! z8 ^4 d2 H; u/ o
b[1]=a[1]*scale;9 K+ x4 n5 P- _. c6 p6 b( J7 {
b[2]=a[2]*scale;! F# ]8 c2 J, h3 b) s( p+ w8 F
}; |& y$ C& V1 g4 r( t7 l
7 y: R& }/ J; l2 ?
|
|