简体   繁体   English

来自两个关节的DrawEllipse(点,或者X和Y坐标)

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

I'm looking to show skeleton by ellipse and not by line. 我希望按椭圆而不是按行显示骨架。 I have two Point with coordinates for X and Y. When i want to draw an ellipse i need 我有两个坐标为X和Y的点。当我想绘制一个椭圆时,我需要

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

)

so i have tried with this code but there is some error(don't know 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);

Can anyone help me? 谁能帮我?

在此处输入图片说明

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]);

You cannot (just) use the DrawEllipse method, because that will always draw horizontal or vertical elipses. 您不能(只是)使用DrawEllipse方法,因为它将始终绘制水平或垂直椭圆。

Use this code to implement the rotation: https://stackoverflow.com/a/5298921/1974021 and write a method that takes the following input parameters: 使用以下代码实现旋转: https : //stackoverflow.com/a/5298921/1974021并编写一个采用以下输入参数的方法:

  1. Focalpoint1 Focalpoint1
  2. FocalPoint2 FocalPoint2
  3. Radius 半径

As an ellipse can be described by both focal points and a (combined) radius. 椭圆可以通过焦点和(组合)半径来描述。 If you use the focal points, the ellipsis will overlap at the joints to create a circle-like pattern at each joint. 如果使用焦点,则省略号将在关节处重叠,从而在每个关节处创建一个圆形图案。 Is that about what you want? 那就是你想要的吗? (It is even easier if you only want them to touch at the joint) (如果只希望他们触摸关节,这会更加容易)

Okay, it's actually not the focal point but the center of the osculating circle. 好的,它实际上不是焦点,而是圆弧的中心。 Try this method: 试试这个方法:

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