2014-11-13 4 views
1

줄이 아닌 타원으로 뼈대를 표시하려고합니다. 내가두 개의 조인트에서 DrawEllipse (점 또는 오히려 X 및 Y 좌표)

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

필요 타원)

그래서 나는이 코드를 시도했지만 일부 오류가 발생을 그릴 할 때 나는 X와 Y 에 대한 좌표 두 점을 (모르는 반경 Y) :

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

아무도 도와 줄 수 있습니까? 즉, 항상 수평 또는 수직 elipses을 그릴 것 때문에

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

_exact_ 오류 메시지는 무엇입니까? http://stackoverflow.com/help/mcve 및 http://stackoverflow.com/help/how-to-ask를 참조하십시오. –

+0

오류가 없지만 원하는대로 스켈레톤을 표시하지 않습니다. 타원은 점들을 통과하지 않고 radiusY를 설정하는 방법을 모른다. 위 내가 i 화면에 게시 뼈를 움직일 때 x와 y가 바뀌기 때문에 더 복잡하다고 생각합니다. – luca

+0

점 사이에 가상 선을 만들 수 있으며 두 개의 90도 회전 된 작은 가상 선을 만들 수 있습니다 (총 15 % 라인) 큰 가상 라인의 상단과 하단. 이제 선 (Math.atan2)의 회전을 가져 와서 회전 된 타원을 그립니다. http://i.imgur.com/XybEThO.png – WebFreak001

답변

0

당신은 (단지)는 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); 
    } 
    
+0

감사합니다, 나는 타원으로 해골의 라인을 대체 할 것입니다. 귀하의 코드를 사용하려고했지만 위의 코드에서 호출하고 매개 변수가 없습니다. – luca