72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace VisionCommon {
|
|
/// <summary>
|
|
/// 수평/수직 라인의 방향 타입
|
|
/// </summary>
|
|
public enum eLineDirection {
|
|
/// <summary>수평 라인</summary>
|
|
H,
|
|
/// <summary>수직 라인</summary>
|
|
V
|
|
}
|
|
|
|
/// <summary>
|
|
/// 시작과 끝점을 가지는 직선
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class Line<T> where T : DoublePoint {
|
|
/// <summary>직선의 시작점</summary>
|
|
public T StartPoint { get; set; }
|
|
|
|
/// <summary>직선의 끝점</summary>
|
|
public T EndPoint { get; set; }
|
|
|
|
/// <summary>직선의 길이</summary>
|
|
public double Length {
|
|
get {
|
|
return MathUtil.CalculateDistance(StartPoint, EndPoint);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="startPoint">시작점</param>
|
|
/// <param name="endPoint">끝점</param>
|
|
public Line(T startPoint, T endPoint) {
|
|
StartPoint = startPoint;
|
|
EndPoint = endPoint;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 수평/수직 라인 방향을 결정
|
|
/// </summary>
|
|
/// <param name="angle">각도</param>
|
|
/// <returns>라인 방향 (수평 or 수직)</returns>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|