|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 ]# [/ @4 A; p& R M8 U. {
1 |7 @! z1 l0 x( @6 @2 J3 T2 _% s( g
2 P5 T* |) ~% M* h, I# `* c#include <math.h>
5 ~) Y. B# h1 @* j6 ~# u! D//矩阵复制1 U/ I: ]7 ]( U# ^
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])1 q( L& e+ a) A1 p" N7 C
{
9 ]! V' H p8 x8 b( J* k" D o8 r% y int i,j;
}$ e# I; J+ `5 `4 C P, d1 p+ U, c3 \& ]8 |. e8 f
for(i=0;i<4;i++)- |0 E) K$ M$ B. V! Y
for(j=0;j<4;j++)$ q5 m' g" t0 n3 x* p6 M" `
to_mtx[i][j]=from_mtx[i][j];
2 N7 J3 e/ m7 d8 \3 K! t}
+ a6 i4 r! s4 G0 f* S6 l//矩阵初始化: r3 j: l: N' M! z( I" T0 e
void Project_Matrix_Identity(double mtx[4][4])
/ _! G$ Q9 D4 d& P{
. t) f1 K# E9 Q- f j0 e int i,j;
* d: G0 e( ]! E5 D
8 w; _& _2 U( d4 h3 P' v for(i=0;i<4;i++)/ ?" |8 T6 S6 K# C! a2 D
for(j=0;j<4;j++)- Y& G. _( B; w: M9 \
if(i==j)3 l D& l3 {& L$ H0 g" b
mtx[i][j]=1.0;
+ d. T& y6 p. }7 R- e else: W. v/ z! z+ F1 q1 U
mtx[i][j]=0.0;
4 W, P- T$ T2 J. k}
9 Q* N+ o& S3 {% m. P% _1 G, I9 H//矩阵相乘 q' R( w) a# O; \" }6 s
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])7 J5 m, L# K k; i) ?4 e$ ~$ V
{
' G, H5 s, \; P$ a2 g' e$ W! S4 y' d3 }
int i,j,k;
" A2 A- ?) t8 u# D/ V* D/ ]# v0 Y( e double left[4][4],right[4][4];
4 ?, i# Y- p r; p2 M
# R) W/ C' |* V+ o5 }4 z Project_Matrix_Copy(left_mtx,left); H6 s7 n8 d8 @4 C$ K& W
Project_Matrix_Copy(right_mtx,right);: e5 o: I* ~2 ~4 f0 b: }$ ]% \
for(i=0;i<4;i++)
8 k5 W# Q- M W/ Q+ h for(j=0;j<4;j++)
! M j# D5 r( A7 W {- a) L' V* Y% g& L! P- `) W' [
get_mtx[i][j]=0.0;
' {+ o5 D" q9 {! U. W for(k=0;k<4;k++)
4 ~6 d% _ W2 d get_mtx[i][j]+=left[i][k]*right[k][j];; O' s. X2 f" m! ^$ P
}- e& H( d5 w8 B
}
1 t# ~2 v$ s" m8 U# j X8 Z//转置矩阵; w6 s. h, \8 C& H
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])& x4 Z: F i. d L1 @; f
{. z' D9 J% P0 W2 `1 ?" u: J6 `
int i,j;
- U2 q4 h5 ^2 P for(i=0;i<4;i++): H2 w! ~2 a! A: q2 Q6 |
{
' U3 h" A. @' g2 w for(j=0;j<4;j++)
0 E' z4 m" t& l& j- s3 K, m& ] {
- \& u" q2 K) T2 }' u2 J transpose_mtx[i][j]=mtx[j][i];3 @ E6 ]$ J) p/ z% i6 h
}" e) u; p9 k$ M. x* O! {: J
}6 X; t' ~! U% w3 z' [" r- i G
}
- G+ n5 ^. t5 }$ C//从11元组获取变换矩阵3 H: E! _* U/ x W
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
) l+ {4 n; p2 ?: g7 N8 S. g! L{
) |. O3 t. Y1 _6 n2 R# l
% N# P4 A) o, i5 J% v2 z$ O5 _ //Project_Matrix_Get_Rotation(rotation,point,angle,pos);, N9 p) C7 y5 x1 Z' }6 i
int i,j;1 c' C& ?9 q6 @+ P: Y1 q" z- _
for(i=0;i<4;i++)2 f9 Y; r& E1 ?# C
for(j=0;j<4;j++)% b% O7 s# ^3 ?, w# {
if(i==j)
/ g9 z, f) O; T6 V- A' |% n pos[i][j]=1.0;
: o! ^! N* U* v0 o else6 N, Y* I3 I+ j9 H, `: c; @) S3 V
pos[i][j]=0.0;
7 w8 D* r% @/ D! @ pos[3][0]+=translation[0];
" s C" ?8 p0 B# W+ J- P! }! L pos[3][1]+=translation[1];$ {0 `/ j% H: H) G0 V- w
pos[3][2]+=translation[2];
7 `" w8 y2 V. X}
2 o$ M( `, b, M, A//向量缩放
9 G& `/ ] _% [) ?' X6 X. M6 _7 Jvoid Project_Vector_Scale(double a[3],double scale,double b[3])
% U7 _. H# u' g% W3 j7 V" }{/ Q) H( k F- z4 p; c
b[0]=a[0]*scale;
, a i9 |/ s6 j. `/ b9 I# y; A b[1]=a[1]*scale;
6 s3 {# K3 D- \( N7 P4 w% [ b[2]=a[2]*scale;
) n& [$ R1 R' f3 s( J. v' J# E6 ~' g}
- _$ _+ Y+ u) r9 L& g
" E6 P# z6 K# w7 L |
|