using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
|
namespace IStation.WinFrmUI.Curve
|
{
|
/// <summary>
|
/// 几何辅助类
|
/// </summary>
|
public class GeomHelper
|
{
|
//判断是否是0点,用于判断函数是否成功返回
|
public static bool IsZeroPoint(Model.CurvePoint pt)
|
{
|
if (pt.X < 0.01 && pt.Y < 0.01)
|
return true;
|
else
|
return false;
|
}
|
|
|
//判断 是否在2个数之间
|
public static bool IsMiddlePt(double pt1, double pt2, double p)
|
{
|
if (p > pt1 && p < pt2)
|
return true;
|
|
if (p < pt1 && p > pt2)
|
return true;
|
|
return false;
|
}
|
|
//求2点的距离
|
public static double Distance(Model.CurvePoint pt1, Model.CurvePoint pt2)
|
{
|
return Math.Sqrt((pt1.X - pt2.X) * (pt1.X - pt2.X) + (pt1.Y - pt2.Y) * (pt1.Y - pt2.Y));
|
}
|
|
//点到线的距离
|
public static double Distance(Model.CurvePoint pt1, List<Model.CurvePoint> CurvePoints)
|
{
|
if (CurvePoints == null)
|
return 10000;
|
|
double min_dis = 10000;
|
double dis = 0;
|
foreach (Model.CurvePoint pt in CurvePoints)
|
{
|
dis = Distance(pt1, pt);
|
if (dis < min_dis)
|
min_dis = dis;
|
}
|
|
return min_dis;
|
}
|
|
//根据2点 产生矩形
|
public static Rectangle CreateRectangle(Point corner1, Point corner2)
|
{
|
int x = corner1.X < corner2.X ? corner1.X : corner2.X;
|
int y = corner1.Y < corner2.Y ? corner1.Y : corner2.Y;
|
int width = Math.Abs(corner1.X - corner2.X);
|
int height = Math.Abs(corner1.Y - corner2.Y);
|
return new Rectangle(x, y, width, height);
|
}
|
public static RectangleF CreateRectangle(PointF corner1, PointF corner2)
|
{
|
float x = corner1.X < corner2.X ? corner1.X : corner2.X;
|
float y = corner1.Y < corner2.Y ? corner1.Y : corner2.Y;
|
float width = Math.Abs(corner1.X - corner2.X);
|
float height = Math.Abs(corner1.Y - corner2.Y);
|
return new RectangleF(x, y, width, height);
|
}
|
|
public bool IsOverlap(RectangleF r1, RectangleF r2)
|
{
|
if (!(r1.Right < r2.Left) && !(r1.Bottom < r2.Top))
|
{
|
if (!(r2.Right < r1.Left))
|
{
|
return !(r2.Bottom < r1.Top);
|
}
|
|
return false;
|
}
|
|
return false;
|
}
|
|
}
|
}
|