|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
- |: A4 h1 |# o. S1 |9 d: d6 q, k: @/ l$ D7 k' `
- ^( ?, M& m5 K' y! B, b#include <math.h> 5 w4 p* k5 g1 U; Z% W
//矩阵复制* y+ C6 i2 M& D+ x* L# ~. U
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4]). W& B' d' a* q% S( O; t6 }
{
- x7 n N+ e: F6 c1 Q3 Q( s( ~6 x int i,j;
# _9 o5 f( E1 M7 H# k
/ |2 }: G/ Z* q% n6 v E8 {7 d for(i=0;i<4;i++)) V$ j, ^3 M: e
for(j=0;j<4;j++)
a) W( |& ]4 _& t9 Q to_mtx[i][j]=from_mtx[i][j];7 J( S% j6 h* I1 A* t1 T" t
}2 |3 w0 `9 J$ t$ z5 Y
//矩阵初始化* G/ K6 u$ E! |; |( P
void Project_Matrix_Identity(double mtx[4][4])
: Q2 [* G( o( _- d{
$ U2 i; F7 A3 c1 I. u+ w# R$ M int i,j;' v# @# [- L4 F4 {; Q" W
/ w4 ]' X- ], b for(i=0;i<4;i++)
8 c$ ~1 o6 v# {( S4 ] for(j=0;j<4;j++)
2 n* Z+ u" c5 y. Z if(i==j)
% Q# R( [4 ^! M( [: ?. b+ { mtx[i][j]=1.0;% q% Z9 e4 ~& x0 @( T* O( ~9 O
else! k! a: a m# l. W
mtx[i][j]=0.0;% c4 N& E( Z6 I4 _" A5 |" G$ O: w
}; L1 `4 m( `3 p/ t6 u. O
//矩阵相乘
. Y: o% c \8 O( O' Dvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])! f5 i3 D2 k+ Y9 k9 y
{
3 k+ d+ p+ \6 n; \+ [) v7 i
q( D/ ~" M- F- S6 \0 ^ int i,j,k;) K3 X# C7 \" t
double left[4][4],right[4][4];
; ~/ N. L3 ]' l1 Y5 P
4 ^4 T7 o3 b0 E/ a; t; k: k) l Project_Matrix_Copy(left_mtx,left);9 D0 ?0 q( Q1 f% N
Project_Matrix_Copy(right_mtx,right);. o5 f7 [7 W$ \' b: q& c) F7 V
for(i=0;i<4;i++)+ Y4 q9 I+ K% v8 E7 ~4 n
for(j=0;j<4;j++)
- o' w7 }& A! j1 B" u5 B7 n7 Q {
- Z* O2 k1 @8 {/ B1 ~ get_mtx[i][j]=0.0;
/ a* t, v: k& g" l for(k=0;k<4;k++)0 j# q0 b5 g. E) q
get_mtx[i][j]+=left[i][k]*right[k][j];7 i- b4 [$ c. a j) |: ?& `
}$ j( D8 e) r- T z
} u" e: S0 z9 k2 i
//转置矩阵- y; O+ ^' o+ h
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
' s7 w: q$ \2 x# {7 g- D{# x7 d2 Y$ ^. r; V4 |
int i,j;: E" d4 i2 g0 C. s
for(i=0;i<4;i++)
5 X0 y1 M9 j: y3 V3 s {! Q& g0 U# g: k& N# B. W5 J4 b M
for(j=0;j<4;j++)
( n" n) I |( U7 ?% M {
- z" a9 P" m+ i/ \7 V transpose_mtx[i][j]=mtx[j][i];. Q; H k2 f7 p& b8 U) w& V' U
}% z$ m; Z% m4 c6 u; I% r8 L2 \: d9 ?
}; R, s6 A. x0 p
}6 ]2 X5 Y, D. H9 W2 ?
//从11元组获取变换矩阵! c) |6 r6 {9 A! F8 l& Z/ U
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4]) l1 v9 W4 I5 G$ P$ m: w
{6 g! l- |6 g1 y7 Q
1 v) V6 V5 l2 \& Y! B //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
$ G! \9 n1 I* N8 E* M" t( G- t int i,j;$ x# b/ _; ~* n; z/ G. y, ^
for(i=0;i<4;i++)
9 x: q! _7 R' B. v9 |2 T: L for(j=0;j<4;j++)2 c; u: c, J5 \; ?, f& V# c4 O
if(i==j)" m0 j6 R3 R2 d# B9 y1 M
pos[i][j]=1.0;
' R7 U E3 ~9 {$ _) _+ g+ N else
! s9 k6 C: j! O+ U" {# W9 ? pos[i][j]=0.0;
8 ^; ?# a. l0 |+ k5 X) ~3 H pos[3][0]+=translation[0];! o" M0 P7 Y! d- w5 D5 T5 y% j3 S
pos[3][1]+=translation[1];
5 S8 Z) u# Y C! R* M n3 p$ g1 Y pos[3][2]+=translation[2];
. z6 V* Y* |+ V9 o# V" s+ q}+ }5 V; D( k2 t+ i
//向量缩放; P, m L- [2 W1 e0 [; a
void Project_Vector_Scale(double a[3],double scale,double b[3])
7 D* K6 f9 D7 _' ` K- v# f4 x4 ?4 S{) e7 U: e" c4 ~( O
b[0]=a[0]*scale;% v2 Q' v+ e q2 h
b[1]=a[1]*scale;
) Q. X S" ?% N6 X& `- } b[2]=a[2]*scale;
! |$ v, r! E1 o: ~* Q( ]}3 k4 @' g# n: Q, t( U: D
5 u- }9 m9 l2 ~# ^; P' I. g5 j |
|