从DXF文件中解析不完整的省略号

时间:2015-06-30 12:03:30

标签: c++ parsing angle ellipse dxf

我正在使用dxflib库开发DXF解析器。解析省略号时遇到问题。

当我解析椭圆时,我收到以下数据:

struct DL_EllipseData 
{
    /*! X Coordinate of center point. */
    double cx;
    /*! Y Coordinate of center point. */
    double cy;

    /*! X coordinate of the endpoint of the major axis. */
    double mx;
    /*! Y coordinate of the endpoint of the major axis. */
    double my;

    /*! Ratio of minor axis to major axis. */
    double ratio;
    /*! Startangle of ellipse in rad. */
    double angle1;
    /*! Endangle of ellipse in rad. */
    double angle2;
};

问题是,当angle1 != 0 AND angle2 != 2* Math.PI椭圆打开时,我无法计算代表该几何体的弧形路径。

例如,考虑以下椭圆:

enter image description here

这些是它的属性:

enter image description here

如您所见,角度为:

angle1 = 0.81855 // 46 degrees
angle2 = 2.38934 // 136 degrees

但是椭圆的图片(我从autocad中获取的角度似乎有不同的角度)。

跟随代表椭圆的DXF文件部分:

0
ELLIPSE
  5
A7
330
1F
100
AcDbEntity
  8
DL-Wall
 48
25.0
370
    -3
100
AcDbEllipse
 10
906.6576677029225
 20
906.657675539829
 30
0.0
 11
-641.4561777354752
 21
641.4561777354752
 31
0.0
210
0.0
220
0.0
230
1.0
 40
0.9999999999999978
 41
0.8185500151218715
 42
2.389346341916759

我如何计算正确的角度(以及开始弧段的终点)?

1 个答案:

答案 0 :(得分:1)

    /// <summary>
    ///     Static method to detemine the WPF end point of the arc.
    /// </summary>
    /// <param name="arc">The DXF ArcEntity object to evaluate</param>
    /// <returns>Point with values of the arc end point.</returns>
    public static Point calcEndPoint(Arc arc)
    {
        double x = (Math.Cos(arc.endAngle * (Math.PI / 180)) * arc.radius) + arc.center.X;
        double y = arc.center.Y - (Math.Sin(arc.endAngle * (Math.PI / 180)) * arc.radius);
        return new Point(x, y);
    }

    /// <summary>
    ///     Static method to detemine the WPF start point of the arc.
    /// </summary>
    /// <param name="arc">The DXF ArcEntity object to evaluate</param>
    /// <returns>Point with values of the arc start point.</returns>
    public static Point calcStartPoint(Arc arc)
    {
        double x = (Math.Cos(arc.startAngle * (Math.PI / 180)) * arc.radius) + arc.center.X;
        double y = arc.center.Y - (Math.Sin(arc.startAngle * (Math.PI / 180)) * arc.radius);
        return new Point(x, y);
    }

    public static bool checkArcSize(Arc arc)
    {
        double angleDiff = arc.endAngle - arc.startAngle;
        return !((angleDiff > 0 && angleDiff <= 180) || angleDiff <= -180);
    }

使用System.Windows.Media.Path,PathFigure,ArcSegment:

PathFigure figure = new PathFigure();
figure.StartPoint = calcStartPoint([your arc struct]);
ArcSegment arc = new ArcSegment();
arc.Point = calcEndPoints([your arc struct]);
arc.RotationAngle = Math.Abs(endAngle - startAngle);
arc.Size = new Size(radius, radius);
arc.IsLargeArc = checkArcSize([your arc struct]);
figure.Segments.Add(arc);

您需要调整每个辅助函数以使用结构以及语法中的任何C ++与C#差异。

我相信这些辅助函数将弥补DXF规范为您提供的内容与在WPF中绘制Arc所需的内容之间的差距。