我目前正在尝试在圆内刻出十边形的对角线
i am currently try to inscribe diagonals of a decagon inside a circle
像这样
在C#中,我的方法是创建一个圆
in c# my approach would be creating a circle
e.Graphics.DrawEllipse(myPen, 0, 0, 100, 100);并使用
e.Graphics.DrawLine(myPen, 20, 5, 50, 50);之后,我将绘制一个十边形多边形.
after that i would draw a decagon polygon.
目前,我一直在研究如何将圆分成10个部分/在圆的圆周上找到正确的点的坐标,因为我的数学不佳, 我想知道我如何知道圆的圆周上的下一个点,如上所示. 而且我也想问一个更好的方法来解决我的问题.
currently im stuck at how to divide the circle into 10 parts/ finding the correct coordiantes of the points on the circumference of the circles because im not good in math, i want to know how would i know the next point in a circumference of the circle the size of my circle is indicated above. and also i want also to ask a better approach for my problem.
谢谢:)
推荐答案仅用于磨粒和胫骨,这是一个通用实现,将X面多边形刻入传递的Rectangle中.请注意,在这种方法中,我实际上并没有计算任何绝对点.取而代之的是,我平移原点,旋转曲面,并使用固定的长度和角度仅相对于原点绘制线条.循环重复此操作以达到下面的最终结果,与在中命令海龟非常相似.徽标:
Just for grits and shins, here's a generic implementation that will inscribe an X-sided polygon into the Rectangle you pass it. Note that in this approach I'm not actually calculating any absolute points. Instead, I am translating the origin, rotating the surface, and drawing the lines only with respect to the origin using a fixed length and an angle. This is repeated in a loop to achieve the end result below, and is very similar to commanding the Turtle in Logo:
public partial class Form1 : Form { PictureBox pb = new PictureBox(); NumericUpDown nud = new NumericUpDown(); public Form1() { InitializeComponent(); this.Text = "Inscribed Polygon Demo"; TableLayoutPanel tlp = new TableLayoutPanel(); tlp.RowCount = 2; tlp.RowStyles.Clear(); tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); tlp.ColumnCount = 2; tlp.ColumnStyles.Clear(); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.Dock = DockStyle.Fill; this.Controls.Add(tlp); Label lbl = new Label(); lbl.Text = "Number of Sides:"; lbl.TextAlign = ContentAlignment.MiddleRight; tlp.Controls.Add(lbl, 0, 0); nud.Minimum = 3; nud.Maximum = 20; nud.AutoSize = true; nud.ValueChanged += new EventHandler(nud_ValueChanged); tlp.Controls.Add(nud, 1, 0); pb.Dock = DockStyle.Fill; pb.Paint += new PaintEventHandler(pb_Paint); pb.SizeChanged += new EventHandler(pb_SizeChanged); tlp.SetColumnSpan(pb, 2); tlp.Controls.Add(pb, 0, 1); } void nud_ValueChanged(object sender, EventArgs e) { pb.Refresh(); } void pb_SizeChanged(object sender, EventArgs e) { pb.Refresh(); } void pb_Paint(object sender, PaintEventArgs e) { // make circle centered and 90% of PictureBox size: int Radius = (int)((double)Math.Min(pb.ClientRectangle.Width, pb.ClientRectangle.Height) / (double)2.0 * (double).9); Point Center = new Point((int)((double)pb.ClientRectangle.Width / (double)2.0), (int)((double)pb.ClientRectangle.Height / (double)2.0)); Rectangle rc = new Rectangle(Center, new Size(1, 1)); rc.Inflate(Radius, Radius); InscribePolygon(e.Graphics, rc, (int)nud.Value); } private void InscribePolygon(Graphics G, Rectangle rc, int numSides) { if (numSides < 3) throw new Exception("Number of sides must be greater than or equal to 3!"); float Radius = (float)((double)Math.Min(rc.Width, rc.Height) / 2.0); PointF Center = new PointF((float)(rc.Location.X + rc.Width / 2.0), (float)(rc.Location.Y + rc.Height / 2.0)); RectangleF rcF = new RectangleF(Center, new SizeF(1, 1)); rcF.Inflate(Radius, Radius); G.DrawEllipse(Pens.Black, rcF); float Sides = (float)numSides; float ExteriorAngle = (float)360 / Sides; float InteriorAngle = (Sides - (float)2) / Sides * (float)180; float SideLength = (float)2 * Radius * (float)Math.Sin(Math.PI / (double)Sides); for (int i = 1; i <= Sides; i++) { G.ResetTransform(); G.TranslateTransform(Center.X, Center.Y); G.RotateTransform((i - 1) * ExteriorAngle); G.DrawLine(Pens.Black, new PointF(0, 0), new PointF(0, -Radius)); G.TranslateTransform(0, -Radius); G.RotateTransform(180 - InteriorAngle / 2); G.DrawLine(Pens.Black, new PointF(0, 0), new PointF(0, -SideLength)); } } }
我在常规多边形计算器.
更多推荐
在圆上转录多边形
发布评论