public static WPoint CalculateCubicBezierPoint(float t, WPoint wp1, WPoint wp2, WPoint wp3, WPoint wp4) { Point p1 = wp1.ToPoint(); Point p2 = wp2.ToPoint(); Point p3 = wp3.ToPoint(); Point p4 = wp4.ToPoint(); Point p = p1; float u = 1 - t; float tt = t * t; float uu = u * u; float uuu = uu * u; float ttt = tt * t; p.X *= uuu; p.Y *= uuu; p.X += 3 * uu * t * p2.X; p.Y += 3 * uu * t * p2.Y; p.X += 3 * u * tt * p3.X; p.Y += 3 * u * tt * p3.Y; p.X += ttt * p4.X; p.Y += ttt * p4.Y; return(new WPoint(p)); }
public void ClearPoint(WPoint wp) { if (canvas.Children.Contains(wp.Shell)) { canvas.Children.Remove(wp.Shell); } }
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { WPoint wp = new WPoint(Mouse.GetPosition(canvas)); switch (CommandBox.SelectedIndex) { case (int)Options.NewPoint: WChains[ChainBox.SelectedIndex].List.Add(wp); PointList.Add(wp.ToString()); if (WChains[ChainBox.SelectedIndex].List.Count > 1) { DM.DrawAdditionalPoint(WChains[ChainBox.SelectedIndex], wp); } break; case (int)Options.NewLine: WChains.Add(new WChain(wp)); int last = ChainList.Count; ChainList.Add(WChains[last].ToString(last)); SetChainBoxIndex(last); SetCommandBoxIndex((int)Options.NewPoint); break; } DM.DrawPoint(wp, Brushes.DarkCyan); }
public WChain(WPoint wp) { List = new List <WPoint>(); List.Add(wp); Shell = new Polyline(); QBShell = new Polyline(); CBShell = new Polyline(); Dump = new List <Polyline>(); }
public void DrawAdditionalPoint(WChain wc, WPoint wp) { Polyline pl = new Polyline(); pl.Points.Add(wc.List.Last().ToPoint()); pl.Points.Add(wc.List[wc.List.Count - 2].ToPoint()); wc.Dump.Add(pl); //не очень изящное решение, still it works pl.Stroke = Brushes.Black; if (!canvas.Children.Contains(pl)) { canvas.Children.Add(pl); } }
public void DrawPoint(WPoint wp, Brush b) { wp.Shell = new Rectangle(); wp.Shell.Stroke = Brushes.Black; wp.Shell.Fill = b; Canvas.SetTop(wp.Shell, wp.Ghost.Y - 3); Canvas.SetLeft(wp.Shell, wp.Ghost.X - 3); wp.Shell.HorizontalAlignment = HorizontalAlignment.Left; wp.Shell.VerticalAlignment = VerticalAlignment.Top; wp.Shell.Height = 6; wp.Shell.Width = 6; canvas.Children.Add(wp.Shell); }