1

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

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):

 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?

enter image description here

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]);
luca
  • 3,248
  • 10
  • 66
  • 145
  • What is the _exact_ error message you are getting? See http://stackoverflow.com/help/mcve and http://stackoverflow.com/help/how-to-ask – Peter Duniho Nov 13 '14 at 18:49
  • i don't have an error but i don't show the skeleton as i would like. The ellipse don't passing through the points and i don't know how to set radiusY. Above i post one screen I think that it is more complex because x and y change when move the bone – luca Nov 14 '14 at 08:09
  • You could make a virtual line between the points and then create two 90 deg rotated smaller virtual line (like 15% of the total line) at the top and bottom of the big virtual line. Now just get the rotation of the line (Math.atan2) and draw a rotated ellipse. http://i.imgur.com/XybEThO.png – WebFreak001 Nov 14 '14 at 13:52
  • which line i get the rotation? – luca Nov 19 '14 at 09:35

1 Answers1

-1

You cannot (just) use the DrawEllipse method, because that will always draw horizontal or vertical elipses.

Use this code to implement the rotation: https://stackoverflow.com/a/5298921/1974021 and write a method that takes the following input parameters:

  1. Focalpoint1
  2. 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);
}
Community
  • 1
  • 1
DasKrümelmonster
  • 5,816
  • 1
  • 24
  • 45
  • thanks, i would to substitute line of skeleton with ellipse. i have tried to use your code but I call it in above code and i don't have your parameters – luca Nov 14 '14 at 13:44