|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 r( Z ]2 l7 N3 C" d
% r2 ~0 ~: v) |6 F
5 R! e- C+ L: N" T#include <math.h>
( r, F1 x1 b/ q0 g//矩阵复制
+ u) d6 J0 ^/ Z- Z& ^0 Q& fvoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
% v: z! h% c" r! Q, z{
* a- S# K" m; r' }& O& i int i,j; V4 X2 B9 O' @# Y& a) \5 N
+ e3 r2 { W) P" r& u) h3 }
for(i=0;i<4;i++)
. H% L$ A6 J' x for(j=0;j<4;j++)
# `! l% g! C5 S0 f to_mtx[i][j]=from_mtx[i][j];
; i( m C' i, a4 }4 F}
0 g) L6 ]" K) v& @* L6 R3 d/ u//矩阵初始化: x* t& _1 u2 U6 W1 l
void Project_Matrix_Identity(double mtx[4][4])
6 M% a: N5 {( j/ {- K/ M) n* P{
& v% ]* a2 q% R( }7 d int i,j;0 {+ o' e% U, ^' k
# l! A; T" `6 c' _: Q1 S% E7 S! U. Q for(i=0;i<4;i++) e9 @$ }5 y% K7 t& [* h1 B
for(j=0;j<4;j++)
( |: f3 L6 w2 Y8 K3 f if(i==j)" N8 v2 l, H2 @+ g- J- ~
mtx[i][j]=1.0;
7 h, W' N' I; @0 [ else
3 v& x" ], e& R9 ?$ l# o% X, ?6 ^ mtx[i][j]=0.0;
! y" ~: j0 N, ?2 O4 H Q% S; m}$ z: V( d8 V, J. j+ B Y
//矩阵相乘
6 c! l! }4 L, v9 p9 _" W! Evoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])7 N* ` k7 G" {$ K
{' X9 y+ E1 D& X. W) S3 e: q
0 h) @/ @ i$ R; v* f$ ^6 a int i,j,k;9 h! {; q- X4 K$ Z ]
double left[4][4],right[4][4];
& o5 r! L) N( ]8 [ s0 z- u# q" T3 o% M- {" X1 U0 ]' X- D
Project_Matrix_Copy(left_mtx,left);
+ ]- x! o8 D: A$ q% m8 q Project_Matrix_Copy(right_mtx,right);
( a& R1 y8 C X+ V" e( S: v* S* S( t for(i=0;i<4;i++)' ]* K2 J' x" Y5 F
for(j=0;j<4;j++)
6 j P5 E, l4 G6 _1 \- z' K {; s, n8 e' b4 b( d! G
get_mtx[i][j]=0.0;0 T. i1 W' s) j9 T6 a# E
for(k=0;k<4;k++)! T4 Z! f& F0 l0 F7 s# [. F% l
get_mtx[i][j]+=left[i][k]*right[k][j];9 M' `2 g7 f+ n# r+ l5 \& L4 T
}
' l5 k/ j) V6 b}
) L' g- o4 p. q. \//转置矩阵
! P9 I. g6 U0 ~# c5 Ivoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])
- \% f' q0 |0 Z2 p4 @+ B) G{
( t5 q' E9 E! A9 X* a! f int i,j;) T0 D2 _+ [, i* D$ X: g
for(i=0;i<4;i++)
9 ?$ O" T8 D- E8 F {- ?( z& U" A# Z& u/ J% V
for(j=0;j<4;j++)
% B! ~- ?( p& ?; Z- ?, P$ s) h6 Q$ L% y {/ a/ z# r" Z$ Q
transpose_mtx[i][j]=mtx[j][i];
/ C; p" w& R* N; e+ {& X }
! V( p( O( _; Z0 \ }
9 e ]2 k; R( j* F5 v0 J}9 g) w j# W. n1 d
//从11元组获取变换矩阵
; {6 l9 O0 V/ o7 ?void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4]) h2 g: G3 M6 p) Z
{. K6 ]2 b: I. F6 e+ s C# u; l
% C6 c1 e8 f$ f' C. i! G
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
/ Y1 R3 p& |! U* B# ^5 O int i,j; x' R* y$ A: Z+ T
for(i=0;i<4;i++)
y: m$ Q) P+ Y* j4 d) I6 B& X. `" d# } for(j=0;j<4;j++)
8 n& B! r1 ~# t5 |0 h! P if(i==j): D4 t. N+ d; }* i! {' W
pos[i][j]=1.0;
+ B9 r, J, \3 K0 W" y4 x else
- V' w, p2 o% ]: H1 S, i1 G pos[i][j]=0.0;4 D; u' S9 l: i
pos[3][0]+=translation[0];7 h- B" A/ j9 L$ I N
pos[3][1]+=translation[1];# ~% ~( C" V' K" `5 ~5 v+ Y6 M. ^
pos[3][2]+=translation[2];
. G! y3 k( Y. R}
, p2 r/ W: X! @* G/ O//向量缩放
4 V- @0 D; {+ ~8 f; @# Zvoid Project_Vector_Scale(double a[3],double scale,double b[3]) ~5 q- @: D* v/ g8 o0 k- \
{
$ a* Z& C5 c" ?2 g( h b[0]=a[0]*scale;
5 f! A* w: i$ d$ }+ O- H b[1]=a[1]*scale;( _- h! e- k4 q |) I+ J
b[2]=a[2]*scale;, \' ?: r$ h: L) D5 ^" ~
}7 I- {0 ^, d. U3 ^2 g9 Q+ p& B
6 T3 a7 Y; ^3 D: w1 _8 {
|
|