当前位置: 首页 > 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; // 相同平面不转换
    }
}

相关文章:

  • 基于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最新-智慧小区物业管理系统
  • 京伦科技网站做的怎么样/怎么做百度推广的代理
  • 建设公司网站开发方案/免费正规大数据查询平台
  • 东南亚做棋牌网站/百度网站的网址
  • 外贸公司的网站建设模板下载/江北seo页面优化公司
  • 网站建设吗/手机网站百度关键词排名查询
  • 中山技术支持中山网站建设/南宁seo公司