2011-10-15 9 views
9

¿Cuál es la mejor solución para obtener el punto medio de un ArcSegment en una ruta y etiquetarlo en WPF?Cómo obtener El punto medio de un ArcSegment en WPF

enter image description here

+0

Buena pregunta. Supongo que debes calcularlo según una combinación de radio y puntos medios. –

+0

Si el arco está de alguna manera ligado a datos a un modelo de vista, entonces puede agregar una propiedad con la posición correcta de la etiqueta al modelo de vista o implementar un convertidor que haga lo mismo. Por otro lado, si no está utilizando el enlace de datos, entonces simplemente puede calcular la posición de la etiqueta en el mismo lugar donde calcula los parámetros para el arco. Como ** Ritch ** señaló, puede calcular la posición en función de los puntos finales, el radio y el ángulo ... –

+0

¿Alguna muestra del código? – ARZ

Respuesta

7

Esto debería funcionar:

 //the given arc (or any other segments) 
     var arc = new ArcSegment(
      point: new Point(200, 100), 
      size: new Size(100, 50), 
      rotationAngle: 90, 
      isLargeArc: true, 
      sweepDirection: SweepDirection.Counterclockwise, 
      isStroked: true); 

     //compose one or more segments into a collection 
     var pathcoll = new PathSegmentCollection(); 
     pathcoll.Add(arc); 

     //create a figure based on the set of segments 
     var figure = new PathFigure(); 
     figure.Segments = pathcoll; 

     //compose a collection of figures 
     var figcoll = new PathFigureCollection(); 
     figcoll.Add(figure); 

     //create a path-geometry using the figures collection 
     var geom = new PathGeometry(figcoll); 

     double fraction = 0.5; //the relative point of the curve 
     Point pt;    //the absolute point of the curve 
     Point tg;    //the tangent point of the curve 
     geom.GetPointAtFractionLength(
      fraction, 
      out pt, 
      out tg); 

espero que ayude.

Cheers

+1

'GetPointAtFractionLength'.¡esto es exactamente lo que me necesitaban! Gracias. – ARZ

+0

varias horas de búsqueda más tarde y aquí estamos! ¡Gracias! – Craig

+0

GetPointAtFractionLength me ha solucionado muchos problemas. Gran descubrimiento! – Jon

Cuestiones relacionadas