c# - 无论起点如何,我都想按顺序保持圆上的点
问题描述
我的程序正在圆上创建随机点。我想将这些点分别保存在一个数组中。例如,首先我选择一个随机点(例如,让它是 p1),然后我将它们顺时针排序并添加到一个数组中。
而且我正在分享我的程序代码,你可能想看看。
public void producePoint()
{
double angle;
PointF org = new PointF(250, 250);
float rad = 250;
for (int i = 0; i < Int32.Parse(totalTextBox.Text); i++)
{
points[i] = new Points();
angle = random.Next(0, 360);
points[i].name = "P" + i.ToString();
points[i].coordX = (float)(rad * Math.Cos(angle * Math.PI / 180F)) + org.X + area.X+10;
points[i].coordY = (float)(rad * Math.Sin(angle * Math.PI / 180F)) + org.Y + area.Y+10;
}
}
public void DrawLine(string a , string b)
{
Points point1 = new Points();
Points point2 = new Points();
for (int i = 0; i < Int32.Parse(totalTextBox.Text); i++)
{
if (points[i].name == a)
{
point1 = points[i];
}
if (points[i].name == b)
{
point2 = points[i];
}
if (a == b)
{
point1 = point2;
}
}
private void drawL_Click(object sender, EventArgs e)
{
if (firstPointComboBox.SelectedItem == null || secondPointComboBox.SelectedItem == null)
{
MessageBox.Show("Please,choose points");
}
else
{
DrawLine(firstPointComboBox.SelectedItem.ToString(), secondPointComboBox.SelectedItem.ToString());
}
}
解决方案
推荐阅读
- crm - SuiteCRM 中的多租户
- c++ - std::bit_cast 产生多个值的值表示的示例是什么?
- c - 在 C 中使用 libmodbus 实现 modbus 网关功能
- powershell - WebBrowser 对象的 PowerShell 事件处理
- c# - 向模板添加其他签名
- excel - Excel VBA:为什么空白单元格的ColorIndex似乎是-4142
- python - 如何找到经验数据集(股票收益)的最佳拟合参数分布?
- python - 成功确认后,发布/订阅消息仍未传递
- r - 遍历 URL 列表并仅保留那些存在的 URL
- php - 具有代码覆盖率的 Laravel 单元测试抛出 ReflectionException