ComputerGraphics/20210129/zzx-20210129作业/Method/VectorsMethod.cs
2021-02-25 15:53:31 +08:00

38 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GraphicsStudy
{
public static class VectorsMethod
{
/// <summary>
/// 向量是否平行
/// </summary>
/// <param name="vector1"></param>
/// <param name="vector2"></param>
/// <param name="v">true为同向平行false为反向平行null为平行</param>
/// <param name="tolerance">允许误差的角度</param>
/// <returns></returns>
public static bool IsParallel(this XYZ vector1, XYZ vector2, bool? v = null, double tolerance = 0.1)
{
if (v == null)
{
return vector1.AngleTo(vector2) > (180 - tolerance).ToRad() || vector1.DistanceTo(vector2) < tolerance.ToRad();
}
else if (v == true)
{
return vector1.AngleTo(vector2) < tolerance.ToRad();
}
else
{
return vector1.AngleTo(vector2) > (180 - tolerance).ToRad();
}
}
}
}