C# Solidworks二次开发:向量相关的数学函数API使用(第二讲)

大家好,今天要讲的是关于向量相关的API,之前讲的不再进行介绍,想了解的可以看我之前的文章:

C# Solidworks二次开发:向量相关的数学函数API的使用介绍_solidworks二次开发中矩阵变换函数-CSDN博客下面介绍向量其它的相关API:

(1)第一个为Add ,这个API的含义为把一个向量添加到另一个向量中,下面是API的解释:

其输入的参数值只有一个,就是Math vector。

其返回值在成功的时候返回的是Math vector,在失败的时候返回的是null。

下面几个API也会涉及vector,这里我运用官方的例子对其进行使用展示:

This example shows how to get the outline of a solid body. This example also creates and inserts a sketch of that outline.

//-----------------------------------------------------
// Preconditions: Open a part document that contains
// at least one solid body.
//
// Postconditions: Processes the body outline curves
// to remove gaps before sketching the outline.
//-----------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace GetBodyOutline2_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        PartDoc swPart;
        ModelDoc2 swModel;
        MathVector swMathVector;
        MathUtility swMathUtility;
        Modeler swModeler;
        object dirVar;
        object[] bVar;
        DispatchWrapper[] arrBodiesIn = new DispatchWrapper[1];
        object[] Bodies = new object[1];
        object curveOut;
        object topol;
        object outline;
        double[] sEva;
        double[] eEva;
        double[] sEvaPrev;
        double[] eEvaPrev;
        double[] sEvaNext;
        double[] eEvaNext;
        double[] dirArr = new double[3];
        double s;
        double e;
        int nCt;
        int i;
        int v;
        bool isClosed;
        bool isPer;

        public enum direction
        {
            X = 1,
            Y = 2,
            Z = 3,
            Xminus = 4,
            Yminus = 5,
            Zminus = 6
        }

        public void Main()
        {
            swPart = (PartDoc)swApp.ActiveDoc;
            swModel = (ModelDoc2)swPart;

            

            //Get the bodies in this part
            bVar = (object[])swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);
            int bdycnt = bVar.GetLength(0);

            for (i = 0; i < bdycnt; i++)
            {
                Bodies[i] = bVar[i];
                arrBodiesIn[i] = new DispatchWrapper(Bodies[i]);
            }



            swModeler = (Modeler)swApp.GetModeler();
            swMathUtility = (MathUtility)swApp.GetMathUtility();

            //Create the direction vector
            dirArr[0] = 0;
            dirArr[1] = 0;
            dirArr[2] = 0;

            direction userDirection = default(direction);
            userDirection = direction.Y;

            if (userDirection == direction.X)
            {
                dirArr[0] = 1;
            }
            else if (userDirection == direction.Xminus)
            {
                dirArr[0] = -1;
            }
            else if (userDirection == direction.Y)
            {
                dirArr[1] = 1;
            }
            else if (userDirection == direction.Yminus)
            {
                dirArr[1] = -1;
            }
            else if (userDirection == direction.Z)
            {
                dirArr[2] = 1;
            }
            else if (userDirection == direction.Zminus)
            {
                dirArr[2] = -1;
            }

            dirVar = dirArr;

            //Create a MathVector
            swMathVector = (MathVector)swMathUtility.CreateVector((dirArr));

            //Get the number of curves in the body outline
            nCt = swModeler.GetBodyOutline2((arrBodiesIn), swMathVector, 0.00001, true, out curveOut, out topol, out outline);
            Object[] crvOut = (Object[])curveOut;
            
            //Open a 3D sketch in the part document
            swModel.Insert3DSketch();

            //Using the end conditions of the curves, create a 2D sketch of each curve
            Curve[] vCurve = null;
            int newCt = 0;

            for (i = 0; i <= nCt - 1; i++)
            {
                ((Curve)crvOut[i]).GetEndParams(out s, out e, out isClosed, out isPer);
                if (((Curve)crvOut[i]).GetLength3(s, e) > 1E-05)
                {
                    Array.Resize(ref vCurve, newCt + 1);
                    vCurve[newCt] = (Curve)crvOut[i];

                    newCt = newCt + 1;
                }
            }

            double[] sPoints = null;
            double[] ePoints = null;

            sPoints = new double[(newCt * 3)];
            ePoints = new double[(newCt * 3)];

            for (i = 0; i <= newCt - 1; i++)
            {
                vCurve[i].GetEndParams(out s, out e, out isClosed, out isPer);
                sEva = (double[])vCurve[i].Evaluate(s);
                eEva = (double[])vCurve[i].Evaluate(e);

                if (i > 0)
                {
                    v = i - 1;
                }
                else
                {
                    v = newCt - 1;
                }

                vCurve[v].GetEndParams(out s, out e, out isClosed, out isPer);
                sEvaPrev = (double[])vCurve[v].Evaluate(s);
                eEvaPrev = (double[])vCurve[v].Evaluate(e);

                if (i < newCt - 1)
                {
                    v = i + 1;
                }
                else
                {
                    v = 0;
                }

                vCurve[v].GetEndParams(out s, out e, out isClosed, out isPer);
                sEvaNext = (double[])vCurve[v].Evaluate(s);
                eEvaNext = (double[])vCurve[v].Evaluate(e);

                sPoints[i * 3] = sEva[0] + 0.5 * (eEvaPrev[0] - sEva[0]);
                sPoints[i * 3 + 1] = sEva[1] + 0.5 * (eEvaPrev[1] - sEva[1]);
                sPoints[i * 3 + 2] = sEva[2] + 0.5 * (eEvaPrev[2] - sEva[2]);

                ePoints[i * 3] = eEva[0] + 0.5 * (sEvaNext[0] - eEva[0]);
                ePoints[i * 3 + 1] = eEva[1] + 0.5 * (sEvaNext[1] - eEva[1]);
                ePoints[i * 3 + 2] = eEva[2] + 0.5 * (sEvaNext[2] - eEva[2]);

                if (userDirection == direction.X | userDirection == direction.Xminus)
                {
                    sPoints[i * 3] = 0;
                    ePoints[i * 3] = 0;
                }
                else if (userDirection == direction.Y | userDirection == direction.Yminus)
                {
                    sPoints[i * 3 + 1] = 0;
                    ePoints[i * 3 + 1] = 0;
                }
                else if (userDirection == direction.Z | userDirection == direction.Zminus)
                {
                    sPoints[i * 3 + 2] = 0;
                    ePoints[i * 3 + 2] = 0;
                }
            }

            for (i = 0; i <= (newCt * 3) - 1; i += 3)
            {
                swModel.CreateLine2(sPoints[i], sPoints[i + 1], sPoints[i + 2], ePoints[i], ePoints[i + 1], ePoints[i + 2]);
            }

            //Insert the sketches
            swModel.InsertSketch2(true);
            swModel.ClearSelection2(true);

        }

        public SldWorks swApp;

    }
}

(2)第二个为Normalise,这个API的含义获取此数学向量的单位长度向量,下面是API的解释:

其没有输入参数,输出参数为向量。

(3)第三个为Scale,这个API的含义为将这个数学向量的大小,安一个因子缩放,并返回一个新的数学向量,下面是其API的解释:

今天这篇文章要介绍的就是这三个API,我们下篇文章再见。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/800515.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C# Solidworks二次开发:涉及主框架相关API详解(第二讲)

大家好&#xff0c;今天要介绍的是和主框架Frame相关的几个API&#xff0c;之前我也在一篇文章中提过一些&#xff0c;没看过的家人可以看一下&#xff1a; C# Solidworks二次开发&#xff1a;获取主窗口API和创建新活动窗口API详解_solidworks二次开发c#-CSDN博客 下面介绍一…

Vue主流UI框架

Vue UI框架是一系列专为Vue.js应用程序设计的用户界面&#xff08;UI&#xff09;组件库&#xff0c;这些组件库提供了预封装的、可复用的UI元素&#xff0c;如按钮、表格、输入框、导航菜单、提示框、卡片、布局容器等&#xff0c;帮助开发者快速构建美观且功能完善的前端界面…

【C++初阶】第九站:vector的介绍及使用

前言&#xff1a; &#x1f3af;个人博客&#xff1a;Dream_Chaser &#x1f388;博客专栏&#xff1a;C &#x1f4da;本篇内容&#xff1a;vector的介绍及使用 ​ 目录 一、vector的介绍 二、vector的使用 1.vector的定义 2.vector iterator(迭代器)的使用 begin和end(…

Spring Boot:数据库的整合

Spring Boot 前言Spring Boot 整合 JDBCSpring Boot 整合 Druid 数据源Spring Boot 整合 MyBatisSpring Boot 整合 JPA 前言 在 Spring Boot &#xff1a;Web开发之视图模板技术的整合 文章中&#xff0c;介绍了 Spring Boot 整合视图模板技术。然而&#xff0c;仅仅整合视图模…

用选择法对数组中10个整数按由小到大排序

#include <stdio.h> /** * 主函数&#xff1a;通过用户输入创建一个数组&#xff0c;并将其进行排序后打印。 */ int main(){ // 定义一个排序函数&#xff0c;接受一个整型数组和数组长度作为参数 void sort (int array[],int n); int a[10],i; // 定义一个…

.net框架和c#程序设计第二次测试

一、实验内容 1、设计一个用户登录页面webform1.aspx&#xff0c;效果如下图所示&#xff1a; 2、点击webform1.aspx中“还未注册”连接进入register.aspx&#xff0c;注册页面效果如下图所示&#xff1a;点击用户注册信息到usershow.aspx页面&#xff0c;并显示注册的用户信息…

思迈特:“人工智能+”浪潮里,国产BI到了关键时刻

作为首个“AI程序员”&#xff0c;Devin最近参与了一系列工作&#xff0c;包括在人力资源外包平台Upwork完成编程工作&#xff1b;潜入一家明星创业公司内部群交流&#xff0c;为公司CTO调整代码方案等。这让整个软件工程行业大受震撼&#xff0c;程序员留言“刷屏”。 “AI…

机器视觉学习(十二)—— 绘制图形

目录 一、绘制函数参数说明 1.1 cv2.line(&#xff09;绘制直线 1.2 cv2.rectangle&#xff08;&#xff09;绘制矩形 1.3 cv2.circle&#xff08;&#xff09; 绘制圆形 1.4 cv2.ellipse&#xff08;&#xff09;绘制椭圆 1.5 cv2.polylines&#xff08;&#xff09;绘制…

第十三届蓝桥杯b组做题笔记

&#xff08;7&#xff09;积木画 题目&#xff1a; 小明最近迷上了积木画, 有这么两种类型的积木, 分别为 &#xfffd;I 型&#xff08;大小为 2 个单位面积) 和 &#xfffd;L 型 (大小为 3 个单位面积): 同时, 小明有一块面积大小为 2&#xfffd;2N 的画布, 画布由 2&am…

【学习】软件测试中为什么要进行接口测试?

接口测试是软件开发过程中不可或缺的一环&#xff0c;它主要是对软件系统中各个模块之间的接口进行测试&#xff0c;以验证它们是否能够正确地交互和协作。接口测试的目的是确保软件系统的各个部分能够无缝地协同工作&#xff0c;从而提高整个系统的质量和稳定性。 一、什么是接…

Web API(三)之事件流事件委托其他事件

Web API(三)之事件流&事件委托&其他事件 事件流捕获和冒泡事件捕获事件冒泡阻止冒泡解绑事件两种注册事件的区别事件委托其他事件页面加载事件元素滚动事件页面滚动事件-获取位置页面滚动事件-滚动到指定的坐标页面尺寸事件元素尺寸与位置元素尺寸与位置-尺寸

深入探究:if、elif、else语句如何塑造Python代码的逻辑魅力

欢迎来CILMY23的博客 本篇主题为 深入探究&#xff1a;if、elif、else语句如何塑造Python代码的逻辑魅力 个人主页&#xff1a;CILMY23-CSDN博客 个人专栏系列&#xff1a; Python | C语言 | 数据结构与算法 | C 感谢观看&#xff0c;支持的可以给个一键三连&#xff0c;点…

递归的层次处理-组合总数

给定一个候选人编号的集合 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用 一次 。 注意:解集不能包含重复的组合。 示例 1: 输入: candidates = [10,1,2,7,6,1,5], target = 8, 输…

JavaSE-10笔记【多线程1(+2024新)】

文章目录 1.进程与线程2.并发与并行3.线程的调度模型4.实现线程4.1 第一种方式&#xff1a;继承Thread4.2 第二种方式&#xff1a;实现Runnable接口4.3 t.start()和t.run()的本质区别&#xff1f;4.4 线程常用的三个方法 5.线程的生命周期&#xff08;把生命周期图背会&#xf…

python实例2.2:编写一个装饰器,计算任何一个函数执行的时间(详解及其知识点拓展)

目录 一、编写一个装饰器,计算任何一个函数执行的时间 二、装饰器详解,及其用法举例

蓝桥杯 历届真题 双向排序【第十二届】【省赛】【C组】

资源限制 内存限制&#xff1a;256.0MB C/C时间限制&#xff1a;1.0s Java时间限制&#xff1a;3.0s Python时间限制&#xff1a;5.0s 改了半天只有60分&#xff0c;还是超时&#xff0c;还不知道怎么写&#xff0c;后面再看吧┭┮﹏┭┮ #include<bits/stdc.h> …

十四、Shell 脚本中的 printf 命令

注&#xff1a; 本文只是博主学习记录分享&#xff0c;仅供参考。如有错误肯定是博主理解有问题&#xff0c;谢谢&#xff01; printf 命令在 Shell 脚本中用于格式化输出。它提供了更灵活和强大的格式化功能&#xff0c;默认不会像 echo 命令自动添加换行符&#xff0c;需要手…

在线聊天使用说明

功能 支持世界聊天没有人数限制支持个人聊天支持群聊(没开放)支持通讯录支持添加好友支持添加群(没开放)支持emoji表情后期会支持发送图片现在还不支持 现有问题可能样式兼容还有点问题, 以后有时间在处理, 目前能正常聊天 入口 聊天入口: https://huanmin.top/#/chat 功…

必知必会!使用NumPy对数组进行拆分

使用NumPy对数组进行拆分是一种高效且灵活的数据处理方式。NumPy提供了多种函数&#xff0c;如numpy.split(), numpy.hsplit(), 和 numpy.vsplit()&#xff0c;使得数组可以根据不同的需求进行拆分。这些函数能够精确控制拆分的数量和位置&#xff0c;满足不同的数据处理和分析…

2024/4/1—力扣—按摩师

代码实现&#xff1a; 思路&#xff1a;打家劫舍题 int massage(int *nums, int numsSize) {if (nums NULL || numsSize 0) {return 0;}if (numsSize 1) {return nums[0];}int dp[numsSize];memset(dp, 0, sizeof(dp));dp[0] nums[0];dp[1] (nums[0] < nums[1] ? nums…