• NXOpen 求点到边的垂线并结合UF求起始点终点交点


    VS2010 NX8.5

    //创建垂线
    Features::AssociativeLine *nullFeatures_AssociativeLine(NULL);

    Features::AssociativeLineBuilder *associativeLineBuilder1;
    associativeLineBuilder1 = workPart->BaseFeatures()->CreateAssociativeLineBuilder(nullFeatures_AssociativeLine);
    Plane *plane1;
    plane1 = workPart->Planes()->CreatePlane(Facemidpoint, oneFaceVec1, SmartObject::UpdateOptionWithinModeling);
    Unit *unit1;
    unit1 = associativeLineBuilder1->Limits()->StartLimit()->Distance()->Units();
    associativeLineBuilder1->Limits()->StartLimit()->Distance()->SetRightHandSide("0");
    associativeLineBuilder1->SetStartPointOptions(Features::AssociativeLineBuilder::StartOptionPoint);
    associativeLineBuilder1->StartAngle()->SetRightHandSide("0");
    associativeLineBuilder1->EndAngle()->SetRightHandSide("270");
    associativeLineBuilder1->Limits()->StartLimit()->SetLimitOption(GeometricUtilities::CurveExtendData::LimitOptionsAtPoint);
    associativeLineBuilder1->Limits()->StartLimit()->Distance()->SetRightHandSide("0");
    associativeLineBuilder1->Limits()->EndLimit()->SetLimitOption(GeometricUtilities::CurveExtendData::LimitOptionsAtPoint);
    associativeLineBuilder1->Limits()->EndLimit()->Distance()->SetRightHandSide("0");
    associativeLineBuilder1->SetStartPointOptions(Features::AssociativeLineBuilder::StartOptionInferred);
    associativeLineBuilder1->Limits()->StartLimit()->Distance()->SetRightHandSide("0");
    associativeLineBuilder1->Limits()->EndLimit()->Distance()->SetRightHandSide("0");
    associativeLineBuilder1->SetStartPointOptions(Features::AssociativeLineBuilder::StartOptionPoint);
    associativeLineBuilder1->Limits()->SetFullCircle(false);

    Point *pointA = workPart->Points()->CreatePoint(Facemidpoint);//面中心点
    Xform *nullXform(NULL);
    Point *point2;
    point2 = workPart->Points()->CreatePoint(pointA, nullXform, SmartObject::UpdateOptionWithinModeling);
    associativeLineBuilder1->StartPoint()->SetValue(point2);
    associativeLineBuilder1->SetEndPointOptions(Features::AssociativeLineBuilder::EndOptionAtAngle);
    associativeLineBuilder1->Limits()->EndLimit()->SetLimitOption(GeometricUtilities::CurveExtendData::LimitOptionsValue);
    associativeLineBuilder1->Limits()->SetFullCircle(false);
    associativeLineBuilder1->Limits()->StartLimit()->Distance()->SetRightHandSide("0");
    Edge *edge1 = dynamic_cast<Edge *>(selectEdgs[0]);//选择的边
    associativeLineBuilder1->EndAtAngle()->SetValue(edge1);
    associativeLineBuilder1->EndAtAngle()->SetValue(NULL);
    associativeLineBuilder1->Limits()->SetFullCircle(false);
    associativeLineBuilder1->Limits()->StartLimit()->Distance()->SetRightHandSide("0");
    associativeLineBuilder1->EndAtAngle()->SetValue(edge1);
    associativeLineBuilder1->Limits()->EndLimit()->Distance()->SetRightHandSide(doubleToNXString(distance1+1));//线的长度
    associativeLineBuilder1->SetAssociative(true);

    //NXObject *nXObject1;
    //nXObject1 = associativeLineBuilder1->Commit();
    Features::Feature *associativelin1;
    associativelin1 = associativeLineBuilder1->CommitFeature();

    associativeLineBuilder1->Destroy();

    //sprintf_s(msg, "%d", associativelin1->Tag());
    //theSession->ListingWindow()->WriteLine(msg);

    Line *line1(dynamic_cast<Line *>(associativelin1->FindObject("CURVE 1")));//垂线转换
    //求线的起点和终点
    UF_CURVE_line_t line_coords;
    UF_CURVE_ask_line_data(line1->Tag(), &line_coords );
    sprintf_s(msg, "垂线起点 x:%.2f,y:%.2f,z:%.2f", line_coords.start_point[0],line_coords.start_point[1],line_coords.start_point[2]);
    theSession->ListingWindow()->WriteLine(msg);
    sprintf_s(msg, "垂线终点 x:%.2f,y:%.2f,z:%.2f", line_coords.end_point[0],line_coords.end_point[1],line_coords.end_point[2]);
    theSession->ListingWindow()->WriteLine(msg);
    //求交点
    double ref_point [ 3 ];// = {Facemidpoint.X,Facemidpoint.Y,Facemidpoint.Z}
    UF_CURVE_intersect_info_t out_info;
    UF_CURVE_intersect(line1->Tag(), edge1->Tag(), ref_point, &out_info );

    sprintf_s(msg, "是否有交点%d", out_info.type_of_intersection);
    theSession->ListingWindow()->WriteLine(msg);
    sprintf_s(msg, "交点 x:%.2f,y:%.2f,z:%.2f", out_info.curve_point[0],out_info.curve_point[1],out_info.curve_point[2]);
    theSession->ListingWindow()->WriteLine(msg);

    怡宁塑胶模具设计
  • 相关阅读:
    Maven3-依赖
    Maven2-坐标
    使用VS Code开发Python
    WinDbg调试分析 asp.net站点 CPU100%问题
    asp.net core2 Centos上配置守护服务(Supervisor)
    asp.net core2部署到Centos上
    IntelliJ Error:Abnormal build process termination
    EF架构~codeFirst从初始化到数据库迁移
    office web apps 实现Wopi预览编辑
    office web apps安装教程
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14651402.html
Copyright © 2020-2023  润新知