using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace VisionCommon { /// /// 수평/수직 라인의 방향 타입 /// public enum eLineDirection { /// 수평 라인 H, /// 수직 라인 V } /// /// 시작과 끝점을 가지는 직선 /// /// public class Line where T : DoublePoint { /// 직선의 시작점 public T StartPoint { get; set; } /// 직선의 끝점 public T EndPoint { get; set; } /// 직선의 길이 public double Length { get { return MathUtil.CalculateDistance(StartPoint, EndPoint); } } /// /// 생성자 /// /// 시작점 /// 끝점 public Line(T startPoint, T endPoint) { StartPoint = startPoint; EndPoint = endPoint; } /// /// 수평/수직 라인 방향을 결정 /// /// 각도 /// 라인 방향 (수평 or 수직) public static eLineDirection GetLineDirection(Angle angle) { // Cognex는 Line이 -180 ~ 180 Deg (MIL은 0 ~ 360) var absDeg = Math.Abs(angle.Degree); if (absDeg >= 0 && absDeg < 45) { return eLineDirection.H; } else if (absDeg >= 45 && absDeg < 135) { return eLineDirection.V; } else if (absDeg >= 135 && absDeg < 225) { return eLineDirection.H; } else if (absDeg >= 225 && absDeg < 315) { return eLineDirection.V; } else { return eLineDirection.H; } } } }