大家好,又见面了,我是你们的朋友全栈君。
emgucv中没有根据给定点画圆弧的函数,自己写了一个,在此给出该函数。其中DrawPixel函数是将圆弧中的点标记一下,需要根据自己程序里的函数具体给出。
private void DrawArc( List<Point> points ) //三个点
{
double x1 = points[0].X;
double x2 = points[1].X;
double x3 = points[2].X;
double y1 = points[0].Y;
double y2 = points[1].Y;
double y3 = points[2].Y;
double x, y;
double r;
double a, b, c, d, e, f;
a = 2 * (x2 - x1);
b = 2 * (y2 - y1);
c = x2 * x2 + y2 * y2 - x1 * x1 - y1 * y1;
d = 2 * (x3 - x2);
e = 2 * (y3 - y2);
f = x3 * x3 + y3 * y3 - x2 * x2 - y2 * y2;
x = (b * f - e * c) / (b * d - e * a);
y = (d * c - a * f) / (b * d - e * a);
r = Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
double startAngle = Math.Atan2( points[0].Y-y, points[0].X-x );
double endAngle = Math.Atan2(points[2].Y - y, points[2].X - x);
double midAngle = Math.Atan2(points[1].Y - y, points[1].X - x);
double xi, yi; //循环过程中实时的点
double minAngle = startAngle <= endAngle ? startAngle : endAngle;
double maxAngle = startAngle <= endAngle ? endAngle : startAngle;
if (midAngle < minAngle || midAngle > maxAngle) //所需要画的弧穿越了二三象限的交线,需要分成2部分来画
{
xi = (r * Math.Cos(minAngle));
yi = (r * Math.Sin(minAngle));
do
{
if ((int)(x + xi + 0.5) >= 0 && (int)(x + xi + 0.5) < currentImage.Width && (int)(y + yi + 0.5) >= 0 && (int)(y + yi + 0.5) < currentImage.Height)
{
ps.Add(new Point((int)(x + xi + 0.5), (int)(y + yi + 0.5)));
currentImage[ps[ps.Count - 1].Y, ps[ps.Count - 1].X] = new Gray(255);
}
minAngle -= 0.001;
xi = (r * Math.Cos(minAngle));
yi = (r * Math.Sin(minAngle));
}
while (minAngle >= -Math.PI);
minAngle = maxAngle;
xi = (r * Math.Cos(minAngle));
yi = (r * Math.Sin(minAngle));
do
{
if ((int)(x + xi + 0.5) >= 0 && (int)(x + xi + 0.5) < currentImage.Width && (int)(y + yi + 0.5) >= 0 && (int)(y + yi + 0.5) < currentImage.Height)
{
drawPixel((int)(y + yi + 0.5) , (int)(x + xi + 0.5));
}
minAngle += 0.001;
xi = (r * Math.Cos(minAngle));
yi = (r * Math.Sin(minAngle));
}
while (minAngle <= Math.PI);
}
else //记录的三个点在圆上的点是按照从小到大的顺序排列的,从小到的顺序即可画完
{
xi = (r * Math.Cos(minAngle));
yi = (r * Math.Sin(minAngle));
do
{
if ((int)(x + xi + 0.5) >= 0 && (int)(x + xi + 0.5) < currentImage.Width && (int)(y + yi + 0.5) >= 0 && (int)(y + yi + 0.5) < currentImage.Height)
{
drawPixel((int)(y + yi + 0.5) , (int)(x + xi + 0.5));
}
minAngle += 0.001;
xi = (r * Math.Cos(minAngle));
yi = (r * Math.Sin(minAngle));
}
while (minAngle <= maxAngle);
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/125806.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...