如何解决在椭圆上找到一个点的角度以在 GDI+ 中使用
我正在尝试创建一个系统来在 2D 渲染格式(即 Direct2D 到 GDI+)之间转换弧参数。在 Direct2D 中,弧由起点、终点、半径、旋转角度、扫描方向和弧扫描大小(大于或小于 180)定义。在 GDI+ 中,它们由边界框、开始角度和结束角度(围绕水平轴)定义。
我需要从 Direct2D 格式转换为 GDI+ 格式。到目前为止,我已经能够生成边界框,但角度是关闭的。下面是我应该得到什么(Direct2D 版本)和我得到什么(在 GDI+ 中)的图像。
预期:
实际:
代码:
RectangleF bounds = GetBoundingBoxOfEllipse(startPoint,EndPoint,ArcRadii,RotationAngle);
PointF ctr = new PointF(bounds.Left + (bounds.Width / 2.0f),bounds.Top + (bounds.Height / 2.0f));
//I originally had +90 per the formula,but it was still wrong (too far the other way instead)
double ang1 = Math.atan2(ctr.X - startPoint.X,ctr.Y - startPoint.Y) * (180.0 / Math.PI);
if (ang1 < 0)
ang1 += 360.0;
double ang2 = Math.atan2(ctr.X - EndPoint.X,ctr.Y - EndPoint.Y) * (180.0 / Math.PI);
if (ang2 < 0)
ang2 += 360.0;
//Accounting for user options
double diffAng = Math.Abs(diffheading(ang1,ang2));
if (ArcSize == ID2D1PathGeometry.figure.ArcSegment.ArcSizeEnum.ArcSize_Large && diffAng < 180.0f)
diffAng += 180.0;
if (SweepDirection == ID2D1PathGeometry.figure.ArcSegment.SweepDirectionEnum.SweepDirection_Clockwise)
diffAng *= -1.0;
path.AddArc(new RectangleF(bounds.X,bounds.Y,bounds.Width,bounds.Height),(float)ang1,(float)diffAng);
任何帮助将不胜感激。我正在随意旋转这些形状来拉我的头发。提前致谢!
RectangleF GetBoundingBoxOfEllipse(PointF startPoint,PointF endPoint,Sizef radii,float rotAngle)
{
PointF v = new PointF((startPoint.X - endPoint.X) / 2.0f,(startPoint.Y - endPoint.Y) / 2.0f);
//rotate if needed later
double x1p = v.X;
double y1p = v.Y;
double rx = Math.Abs(radii.Width);
double ry = Math.Abs(radii.Height);
double lam = (Math.Pow(x1p,2.0) / Math.Pow(rx,2.0)) + (Math.Pow(y1p,2.0) / Math.Pow(ry,2.0));
if(lam > 1)
{
rx = Math.Sqrt(lam) * rx;
ry = Math.Sqrt(lam) * ry;
}
double sign = 1; //const sign = fa === fs ? -1 : 1;
double div = (rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p) /
(rx * rx * y1p * y1p + ry * ry * x1p * x1p);
double co = sign * Math.Sqrt(Math.Abs(div));
v = new PointF((float)(((rx * y1p) / ry) * co),(float)(((-ry * x1p) / rx) * co));
v.X += (startPoint.X + endPoint.X) / 2.0f;
v.Y += (startPoint.Y + endPoint.Y) / 2.0f;
return new RectangleF(v.X - (radii.Width),v.Y - (radii.Height),radii.Width * 2.0f,radii.Height * 2.0f);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。