WPF心形線演算法

傑克.陳發表於2018-09-21
原文:WPF 心形線演算法
今天在網上查詢下心形演算法公式,自己便按照公式寫下來標記在部落格,主要是方便以後檢視!

private int maxStep = 520; private double radius; private double centerPt; private void CreateHeartLine() { /*RootCvs是Canvas控制元件*/ centerPt = RootCvs.Width / 2; radius = RootCvs.Width / 6; for (int i = 0; i < maxStep; i++) { var rect = new Rectangle { Height = 5, Width = 5, Fill = Brushes.Red }; double angle = 2 * Math.PI / maxStep * i; double r = 2 * radius * (1 - Math.Sin(angle)); //圓形心 //double x = centerPt + radius * (2 * Math.Cos(angle) - Math.Cos(2 * angle)); //double y = centerPt + radius * (2 * Math.Sin(angle) - Math.Sin(2 * angle)); //桃形心 double x = centerPt + 16 * (Math.Sin(angle) * Math.Sin(angle) * Math.Sin(angle)) * 10;// double y = centerPt + (13 * Math.Cos(angle) - 5 * Math.Cos(2 * angle) - 2 * Math.Cos(3 * angle) - Math.Cos(4 * angle)) * 10;// Canvas.SetLeft(rect, x); Canvas.SetTop(rect, y); RootCvs.Children.Add(rect); } }

 


相關文章