计算点和值
 
 

By using the methods provided by the Editor object and the Geometry and Runtime namespaces, you can quickly solve a mathematical problem or locate points in your drawing. Some of the available methods are:

使用 Editor 对象 和 Geometry 与 Runtime 命令空间提供的方法,用户可以快速在图形中解决数学问题或定位点。以下是一些可用的方法:

NoteThe .NET API does not contain methods to calculate a point based on a distance and angle (polar point) and for translating coordinates between different coordinate systems. If you need these utilities, you will want to utilize the PolarPoint and TranslateCoordinates methods from the ActiveX Automation library.

注意 .NET API 不包含根据距离和角度计算点(极坐标点)和在两个不同的坐标系统中转换坐标的方法 。如果你需要这些功能,就得使用 ActiveX Automation 库的 PolarPointTranslateCoordinates 方法。

获得与X轴形成的角度

This example calculates a vector between two points and determines the angle from the X-axis.

本例计算两个点之间的矢量并求出与X轴形成的角度。

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("AngleFromXAxis")> _
Public Sub AngleFromXAxis()
  Dim pt1 As Point2d = New Point2d(2, 5)
  Dim pt2 As Point2d = New Point2d(5, 2)
 
  Application.ShowAlertDialog("Angle from XAxis: " & _
                              pt1.GetVectorTo(pt2).Angle.ToString())
End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("AngleFromXAxis")]
public static void AngleFromXAxis()
{
  Point2d pt1 = new Point2d(2, 5);
  Point2d pt2 = new Point2d(5, 2);
 
  Application.ShowAlertDialog("Angle from XAxis: " +
                              pt1.GetVectorTo(pt2).Angle.ToString());
}
VBA/ActiveX 代码参考

计算极坐标点

This example calculates a point based on a base point, an angle and distance.

本例根据基点、角度和距离计算一个点。

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
 
Public Shared Function PolarPoints(ByVal pPt As Point2d, _
                                   ByVal dAng As Double, _
                                   ByVal dDist As Double)
 
  Return New Point2d(pPt.X + dDist * Math.Cos(dAng), _
                     pPt.Y + dDist * Math.Sin(dAng))
End Function
 
Public Shared Function PolarPoints(ByVal pPt As Point3d, _
                                   ByVal dAng As Double, _
                                   ByVal dDist As Double)
 
  Return New Point3d(pPt.X + dDist * Math.Cos(dAng), _
                     pPt.Y + dDist * Math.Sin(dAng), _
                     pPt.Z)
End Function
 
<CommandMethod("PolarPoints")> _
Public Sub PolarPoints()
  Dim pt1 As Point2d
  pt1 = PolarPoints(New Point2d(5, 2), 0.785398, 12)
 
  Application.ShowAlertDialog(vbLf & "PolarPoint: " & _
                              vbLf & "X = " & pt1.X & _
                              vbLf & "Y = " & pt1.Y)
 
  Dim pt2 As Point3d
  pt2 = PolarPoints(New Point3d(5, 2, 0), 0.785398, 12)
 
  Application.ShowAlertDialog(vbLf & "PolarPoint: " & _
                              vbLf & "X = " & pt2.X & _
                              vbLf & "Y = " & pt2.Y & _
                              vbLf & "Z = " & pt2.Z)
End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
 
static Point2d PolarPoints(Point2d pPt, double dAng, double dDist)
{
  return new Point2d(pPt.X + dDist * Math.Cos(dAng),
                     pPt.Y + dDist * Math.Sin(dAng));
}
 
static Point3d PolarPoints(Point3d pPt, double dAng, double dDist)
{
  return new Point3d(pPt.X + dDist * Math.Cos(dAng),
                     pPt.Y + dDist * Math.Sin(dAng),
                     pPt.Z);
}
 
[CommandMethod("PolarPoints")]
public static void PolarPoints()
{
  Point2d pt1 = PolarPoints(new Point2d(5, 2), 0.785398, 12);
 
  Application.ShowAlertDialog("\nPolarPoint: " +
                              "\nX = " + pt1.X +
                              "\nY = " + pt1.Y);
 
  Point3d pt2 = PolarPoints(new Point3d(5, 2, 0), 0.785398, 12);
 
  Application.ShowAlertDialog("\nPolarPoint: " +
                              "\nX = " + pt2.X +
                              "\nY = " + pt2.Y +
                              "\nZ = " + pt2.Z);
}
VBA/ActiveX 代码参考

使用 GetDistance 方法找出两点间的距离

This example uses the GetDistance method to obtain two points and displays the calculated distance.

本例使用 GetDistance 方法获得两个点并显示计算的距离。

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
 
<CommandMethod("GetDistanceBetweenTwoPoints")> _
Public Sub GetDistanceBetweenTwoPoints()
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
 
  Dim pDblRes As PromptDoubleResult
  pDblRes = acDoc.Editor.GetDistance(vbLf & "Pick two points: ")
 
  Application.ShowAlertDialog(vbLf & "Distance between points: " & _
                              pDblRes.Value.ToString())
End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
 
[CommandMethod("GetDistanceBetweenTwoPoints")]
public static void GetDistanceBetweenTwoPoints()
{
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
  PromptDoubleResult pDblRes;
  pDblRes = acDoc.Editor.GetDistance("\nPick two points: ");
 
  Application.ShowAlertDialog("\nDistance between points: " +
                              pDblRes.Value.ToString());
}
VBA/ActiveX 代码参考