private void pictureBox1_Click(object sender, EventArgs e) { Graphics gr = DrawCanvas.CreateGraphics(); double x, y, prevX = 0, prevY = 0; float a = 13, b = 7; float offsetX = DrawCanvas.Size.Width / 2; float offsetY = DrawCanvas float angleStep = 0.5f; for (float angle = 0; angle < 360; angle += angleStep) { x = (a + b) * Math.Cos(angle) - a * Math.Cos((a + b) * angle / a); y = (a + b) * Math.Sin(angle) - a * Math.Sin((a + b) * angle / a); if (angle > 0) { gr.DrawLine(new Pen(Color.Black), (float)prevX, (float)prevY, (float)x, (float)y); } prevX = x; prevY = y; } }
private void ProceedButton_Click(object sender, EventArgs e) { Graphics gr = DrawCanvas.CreateGraphics(); gr.Clear(Color.White); gr.TranslateTransform(DrawCanvas.Size.Width / 2.0f, DrawCanvas.Size.Height / 2.0f); if (PointGrid.RowCount < 4) { MessageBox.Show("Not enough points to build a triangle"); return; } // Перебор всех треугольников double minDiff = -1; bool setup = false; Triangle min = new Triangle(); for (int i = 0; i < PointGrid.RowCount - 1 && PointGrid[0, i] != null; i++) { for (int j = i; j < PointGrid.RowCount - 1 && PointGrid[0, j] != null; j++) { for (int k = j; k < PointGrid.RowCount - 1 && PointGrid[0, k] != null; k++) { bool success = true; double val1 = S2R(PointGrid[0, i].Value, ref success); double val2 = S2R(PointGrid[1, i].Value, ref success); double val3 = S2R(PointGrid[0, j].Value, ref success); double val4 = S2R(PointGrid[1, j].Value, ref success); double val5 = S2R(PointGrid[0, k].Value, ref success); double val6 = S2R(PointGrid[1, k].Value, ref success); if (!success) { continue; } Vertex a = new Vertex(val1, val2, i); Vertex b = new Vertex(val3, val4, j); Vertex c = new Vertex(val5, val6, k); Triangle triangle = new Triangle(a, b, c); if (triangle.IsDegenerate) { continue; } double diff = triangle.CircumcircleArea - triangle.Area; if (diff < minDiff || !setup) { setup = true; minDiff = diff; min = triangle; } } } } if (setup) { ResultLabel.Text = min + "\nTriange with minimum difference between circumircle and its own area."; } else { ResultLabel.Text = "No correct triangles found"; } min.DrawFitting(DrawCanvas); }