PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2014-8-25 15:14:54

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

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

x
! q$ F! U+ ?% I1 L
- J0 z, C6 o2 G/ I/ a, t

, @+ X* y- P) }# q' t& S#include <math.h>
2 {: v( V8 V. [7 R& o- }: i//矩阵复制
& o  q. U0 l9 t0 \; F* f+ ivoid Project_Matrix_Copy(double from_mtx[4][4], double to_mtx[4][4])
* d! |/ A5 z, P6 F{& S' ^, f. T5 j: v
        int i,j;7 E' e: P* X0 J* k
8 Y  I  ]0 V# M
        for(i=0;i<4;i++)! ~' Y, [4 ~$ W" Y* a2 C
                for(j=0;j<4;j++)
- L5 Q5 t/ e/ y2 y) ~                        to_mtx[i][j]=from_mtx[i][j];
3 _) A0 y  S0 X9 e0 M, S/ Y}. b8 `  b  _$ t, p2 S
//矩阵初始化& I' J+ G0 G; P7 g6 _
void Project_Matrix_Identity(double mtx[4][4])+ B: P9 k; j2 B' ?( n
{+ q, `% }5 V8 O& k3 ]* Y8 w
        int i,j;
* t2 o$ u. ?& l7 f' H        0 p* [: [2 c, c- X- n% U) A, e# r
        for(i=0;i<4;i++)
, P2 k! O3 s+ H0 G- |                for(j=0;j<4;j++)
* I+ M+ S1 k/ L  O, g  Y' f" b                        if(i==j)  F+ D+ H5 F1 l6 A; T# v+ m
                                mtx[i][j]=1.0;
, R5 q% K& a1 S8 {- o                        else
2 V# L$ K! k8 n& Z& e                                mtx[i][j]=0.0;! G* c/ f; U' |/ Z/ N, `
}
) j8 d* R# [' ?//矩阵相乘
$ O5 E) f1 `% `/ o5 J: R; w8 ]2 mvoid Project_Matrix_Product(double left_mtx[4][4],double right_mtx[4][4],double get_mtx[4][4])0 @& b) m0 s8 k6 _% N/ f* m0 G
{
8 T1 X- M- {  R5 s" Q7 p" ~% q2 o3 Z
        int i,j,k;8 }) D  j4 x' u; ~6 v6 Q% m
        double left[4][4],right[4][4];
/ l! t3 L3 ~. L3 Z' i7 r+ O3 i0 W, T/ R2 s: i
        Project_Matrix_Copy(left_mtx,left);* b1 O" A5 g2 f2 A) v* ^& o
        Project_Matrix_Copy(right_mtx,right);' Z/ \) O1 [7 b1 S
        for(i=0;i<4;i++)% x/ T1 b6 a* ]  x* h6 C/ E
                for(j=0;j<4;j++)
2 f, d; w) G: z! E& j                {+ Z: Q& E- ^% N* x8 B
                        get_mtx[i][j]=0.0;
! z" F- ?1 {* e5 e8 j                        for(k=0;k<4;k++)
7 w) d% w2 u! g                                get_mtx[i][j]+=left[i][k]*right[k][j];
4 ?- [* `  g9 Y4 @: h5 F7 |# q                }: u1 x6 Q8 o1 e2 B! s: {2 x) Z
}- x  s4 t7 n1 X
//转置矩阵
' L* w. q/ g) Xvoid Project_MatrixGet_Transpose(double mtx[4][4],double transpose_mtx[4][4])* B, B+ Z' z: ^1 Y5 c0 o
{
  j/ ?) Y% [7 \% b, T        int i,j;
. c; m" A8 y$ J$ C        for(i=0;i<4;i++)5 ]7 t+ l  K) P
        {
3 r( c' N: n& o2 x/ R                for(j=0;j<4;j++)6 W  Z( W! d7 Y2 E; Q6 ~
                {6 {2 S/ l7 K% f$ g: @1 E
                        transpose_mtx[i][j]=mtx[j][i];
2 ~4 @1 w6 W, u. T# e# T                }. _% w+ j0 `1 r
        }
% \8 Y/ M4 L  T- {2 D}
0 c! Y, U! Y8 P8 L, r//从11元组获取变换矩阵
9 y# }+ B, Y8 V* i# _3 ]void Project_Matrix_Get_From_Move(double translation[3],double point[3],double rotation[3],double angle,double pos[4][4])5 \9 ~2 @0 _& J; |
{
, q3 [( x9 U) x- d% Y; G; X* v3 F4 H5 B1 N6 ^% P, K$ h- o& z' |
        //Project_Matrix_Get_Rotation(rotation,point,angle,pos);
& H7 p3 G) u4 s. y        int i,j;
$ S8 k5 r& V8 w" J% q  S$ S        for(i=0;i<4;i++)1 w5 W/ l3 f* L" q4 }4 V- s" M
        for(j=0;j<4;j++)
0 g- c# x- o( M  X+ Z9 }                if(i==j)
9 F  M+ Q4 g! f                        pos[i][j]=1.0;& I- ]( d, f& T0 X( \, d: N( W2 ?
                else2 @0 A) n" y8 `3 Q/ o1 Y
                        pos[i][j]=0.0;
' o& G0 d  G0 d& h! Y: n+ o' C$ d% z        pos[3][0]+=translation[0];* [: q! D4 j8 h: ^2 \8 ~/ y1 p
        pos[3][1]+=translation[1];; `( B' L0 C9 w, L
        pos[3][2]+=translation[2];6 S, e6 f  j7 C" y3 V% E
}
7 u0 a' m0 c& |# Y//向量缩放
* |6 T; B3 _+ cvoid Project_Vector_Scale(double a[3],double scale,double b[3])- P7 ]- D' t! a' _
{
, {) K( k' F+ C1 E' ?% H6 a$ U        b[0]=a[0]*scale;7 n2 b" _% w3 S( C0 h3 _$ H
        b[1]=a[1]*scale;
5 {5 O# s6 k& M        b[2]=a[2]*scale;6 [. V2 L6 _2 M
}8 S9 X- f4 v( a/ f- q4 Z. {' m  v

& ]; |) g7 [- {3 O+ s- B5 Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了