【问题标题】:Creating a 3D cordinate in C#在 C# 中创建 3D 坐标
【发布时间】:2021-10-20 02:17:52
【问题描述】:

其实我已经设计了一个C#程序来控制CNC机器,例如,我们可以拿UGS,有很多软件,但我需要用C#创建这个。我在这里唯一受苦的是3D坐标系。如何在 3D 中创建轴图。示例:Planet Cnc 的“Cnc USB 控制器”我想用 C# 创建这个软件。

【问题讨论】:

  • public record Vector3d(float X, float Y, float Z); - 不确定您是否要求超出此范围的内容...一些edit 可能有助于将问题缩小到单个编码问题并使问题更容易回答...
  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。
  • 我建议查看 helix 3d,他们有一些关于如何设置 3D 视图的示例。但是你的问题很不清楚。我建议对 c# 中的 3D 图形如何工作进行一些基础研究,并将问题限制在特定问题上。

标签: c# controller cnc


【解决方案1】:

我会尽我所能回答,但你应该考虑定义你想要实现的范围,即如果你只想要一个坐标系或一个 UI 来配合它,比如 UGS。

仅制作坐标系的最佳方法是定义您需要的所有数据,例如位置、旋转、进给、快速、偏移等。然后将所有这些数据包装在一个类中以用于机器状态,并提供帮助您的方法操作数据。

例子

public struct Vector3 
{
    public float x,y,z
}

public struct Rotation 
{
    public float x,y,z //Or whatever your machine uses, the 5 axis at my work is v,w for rotation. 
                       //I recommend leaving it as x,y,z though cause it will make it more robust as you 
                       //can use the same code on different machines by interpreting the values differently later on.
                       //Alternatively you could use a Quaternion if need but most machines interprat eular angles just fine without gimble lock.
}

//only if you need scale. stay away from this if you can help it, it will make zeroing harder because you will have to use matrix math to make the position and rotation work properly with it(I could be wrong about that though).
public struct Scale 
{
    public float x,y,z
}

public struct Transform 
{
    public Vector3 position;
    public Rotation rotation;
}

//then create a class to define the state of the machine.
public class MachineState 
{
    public bool rapid = false;
    public bool feed = false;
    public bool flood = false;
    public bool mist = false;
    public Transform transform;
    
    //An example of a method to manipulate the data.
    public Vector3 CalculateOffset (Vector3 offsetPosition, Vector3 offset) 
    {
        //Add your offset logic here.
    } 
}

如果您也需要 UI,那么我建议您使用 .net MUAI 或 Windows 窗体,它们中的任何一个都应该可以直接创建一个 UI 来使用这些数据,以及添加 3D 视图和您能想到的任何其他内容的。

.Net MAUI: https://docs.microsoft.com/en-us/dotnet/maui/what-is-maui

Windows 窗体: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/?view=netdesktop-5.0

我希望这能帮助你走上正确的道路,但也对我所说的一切持保留态度,因为我以前从未编写过操纵 cnc 机器的程序。

我只是对它们进行操作和数据分析。不过,我确实对坐标系有很多了解,因为我曾经是一名游戏开发人员。

【讨论】:

  • 我会非常害怕使用在不同环境中可能会有不同解释的欧拉角。我强烈主张指定使用哪种变体。或者只是使用四元数,让其他东西担心如何将其转换为机器中的旋转。此外,system.Numerics 库几乎提供了 3D 矢量和变换的所有基本类。
猜你喜欢
  • 1970-01-01
  • 2016-05-25
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
  • 2014-11-13
  • 2014-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多