|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" z: e. L, I& Q1 E- U9 V5 S5 J: M( r3 y6 C ?0 a0 i
, Y7 N" O: u7 V& e+ T1 n! P#include <math.h> 9 Q3 r/ Q( U6 C3 A+ U
//矩阵复制
" o. E# t* J4 ovoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
" c/ P0 J: x' q* Z{; r: s% O U" I6 p# U7 e7 S
int i,j;
8 ?3 V9 d" ? j0 \
4 [& {7 ], x& ~. V for(i=0;i<4;i++)
+ ~- Z W( r& f+ J, r& \ for(j=0;j<4;j++)
o7 o; s! S* \8 l! l to_mtx[i][j]=from_mtx[i][j];
& \ W, g% |2 U2 ~! @8 \}- ~! E/ A T! r$ [* |+ o; I
//矩阵初始化" S+ g% S. k/ S6 d8 b
void Project_Matrix_Identity(double mtx[4][4])
8 V+ Y6 D) u% {# k- R( H/ q0 k1 }{
5 J1 t- G( o6 h int i,j;
: L! s* _& o. `/ C / l: ~4 l. b' y" w' o
for(i=0;i<4;i++); o8 D, ^! h+ {% x
for(j=0;j<4;j++)7 \( c" x2 S5 h4 \
if(i==j)
. T; H7 \( U' @# u5 K mtx[i][j]=1.0;3 J5 n& `$ [2 \4 j9 V* h$ z8 J
else
+ [5 d% Z* d7 f mtx[i][j]=0.0;
& j4 t4 u" H" |$ H}
3 c! {) C8 ^( m6 K9 i+ W# N//矩阵相乘6 W- c& U' C( k* P3 G( m4 y. T1 r1 T
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4]) C( e# g% K% L6 a, A" C2 W
{
# f' c) y! f# D' s* Z% e- t& y& c2 \9 l2 w6 E
int i,j,k;8 O# {* w3 v3 W
double left[4][4],right[4][4];" r& p B- x* b2 Q' u, f h. z! K9 p
1 m1 X5 z0 N" k3 W3 c4 c- s Project_Matrix_Copy(left_mtx,left);$ z5 |8 m9 ~$ K+ P! u5 g7 H$ G
Project_Matrix_Copy(right_mtx,right);
: Z$ {- l5 n$ L$ s$ j for(i=0;i<4;i++)
+ b8 o0 ]7 F3 o' L7 q$ N# a n for(j=0;j<4;j++)- b# V' W, D' y( V! q- s
{# r) ~& i% ?/ @( z
get_mtx[i][j]=0.0;# {. Z; q# ]3 a t* h
for(k=0;k<4;k++)% N0 a+ b6 T. ], [$ m
get_mtx[i][j]+=left[i][k]*right[k][j];, v0 B, g, x2 f. U6 S; Y; c8 {0 y* W
}
( \7 f4 W4 r5 O$ t' f}6 n2 O1 }3 ?9 m9 u3 L
//转置矩阵
- Q! o& g2 R( e& _) } [' ?void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])! R# R6 U+ p+ N" ~1 T0 N) V
{, p/ Q) h$ T* j4 v" k
int i,j;
4 m9 x5 X' s' w; {. R" X for(i=0;i<4;i++)
9 s! M* M4 O3 D3 L {
1 g. k5 ]0 k7 I% k: f3 X) m for(j=0;j<4;j++)
2 e- f5 m1 U# e5 l6 ~ {
( I6 ~. Y* q. H8 r! U2 X transpose_mtx[i][j]=mtx[j][i];- E2 G6 F* j3 D# H" J3 @; j$ L9 H* T
}* g# G5 _2 T: G2 o' @$ l) D
}: W Q4 v9 u: |; f' J* X
}3 V% w6 f8 ^0 J3 R H
//从11元组获取变换矩阵
% |+ O( E& t: z) a0 _9 ^8 nvoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4]): M# S9 O5 q$ i6 s% \
{5 o* O- D" j3 n) o4 c1 d/ c
( [+ F/ r: b8 k+ S4 Q0 K //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
P4 N) q6 _8 i5 u7 N4 N int i,j;
" b- ]+ }5 L$ ]. n; n; @* Y2 P for(i=0;i<4;i++)! J7 ?- Z9 n# R& |
for(j=0;j<4;j++)
) k& S- ?$ P0 i6 g, l5 n if(i==j)
. ~& g. P0 B+ i$ s7 W) y pos[i][j]=1.0;
5 z- T3 r: e. N& G$ M. y* k3 j else
& ], a3 i3 W+ y- R% _: M pos[i][j]=0.0;$ C0 l/ e, F; M% v( z# S
pos[3][0]+=translation[0];
- m, L# ?/ v7 S0 X" w pos[3][1]+=translation[1];
# v$ F3 }2 V, ?8 W5 d, I" ^ pos[3][2]+=translation[2];
* W. R" r2 c& \}. Y2 @) w5 x& I, u7 ~$ Y, `/ l
//向量缩放; d. t" n4 U5 H2 d6 M1 g% |. `
void Project_Vector_Scale(double a[3],double scale,double b[3])
$ O( ?# z9 b/ b. v9 F& j{
4 K: V7 c* v( \ b[0]=a[0]*scale;
. R0 {$ l: [1 H. T b[1]=a[1]*scale;
% {% V: ]8 E4 g, U: @% B. V b[2]=a[2]*scale;; _7 t- }, Y* [. K, j( G7 G
}- a3 N( }& J" @
# c; c$ _" g1 @9 C0 Z8 s |
|