【问题标题】:DrawEllipse from two joint (Point, or rather X and Y coordinates)DrawEllipse 从两个关节(点,或者更确切地说是 X 和 Y 坐标)
【发布时间】:2015-01-10 17:57:09
【问题描述】:

我希望通过椭圆而不是线来显示骨架。我有两个坐标为 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]);

【问题讨论】:

  • 您收到的 exact 错误消息是什么?见stackoverflow.com/help/mcvestackoverflow.com/help/how-to-ask
  • 我没有错误,但我没有按照我的意愿显示骨架。椭圆不通过点,我不知道如何设置radiusY。上面我发布了一个屏幕,我认为它更复杂,因为移动骨骼时 x 和 y 会发生变化
  • 您可以在点之间制作一条虚拟线,然后在大虚拟线的顶部和底部创建两条旋转 90 度的较小虚拟线(如总线的 15%)。现在只需获取线的旋转(Math.atan2)并绘制一个旋转的椭圆。 i.imgur.com/XybEThO.png
  • 哪一行得到轮换?

标签: c# kinect ellipse skeleton-code


【解决方案1】:

您不能(仅)使用 DrawEllipse 方法,因为它总是会绘制水平或垂直椭圆。

使用此代码实现旋转:https://stackoverflow.com/a/5298921/1974021 并编写一个采用以下输入参数的方法:

  1. 联络点1
  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);
}

【讨论】:

  • 谢谢,我想用椭圆代替骨架线。我试图使用你的代码,但我在上面的代码中调用它,我没有你的参数
猜你喜欢
  • 2017-04-25
  • 1970-01-01
  • 2022-01-16
  • 2022-11-13
  • 1970-01-01
  • 1970-01-01
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多