Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For those that can be interested by the WPF solution, I finally code this (not very optimized) based on the <code>QuadraticBezierSegment</code> and <code>PathGeometry</code> classes.</p> <p>Thanks very much to all of you. :)</p> <pre class="lang-cs prettyprint-override"><code>public partial class MainWindow : Window { int orientation = 1; int compt = 0; int SpikeWidth = 5; int SpikeHeigth = 3; public MainWindow() { InitializeComponent(); Polyline wave = new Polyline(); wave.Stroke = Brushes.Blue; wave.StrokeThickness = 2; PathGeometry pg = BezierPath.Data.GetFlattenedPathGeometry(); double CurveLenght = GetLength(pg, PathFigure.StartPoint); double NbrPoint = (Math.Round(CurveLenght / SpikeWidth)); for (int i = 0; i &lt;= NbrPoint; i++) { //Calcul de T double t = SpikeWidth * i / CurveLenght; Point TangentPoint; Point PointToDraw; pg.GetPointAtFractionLength(t, out PointToDraw, out TangentPoint); // Calcul de l'angle double a = Math.Atan2(TangentPoint.Y, TangentPoint.X); a += Math.PI / 2; //Alterner un point sur deux de chaque coté de la courbe if (compt % 2 == 0) orientation = 1; else orientation = -1; //Calcul du point et ajout à la polyligne. //Point calculation and added to the polyline. wave.Points.Add(new Point(Math.Cos(a) * SpikeHeigth * orientation + PointToDraw.X, Math.Sin(a) * SpikeHeigth * orientation + PointToDraw.Y)); //Compte le nombre de passage pour l'orientation compt += 1; } //Traçage sur la canvas cv.Children.Add(wave); } private double GetLength(PathGeometry pg, Point startPoint) { PolyLineSegment pls = pg.Figures[0].Segments[0] as PolyLineSegment; double distance = 0; foreach (Point pt in pls.Points) { distance += Math.Sqrt((startPoint.X - pt.X).Pow(2) + (startPoint.Y - pt.Y).Pow(2)); startPoint = pt; } return distance; } } </code></pre> <pre class="lang-xaml prettyprint-override"><code>&lt;Canvas x:Name="cv"&gt; &lt;Path Stroke="Black" x:Name="BezierPath"&gt; &lt;Path.Data&gt; &lt;PathGeometry&gt; &lt;PathGeometry.Figures&gt; &lt;PathFigureCollection&gt; &lt;PathFigure x:Name="PathFigure" StartPoint="10,400"&gt; &lt;PathFigure.Segments&gt; &lt;PathSegmentCollection&gt; &lt;QuadraticBezierSegment x:Name="BezierSegment" Point1="50,80" Point2="400,400"&gt; &lt;/QuadraticBezierSegment&gt; &lt;/PathSegmentCollection&gt; &lt;/PathFigure.Segments&gt; &lt;/PathFigure&gt; &lt;/PathFigureCollection&gt; &lt;/PathGeometry.Figures&gt; &lt;/PathGeometry&gt; &lt;/Path.Data&gt; &lt;/Path&gt; &lt;/Canvas&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload