C#Vector.Add with PointF

时间:2012-12-12 11:26:17

标签: c# vector drawing

我正在编写一个用于解释和绘制G-Code(用于CNC机器)的小程序

为了连接两条半径的线,我写了一个小程序,并且必须使用Vector.Add函数。

No code, had probelems with formatting :)
p1,p2,p3 are the three points 
p1->p2 = vector ab 
p2->p3 = vector bc 
eab = Unit vector ab 
ebc = Unit vector bc 
eres = resulting vector 

我的问题是:对于Vector.Add()操作,我需要VectorPointPointF不允许)但我必须使用PointF由于准确性。 我该怎么办?

eab = ab / ab.Length;
ebc = bc / bc.Length;
eres = Vector.Add(eab, ebc);
PointF test= new PointF();
test= Vector.Add(5 * eres, test ); 

我使用System.Windows.Drawing进行绘制,使用System.Windows.Base进行向量。

1 个答案:

答案 0 :(得分:0)

在System.Drawing.dll,名称空间System.Drawing中,有:

public struct Point { ... }
public struct PointF { ... }

的坐标分别为intSystem.Int32)和floatSystem.Single)。

在WindowsBase.dll,名称空间System.Windows中,有另一个

public struct Point { ... }

,其坐标为doubleSystem.Double)。

如果你需要两者,你可以

  • 将指令using System.Drawing;using System.Windows;放在文件的同一级别,然后在代码中提供全名(例如System.Winodws.Point而不是Point每当存在歧义时(即编译器需要时)。或者:
  • 只有一个using指令(您最常使用的指令),然后在您使用其他命名空间中的类型(如结构)时提供全名。或者:
  • 创建一个或多个using alias directives (see link)