7,765
社区成员
发帖
与我相关
我的任务
分享
public Point[] GetPoint(Point a, Point c, int m)
{
}
/// <summary>
/// 获取线点a(x1, y1) 点b(x2, y2)平行向左右移动offset后的矩形区域
/// </summary>
/// <param name="p_p1"></param>
/// <param name="p_p2"></param>
/// <param name="p_offset"></param>
/// <returns></returns>
public Point[] GetPoints(int x1, int y1, int x2, int y2, int p_offset)
{
double k = (((x2 - x1) == 0) ? 0 : (double)(y2 - y1) / (x2 - x1));
double sink = Math.Pow(Math.Pow(k, 2) / (1 + Math.Pow(k, 2)), 1 / 2);
double cosk = Math.Pow(1 / (Math.Pow(k, 2) + 1), 1 / 2);
if (k < 0)
cosk = -cosk;
else if ((y2 - y1) == 0)
sink = 0;
else if ((x2 - x1) == 0)
cosk = 0;
double ax = x1 + p_offset * sink;
double ay = y1 - p_offset * cosk;
double bx = x1 - p_offset * sink;
double by = y1 + p_offset * cosk;
double cx = x2 + p_offset * sink;
double cy = y2 - p_offset * cosk;
double dx = x2 - p_offset * sink;
double dy = y2 + p_offset * cosk;
Point a = new Point((int)ax, (int)ay);
Point c = new Point((int)cx, (int)cy);
Point b = new Point((int)bx, (int)by);
Point d = new Point((int)dx, (int)dy);
return new Point[] { a, c, d, b };
}
(x-x1)^2 + (y-y1)^2 = m^2 ....................................(1)
y=kx + b .......................................................(2)
其中 b 不定,k即为上述的k,该方程表示一簇直线