我正在尝试围绕表单中心的圆圈移动图片框。由于舍入问题,我在准确描述图片框应出现的位置时遇到问题。我的数据的一个子集可能反映以下内容:
109.023696905025,151.715396359085
109.041149311463,152.715244054241
109.0586017179,153.715091749398
109.076054124337,154.714939444554
109.093506530774,155.714787139711
109.110958937212,156.714634834867
109.128411343649,157.714482530023
109.145863750086,158.71433022518
控件的Location
字段仅接受Point
,这会截断我的点小数位,从而在绘制时产生类似六边形的形状。我正在使用以下代码块来创建我的坐标:
double x1 = pictureBox1.Location.X;
double y1 = pictureBox1.Location.Y;
double cx = (double)this.Width / 2;
double cy = (double)this.Height / 2;
double radius = Math.Sqrt(Math.Pow(cx - x1, 2) + Math.Pow(cy - y1, 2));
double arc = Math.Atan((y1 - cy) / (x1 - cx));
double x = cx + radius * Math.Cos(arc + Math.PI - (Math.PI / 180.0));
double y = cy + radius * Math.Sin(arc + Math.PI - (Math.PI / 180.0));
考虑到创建Point
对象时的不准确性,以及 x 和 y 代表我的点,我怎样才能准确地绘制我的代码生成的点以更准确?
Console.WriteLine("{0},{1}",x, y);
pictureBox1.Location = new Point((int)x, (int)y); // Only takes integers, which results in the irregular path.