WPF에서 Point List로 타원을 만들고 싶습니다.

WPF에서 List에 좌표를 넣고 타원을 만들고싶습니다.
사용한 방법으로는 베지어 세그먼트, 폴리 베지어세그먼트들을 사용했었는데
그래도 타원이 시작부분과 끝부분이 각이 지게 생성이됩니다.
그래서 좌표들 사이에 중간점을 보정점으로 추가를 해주었는데, 여전히 각이 살짝 생겨서 고민입니다.

아래는 제가 실행한 코드입니다.
private PathFigure UpdateBezierCurve(List data)
{
PathGeometry pathGeometry = new PathGeometry();

        PathFigure pathFigure = new PathFigure
        {
            StartPoint = padPoint[0],
            IsClosed = true
        };

        PointCollection points = new PointCollection();

        for (int i = 1; i < data.Count; i++)
        {
            points.Add(data[i]);
        }

        PolyQuadraticBezierSegment polyBezierSegment = new PolyQuadraticBezierSegment();
        polyBezierSegment.Points = points;
        polyBezierSegment.IsSmoothJoin = true;

        pathFigure.Segments.Add(polyBezierSegment);
        pathGeometry.Figures.Add(pathFigure);

        return pathFigure;
    }

소중한 조언 부탁드립니다.

2개의 좋아요
2개의 좋아요

EllipseGeometry의 경우 Center 점을 구해서 Radius X, Y를 조절하거나, 경계의 사각형을 정의해서 안에 원을 그리는 형식으로 알고있습니다.
저는 Point들을 통과하는 타원을 그리고싶은데 혹시 다른 필드나 메서드가 있을까요?

1개의 좋아요

참고한 글
C# Helper: Draw a smooth closed curve in WPF and C# (csharphelper.com)
C# Helper: Draw a smooth curve in WPF and C# (csharphelper.com)

// Make an array containing Bezier curve points and control points.
private Point[] MakeClosedCurvePoints(Point[] points, double tension)
{
    if (points.Length < 2) return null;
    double control_scale = tension / 0.5 * 0.175;

    // Make a list containing the points and
    // appropriate control points.
    List<Point> result_points = new List<Point>();
    result_points.Add(points[0]);

    int num_points = points.Length;
    for (int i = 0; i < num_points; i++)
    {
        // Get the point and its neighbors.
        Point pt_before = points[(i - 1 + num_points) % num_points];

        Point pt = points[i];
        Point pt_after = points[(i + 1) % num_points];

        Point pt_after2 = points[(i + 2) % num_points];

        double dx1 = pt_after.X - pt_before.X;
        double dy1 = pt_after.Y - pt_before.Y;

        Point p1 = points[i];
        Point p4 = pt_after;

        double dx = pt_after.X - pt_before.X;
        double dy = pt_after.Y - pt_before.Y;
        Point p2 = new Point(
            pt.X + control_scale * dx,
            pt.Y + control_scale * dy);

        dx = pt_after2.X - pt.X;
        dy = pt_after2.Y - pt.Y;
        Point p3 = new Point(
            pt_after.X - control_scale * dx,
            pt_after.Y - control_scale * dy);

        // Save points p2, p3, and p4.
        result_points.Add(p2);
        result_points.Add(p3);
        result_points.Add(p4);
    }

    // Return the points.
    return result_points.ToArray();
}

// Make a Path holding a series of Bezier curves.
// The points parameter includes the points to visit
// and the control points.
private Path MakeBezierPath(Point[] points)
{
    // Create a Path to hold the geometry.
    Path path = new Path();

    // Add a PathGeometry.
    PathGeometry path_geometry = new PathGeometry();
    path.Data = path_geometry;

    // Create a PathFigure.
    PathFigure path_figure = new PathFigure();
    path_geometry.Figures.Add(path_figure);

    // Start at the first point.
    path_figure.StartPoint = points[0];

    // Create a PathSegmentCollection.
    PathSegmentCollection path_segment_collection =
        new PathSegmentCollection();
    path_figure.Segments = path_segment_collection;

    // Add the rest of the points to a PointCollection.
    PointCollection point_collection =
        new PointCollection(points.Length - 1);
    for (int i = 1; i < points.Length; i++)
        point_collection.Add(points[i]);

    // Make a PolyBezierSegment from the points.
    PolyBezierSegment bezier_segment = new PolyBezierSegment();
    bezier_segment.Points = point_collection;

    // Add the PolyBezierSegment to othe segment collection.
    path_segment_collection.Add(bezier_segment);

    return path;
}

// Make a Bezier curve connecting these points.
private Path MakeCurve(Point[] points, double tension)
{
    if (points.Length < 2) return null;
    Point[] result_points = MakeClosedCurvePoints(points, tension);

    // Use the points to create the path.
    return MakeBezierPath(result_points.ToArray());
}
2개의 좋아요

'점 목록(Point List)'으로 하나의 '타원’을 ‘일반적으로’ 만들 수 없습니다.
이것은 '세 점’이 주어지면 한 직선을 만들 수 없는 경우가 생기는 것과 같은 이치입니다.
'평면의 결정 조건’이 '서로 다른 세 점’이라는 말을 상기하시기 바랍니다.

아래 타원에 관한 설명 참고하시기 바랍니다.

2개의 좋아요