簡體   English   中英

來自兩個關節的DrawEllipse(點,或者X和Y坐標)

[英]DrawEllipse from two joint (Point, or rather X and Y coordinates)

我希望按橢圓而不是按行顯示骨架。 我有兩個坐標為X和Y的點。當我想繪制一個橢圓時,我需要

public abstract void DrawEllipse(
Brush brush,
Pen pen,
Point center,
double radiusX,
double radiusY

所以我已經嘗試過使用此代碼,但是有一些錯誤(不知道radiusY):

 double centerX = (jointPoints[jointType0].X + jointPoints[jointType1].X) / 2;
        double centerY = (jointPoints[jointType0].Y + jointPoints[jointType1].Y) / 2;
        double radiusX =Math.Sqrt( (Math.Pow((jointPoints[jointType1].X - jointPoints[jointType0].X), 2)) + (Math.Pow((jointPoints[jointType1].Y - jointPoints[jointType0].Y), 2)));
        drawingContext.DrawEllipse(null, drawPen, new Point(centerX, centerY), radiusX, radiusX/5);

誰能幫我?

在此處輸入圖片說明

private void DrawBone(IReadOnlyDictionary<JointType, Joint> joints, IDictionary<JointType, Point> jointPoints, JointType jointType0, JointType jointType1, DrawingContext drawingContext, Pen drawingPen,List<JointType> badJoint)
    {
        Joint joint0 = joints[jointType0];
        Joint joint1 = joints[jointType1];

        // If we can't find either of these joints, exit
        if (joint0.TrackingState == TrackingState.NotTracked ||
            joint1.TrackingState == TrackingState.NotTracked)
        {
            return;
        }



        // We assume all drawn bones are inferred unless BOTH joints are tracked
        Pen drawPen = this.inferredBonePen;

        if ((joint0.TrackingState == TrackingState.Tracked) && (joint1.TrackingState == TrackingState.Tracked))
        {
            drawPen = drawingPen;
        }
        //If a bone makes parts of an one bad angle respect reference angle
        if (badJoint.Contains(jointType0) && badJoint.Contains(jointType0))
            drawPen = new Pen(Brushes.Red, 6);
        drawingContext.DrawLine(drawPen, jointPoints[jointType0], jointPoints[jointType1]);

您不能(只是)使用DrawEllipse方法,因為它將始終繪制水平或垂直橢圓。

使用以下代碼實現旋轉: https : //stackoverflow.com/a/5298921/1974021並編寫一個采用以下輸入參數的方法:

  1. Focalpoint1
  2. FocalPoint2
  3. 半徑

橢圓可以通過焦點和(組合)半徑來描述。 如果使用焦點,則省略號將在關節處重疊,從而在每個關節處創建一個圓形圖案。 那就是你想要的嗎? (如果只希望他們觸摸關節,這會更加容易)

好的,它實際上不是焦點,而是圓弧的中心。 試試這個方法:

private static void DrawEllipse(Pen pen, Graphics g, PointF pointA, PointF pointB, float radius)
{
    var center = new PointF((pointA.X + pointB.X) / 2, (pointA.Y + pointB.Y) / 2);
    var distance = GetDistance(pointA, pointB);

    // The axis are calculated so that the center of the osculating circles are conincident with the points and has the given radius.
    var a = radius + distance / 2; // Semi-major axis
    var b = (float)Math.Sqrt(radius * a); // Semi-minor axis


    // Angle in degrees
    float angle = (float)(Math.Atan2(pointA.Y - pointB.Y, pointA.X - pointB.X) * 180 / Math.PI);
    using (Matrix rotate = new Matrix())
    {
        GraphicsContainer container = g.BeginContainer();
        rotate.RotateAt(angle, center);
        g.Transform = rotate;
        g.DrawEllipse(pen, center.X-a, center.Y-b, 2 * a, 2 * b);
        g.EndContainer(container);
    }
}

private static float GetDistance(PointF a, PointF b)
{
    var dx = a.X - b.X;
    var dy = a.Y - b.Y;
    return (float)Math.Sqrt(dx * dx + dy * dy);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM