123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /////////////////////////////////////////
- //Copyright (c) 2016, SAGA
- //All rights reserved.
- //文件名称: PointDistanceInfo.cs
- //文件描述: 包含点线面的功能类
- //创 建 者: ly
- //创建日期: 2016-2-25
- //版 本 号:1.0.0.0
- ////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using Autodesk.Revit.DB;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- namespace SAGA.RevitUtils.Extends
- {
- public class PointDistanceInfo
- {
- public PointDistanceInfo(XYZ p1, XYZ p2)
- {
- this.P1 = p1;
- this.P2 = p2;
- }
- public XYZ P1 { get; private set; }
- public XYZ P2 { get; private set; }
- private double _mDistance = -1;
- public double Distance
- {
- get
- {
- if (_mDistance < 0)
- {
- _mDistance = P1.DistanceTo(P2);
- }
- return _mDistance;
- }
- }
- public static Line CreateLongLine(XYZ[] points)
- {
- PointDistanceInfo max = Max(points);
- if (max.P1.DistanceTo(max.P2).IsLess(0.1d))
- return null;
- return max.P1.NewLine( max.P2);
- }
- public static PointDistanceInfo Min(PointDistanceInfo a, PointDistanceInfo b)
- {
- if (a.Distance == b.Distance)
- {
- return a;
- }
- if (a.Distance > b.Distance)
- {
- return b;
- }
- return a;
- }
- public static PointDistanceInfo Max(PointDistanceInfo a, PointDistanceInfo b)
- {
- if (a.Distance == b.Distance)
- {
- return a;
- }
- if (a.Distance > b.Distance)
- {
- return a;
- }
- return b;
- }
- public static PointDistanceInfo Max(PointDistanceInfo[] items)
- {
- if (items == null || items.Length <= 0)
- throw new ArgumentNullException("items");
- PointDistanceInfo maxResult = items[0];
- for (int i = 1; i < items.Length; i++)
- {
- maxResult = Max(maxResult, items[i]);
- }
- return maxResult;
- }
- public static PointDistanceInfo Min(PointDistanceInfo[] items)
- {
- if (items == null || items.Length <= 0)
- throw new ArgumentNullException("items");
- PointDistanceInfo minResult = items[0];
- for (int i = 1; i < items.Length; i++)
- {
- minResult = Min(minResult, items[i]);
- }
- return minResult;
- }
- public static PointDistanceInfo Max(XYZ[] ps)
- {
- if (ps == null || ps.Length < 2)
- {
- throw new ArgumentException("ps");
- }
- PointDistanceInfo[] distances = FromPoints(ps);
- if (distances.Length <= 0)
- throw new ArgumentException("ps");
- return Max(distances);
- }
- public static PointDistanceInfo Min(XYZ[] ps)
- {
- if (ps == null || ps.Length < 2)
- {
- throw new ArgumentException("ps");
- }
- PointDistanceInfo[] distances = FromPoints(ps);
- if (distances.Length <= 0)
- throw new ArgumentException("ps");
- return Min(distances);
- }
- public static PointDistanceInfo[] FromPoints(XYZ[] points)
- {
- List<PointDistanceInfo> listDistanceInfos = new List<PointDistanceInfo>();
- for (int i = 0; i < points.Length; i++)
- {
- for (int j = i + 1; j < points.Length; j++)
- {
- listDistanceInfos.Add(new PointDistanceInfo(points[i], points[j]));
- }
- }
- return listDistanceInfos.ToArray();
- }
- }
- }
|