今天在网上查找下心形算法公式,自己便按照公式写下来标记在博客,主要是方便以后查看!

        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);
}
}
05-11 22:06