using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcEd = Autodesk.AutoCAD.EditorInput;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(TestVector.MyCommands))]
namespace TestVector
{
public class MyCommands
{
/// <summary>
/// Функция для получения перпендикуляра к вектору согласно
/// Arbitrary AutoCAD Algorithm
/// </summary>
/// <param name="zAxis"></param>
/// <returns></returns>
static AcGe.Vector3d GetArbPerpVector(AcGe.Vector3d zAxis)
{
AcGe.Vector3d xAxis;
const double kArbBound = 0.015625; // 1/64th
if ((Math.Abs(zAxis.X) < kArbBound) && (Math.Abs(zAxis.Y) < kArbBound))
xAxis = AcGe.Vector3d.YAxis.CrossProduct(zAxis);
else
xAxis = AcGe.Vector3d.ZAxis.CrossProduct(zAxis);
return xAxis.GetNormal();
}
[CommandMethod("TestVector")]
public void TestVector()
{
AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument;
AcEd.Editor ed = doc.Editor;
AcEd.PromptPointOptions pr =
new AcEd.PromptPointOptions("\nУкажите вектор для получения перпендикулярного (ENTER - завершение): ");
pr.AllowNone = true;
AcEd.PromptPointResult res;
while ((res = ed.GetPoint(pr)).Status == AcEd.PromptStatus.OK)
{
AcGe.Vector3d v = res.Value.GetAsVector();
v = v.GetNormal();
AcGe.Vector3d vPerp1 = v.GetPerpendicularVector(); // Стандартный алгоритм
AcGe.Vector3d vPerp2 = GetArbPerpVector(v); // Arbitrary алгоритм
ed.WriteMessage("\nPerp1 = ({0}) Perp2=({1})", vPerp1, vPerp2);
}
}
}
}