|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
4 z$ u3 Y/ q. s8 h& v6 Y8 x/ h6 n, e( `- g* e
# T7 \% ~0 N2 q9 T6 X
#include <math.h>
# z% S: t9 a- T$ X5 r//矩阵复制' M" F2 r' t. o: }) T
void Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
9 j, ?1 [2 l/ R7 w+ q$ G{
9 X% x+ e1 o V& j8 W6 w" s int i,j;7 V& f% [! j# x8 v
- C) P9 C2 t: Q2 A/ |# K for(i=0;i<4;i++)
* e, H- M4 Y- e for(j=0;j<4;j++)4 B4 P1 M3 `+ Y' v6 n
to_mtx[i][j]=from_mtx[i][j];" h+ i ]. a$ \ q
}6 L5 _! F/ ?4 P& m$ `( @
//矩阵初始化
3 G5 Z' o# B+ M# }0 Z5 rvoid Project_Matrix_Identity(double mtx[4][4])
f8 n) M) `1 l4 n/ j# V{
! R/ A3 Y7 N$ `1 d5 Q: _ int i,j;& M. R& b4 l3 C9 x. c& m4 `% x, [
% m& ~! z* d, c O& F
for(i=0;i<4;i++)
# y' i5 M* ~. c6 b for(j=0;j<4;j++)
) _5 ?% f3 w/ {, E. } if(i==j); |% H0 G- C2 Z; x3 z2 y
mtx[i][j]=1.0;4 w' p: B$ T6 j3 j* W
else; w% n/ T7 g( i6 D: z3 i. p
mtx[i][j]=0.0;
. Q' Z+ \2 \/ k' y8 ]}$ w! z7 V( f7 X3 u
//矩阵相乘
. C O9 K Q1 S- }void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
d; P: s8 h2 D. B% b( n{
N) Q# H! b% `( C; _
5 \; t& }; a+ W9 v7 D int i,j,k;
& ^7 X! t+ B: `* O double left[4][4],right[4][4];
& V% ^0 r9 a& N2 A. d% I* F! A4 Z4 L2 ~* H5 o- p8 M7 I! x
Project_Matrix_Copy(left_mtx,left);
4 V0 _2 G. E/ ^ Project_Matrix_Copy(right_mtx,right); W; j" t! t9 ^3 v$ N9 G- V
for(i=0;i<4;i++). l6 R1 Z2 h) u
for(j=0;j<4;j++)
" N2 W" D8 x+ K( M: M {. I& E- x9 X6 v4 V! ^
get_mtx[i][j]=0.0;, r* T: n4 _* X8 Q3 w
for(k=0;k<4;k++)
$ C0 G; }( {* P% L& \' D get_mtx[i][j]+=left[i][k]*right[k][j];
3 I1 M6 S: ]. D0 B4 i0 d' z }
9 r3 x( p3 Z8 L}
. ]; Y) U4 s8 M8 N//转置矩阵
( H$ f/ F" d: f9 y4 J' Yvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
8 h/ L& K* _0 C{7 k$ U( @$ _. f2 l& ]
int i,j;
; ]9 _+ O, m# z3 {, X G; k4 r for(i=0;i<4;i++). |5 M# e; I" |
{
( {( m9 \# d$ H8 a; B$ |$ Y( J: x for(j=0;j<4;j++)
- _- c9 b! @; j. y1 E' \5 r; Y {
4 v: k/ x0 O. x5 h; l transpose_mtx[i][j]=mtx[j][i];5 ~- }. N4 O& Y) B m
}2 M5 v4 H8 d- b
}4 t/ o! m- e7 |" U! h, Y0 M6 Q5 R
}
% O5 q6 c. G9 ~( W& I: C8 [//从11元组获取变换矩阵8 W# z; P1 _" O3 A) \; W
void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
% g/ Y4 Z9 {3 c& J7 J% a5 N1 i{5 P3 v* K" Y( ?! v2 Z6 s+ O" ]
, i \9 O; y# ?3 {' p$ [5 i
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
+ K! J# E' ^* u- n' }3 l( _) _ int i,j;
. | d* o# u1 b( m for(i=0;i<4;i++)8 P. e& O+ A: q! c9 p5 |
for(j=0;j<4;j++)- {* V3 A x0 c6 \
if(i==j). u" b' z6 {( U% @. O
pos[i][j]=1.0;
, |# ` o1 T* \3 R9 N2 ^) g: b else6 N3 @' h1 I% L. H/ N, [' q3 }
pos[i][j]=0.0;
+ g9 {" d% J1 Q- x# v/ V pos[3][0]+=translation[0];
7 Y% K& v" m E4 q pos[3][1]+=translation[1];6 A6 V: ` F, O3 G: W
pos[3][2]+=translation[2];
$ A# P" N/ J" A0 w' h2 U9 Z}0 _4 B5 c3 ]6 p/ K, p% A
//向量缩放
3 e: J' D$ [3 P( M. y2 I( s1 R! ivoid Project_Vector_Scale(double a[3],double scale,double b[3])
& Z$ L2 J9 F, Z! \{
- @5 v) P* p, G' s2 R) i, |# I4 N b[0]=a[0]*scale;) B! ?6 H7 U. V) d8 F( [& \' V
b[1]=a[1]*scale;( m, `5 ?% I; i @
b[2]=a[2]*scale;0 W# ?# \) |! F6 `, q8 \2 d
}5 q7 r6 d3 X+ |
' X" g: u$ T9 B& G- n: U; u" W
|
|