PLM之家PLMHome-工业软件与AI结合践行者

[二次开发源码] UG NX二次开发源码分享:矩阵操作的基础算法代码

[复制链接]

2014-8-25 15:14:54 3646 0

admin 发表于 2014-8-25 15:14:54 |阅读模式

admin 楼主

2014-8-25 15:14:54

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
5 O8 ]3 \3 G- w! f9 C1 h( y4 ?
, U4 s8 N. q8 X8 Z9 y7 w

8 A1 C9 e! I) ?1 u) o! N( \7 {#include <math.h>
5 s; @  m2 L, f6 D' T$ A4 b( j//矩阵复制
/ k# v# F: M- S8 o  ~  ]! Ivoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
, t  P6 B; m, p/ u) B& t{
& X  k0 k  a, i        int i,j;
- P# c( N' D* G, i2 a, f
8 W& D4 n4 L# a9 u" N+ r        for(i=0;i<4;i++)
, ?; _- J7 M( i                for(j=0;j<4;j++)/ z( E& j" u' u
                        to_mtx[i][j]=from_mtx[i][j];( |' S4 _: X& q( [$ m" x2 H$ L
}
0 {# F  x4 B/ j6 u" Y//矩阵初始化
' g8 t! |& C6 o0 vvoid Project_Matrix_Identity(double mtx[4][4])9 n5 f! f" o$ W) n  ], b' F5 A5 S
{6 u6 W! ]6 r+ l* \4 ~1 @
        int i,j;9 H! f4 Y# g% @
        5 ]% T1 m6 s  H, B
        for(i=0;i<4;i++)
1 ?5 i- P- O5 Z  |; L                for(j=0;j<4;j++)* D# |  H" G- W) {' o0 q% e2 o/ M
                        if(i==j)6 p) f; Z1 Z& i
                                mtx[i][j]=1.0;
* M0 g( m  Y7 G2 w, s, ]" M2 M                        else+ p" @8 A& h; ~8 P; L8 f# l# o( `
                                mtx[i][j]=0.0;# I% B8 o; \! B! K2 e% p6 L
}
; V% K! Y8 H+ b9 [5 w//矩阵相乘2 D" r/ ?2 m$ V- Z9 ^& w
void Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])
& Y$ @: N( X% K$ T% O{
. @' b2 d1 x, n) U+ a! r0 @5 |- [! Y
        int i,j,k;/ W9 n) Y' H: \) {
        double left[4][4],right[4][4];
; l; |: ]2 ?5 P. T0 R4 n5 x: `# F. T4 r
        Project_Matrix_Copy(left_mtx,left);" D: a9 o5 k! Z3 T
        Project_Matrix_Copy(right_mtx,right);& a4 B7 r4 [( e8 ~* S" {, i+ M/ a- ]
        for(i=0;i<4;i++)& \6 C) A) D* m8 J! S5 p1 {# Q$ Q
                for(j=0;j<4;j++)9 f) p, d# C* E& |+ I
                {6 |' b4 T6 _3 w9 x) H/ t
                        get_mtx[i][j]=0.0;
# E) E  K  n7 a3 @- p* V$ z                        for(k=0;k<4;k++)! e" W. [7 o8 z, O4 g6 O+ }
                                get_mtx[i][j]+=left[i][k]*right[k][j];
! @! @6 L/ S! |; d9 M. q                }
: W0 ^3 F+ }- H3 m2 ?$ M. Q% k; V}
6 Y; \% Z9 w$ C0 M- Q0 S//转置矩阵0 ?! I! Q' x3 W# }4 s0 {- q2 ?) o
void Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])5 B! d1 ?( F& I# Q/ ^
{
. T' t. e! J! y1 r        int i,j;
1 |4 `: p3 S- P5 u3 x        for(i=0;i<4;i++)* f% Z7 h8 Y6 _0 U+ I) h, ^) O7 q
        {
3 b' L# ]! C/ g5 Z                for(j=0;j<4;j++)7 }! u4 U/ s1 X' H6 s+ [# c& W
                {$ D4 x8 x, ~# c' w! Q; d
                        transpose_mtx[i][j]=mtx[j][i];, K# ^( x# R; ^4 k  U
                }
! O! ]  T9 u$ B% t9 ?* }" `/ |        }
/ G2 ~) T5 Y! C- t  X' V}6 N7 w  V2 `1 C, t! ~- K
//从11元组获取变换矩阵
2 J! B& j6 f( U: svoid Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])
( m( r1 W. f* i4 g6 v: c{
  G4 g( \$ g! _  h8 q4 ?  l0 W/ }6 K1 Z$ C8 z% ?* D
        //Project_Matrix_Get_Rotation(rotation,point,angle,pos);; e. z! c, t+ K) T3 ^3 \
        int i,j;
% x! @: W7 l0 f3 R  }/ t; j% @% o" c2 k        for(i=0;i<4;i++)
4 ?4 `4 B5 q/ V0 G- G( I6 u0 l        for(j=0;j<4;j++)  p+ B5 _! X6 c, r- T1 S- h' [
                if(i==j)5 {- Q7 {& A3 l9 w( o$ C$ s- K
                        pos[i][j]=1.0;) V& @/ N" ]6 g$ P
                else" \- }+ T) ^8 v: l! Q) `9 t
                        pos[i][j]=0.0;  J8 s# w0 X0 ^: Z# h  ^3 f7 o
        pos[3][0]+=translation[0];' j( c7 s, E& ^$ |- [; ?
        pos[3][1]+=translation[1];
0 Y1 F8 I2 O& |% j5 P5 l% M        pos[3][2]+=translation[2];
' U/ R$ \+ `7 C6 ]' R, r}# R1 S/ r* _- `$ f1 Q
//向量缩放. |+ @9 `* j) t: N8 m2 u
void Project_Vector_Scale(double a[3],double scale,double b[3])
8 p! V4 E6 f, G+ E/ _6 U' d* V" B/ Z{
: }  z1 c7 x( q/ ]+ N0 e: o9 ~5 ^0 h        b[0]=a[0]*scale;
, k* V. `0 t3 @        b[1]=a[1]*scale;
4 T3 Z6 k: F+ ?6 w* J6 x        b[2]=a[2]*scale;
  A9 Z4 \1 W. P}
& L) y/ B  T- B
% s9 G5 w# L2 K% ]. G
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了