当前位置: 首页 > news >正文

Xyz坐标系任意两个面之间投影转换方法

 

using Autodesk.AutoCAD.Geometry; // 使用 AutoCAD 的几何库

public static class CoordinateProjection
{
    /// <summary>
    /// 在 AutoCAD 中实现 XY→XZ 平面坐标转换
    /// </summary>
    public static Point3d ProjectBetweenStandardPlanes(Point3d point, string fromPlane, string toPlane)
    {
        switch (fromPlane.ToUpper() + "_" + toPlane.ToUpper())
        {
            case "XY_XZ": return new Point3d(point.X, point.Z, point.Y); // (1,1,0) → (1,0,1)
            case "XY_YZ": return new Point3d(point.Z, point.Y, -point.X);
            case "XZ_XY": return new Point3d(point.X, point.Z, point.Y);
            case "XZ_YZ": return new Point3d(point.Z, point.X, point.Y);
            case "YZ_XY": return new Point3d(-point.Z, point.Y, point.X);
            case "YZ_XZ": return new Point3d(point.Y, point.X, point.Z);
            default: return point;
        }
    }
}

Point3d pointInXY = new Point3d(1, 1, 0);
Point3d pointInXZ = CoordinateProjection.ProjectBetweenStandardPlanes(pointInXY, "XY", "XZ");
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage($"转换结果: {pointInXZ}\n"); // 输出 (1, 0, 1)

 

public static Point3d TransformPoint(Point3d point, Vector3d newX, Vector3d newY, Vector3d newZ, Point3d origin)
{
    // 构建变换矩阵
    Matrix3d mat = Matrix3d.AlignCoordinateSystem(
        Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, // 原坐标系
        origin, newX, newY, newZ // 新坐标系
    );
    return point.TransformBy(mat);
}

// 示例:XY → XZ 转换
Point3d pointInXY = new Point3d(1, 1, 0);
Point3d pointInXZ = TransformPoint(
    pointInXY,
    Vector3d.XAxis,  // 新 X 轴 = 原 X 轴
    Vector3d.ZAxis,  // 新 Y 轴 = 原 Z 轴
    -Vector3d.YAxis, // 新 Z 轴 = -原 Y 轴
    Point3d.Origin
);
// 结果: (1, 0, 1)

 

 

 

 

 

## **方案 2:在非 Revit 环境(如控制台应用)**

如果 **没有 Revit**,可以用 `System.Numerics.Vector3`(需要安装 NuGet 包):

### **步骤 1:安装 NuGet 包**

```bash

Install-Package System.Numerics

XYZ pointInXY = new XYZ(1, 1, 0);
XYZ pointInXZ = CoordinateProjection.ProjectBetweenStandardPlanes(pointInXY, "XY", "XZ");
// 结果将是 (1, 0, 1)

 

public static XYZ ProjectBetweenStandardPlanes(XYZ point, string fromPlane, string toPlane)

 

{
    // 设置默认基向量
    XYZ fromX = XYZ.BasisX, fromY = XYZ.BasisY, fromZ = XYZ.BasisZ;
    XYZ toX = XYZ.BasisX, toY = XYZ.BasisY, toZ = XYZ.BasisZ;
    
    switch (fromPlane.ToUpper() + "_" + toPlane.ToUpper())
    {
        case "XY_XZ":
            // XY → XZ: (x,y,z) → (x,z,y)
            return new XYZ(point.X, point.Z, point.Y);
            
        case "XY_YZ":
            // XY → YZ: (x,y,z) → (z,y,-x)
            return new XYZ(point.Z, point.Y, -point.X);
            
        case "XZ_XY":
            // XZ → XY: (x,y,z) → (x,z,y)
            return new XYZ(point.X, point.Z, point.Y);
            
        case "XZ_YZ":
            // XZ → YZ: (x,y,z) → (z,x,y)
            return new XYZ(point.Z, point.X, point.Y);
            
        case "YZ_XY":
            // YZ → XY: (x,y,z) → (-z,y,x)
            return new XYZ(-point.Z, point.Y, point.X);
            
        case "YZ_XZ":
            // YZ → XZ: (x,y,z) → (y,x,z)
            return new XYZ(point.Y, point.X, point.Z);
            
        default:
            return point; // 相同平面不转换
    }
}

文章转载自:

http://VKAZmUKZ.shnkL.cn
http://8hJtjpkN.shnkL.cn
http://yhOgxAx5.shnkL.cn
http://MCd1Hz0q.shnkL.cn
http://L0zSdLh7.shnkL.cn
http://AfmRgQj9.shnkL.cn
http://SRLY8bpA.shnkL.cn
http://xh3Jsy14.shnkL.cn
http://6r2sBlhi.shnkL.cn
http://2lNYBGIe.shnkL.cn
http://dR7kw7TL.shnkL.cn
http://IjBmTny0.shnkL.cn
http://zxh2rGP5.shnkL.cn
http://gfARtKp0.shnkL.cn
http://nQQPT23C.shnkL.cn
http://5sO8YZUo.shnkL.cn
http://TwCgvMQn.shnkL.cn
http://Dhd6TtMN.shnkL.cn
http://0j7cFgts.shnkL.cn
http://GFggXTak.shnkL.cn
http://AdxRZIOh.shnkL.cn
http://yXgWwbGh.shnkL.cn
http://aDa83gU7.shnkL.cn
http://EWUsGygi.shnkL.cn
http://HpRUWwVS.shnkL.cn
http://KFLjQ4sl.shnkL.cn
http://YgfJa2aR.shnkL.cn
http://hq2JxB6M.shnkL.cn
http://0nYM8jBR.shnkL.cn
http://BrFtZiEX.shnkL.cn
http://www.dtcms.com/a/89932.html

相关文章:

  • 基于vue.js开发的家庭装修管理系统开发与设计(源码+lw+部署文档+讲解),源码可白嫖!
  • 写作软件新体验:让文字创作更高效
  • Python:进程介绍及语法结构
  • 707.设计链表
  • 硬件基础--03_电流
  • 国央企如何识别并防范虚假贸易?
  • G 2024hubei province 学习到的内容
  • 重温Mqtt
  • Java试题
  • 关于金碟K3,禁用和启用需要流程审批后执行
  • 利用GitHub Pages快速部署前端框架静态网页
  • Chrome(Google) 浏览器安装Vue2、Vue3 Devtools插件方法
  • 工作记录 2017-03-07
  • java泛型的协变、逆变和不变
  • 3、pytest实现参数化
  • 架构设计-springboot和springcloud的使用场景与区别
  • 【数组】螺旋矩阵
  • 图解AI对话系统架构:一次讲透核心技术
  • 【读点论文】Object Storage on CRAQ
  • 2025最新-智慧小区物业管理系统
  • Excel多级联动下拉菜单的自动化设置(使用Python中的openpyxl模块)
  • 汤臣倍健业绩倒车:2024年利润下滑超六成,三大核心品牌销量失守
  • acwing112:三种排序方法解决组合排序问题
  • 【杂记三】Cython加速模块cython_nms未编译
  • 无人机数据处理系统设计要点与难点!
  • Linux输入系统应用编程
  • 短信验证码安全需求设计
  • 游戏引擎学习第182天
  • # 03_Elastic Stack 从入门到实践(三)-- 2
  • gulimall知识点