RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-561932

Mark Mindrin's questions

Martin Hope
Mark Mindrin
Asked: 2023-11-28 02:13:48 +0000 UTC

我无法基于随机给定点构建多边形 C# Windows 窗体

  • 8

我想根据给定的点构造一个多边形。为此,我执行格雷厄姆算法的第 1 点和第 2 点。接下来,我计划执行步骤 3,看看执行步骤 3 后点数组是否不同,因为如果是这样,那么我可以说最初多边形不是凸的。也就是说,我需要从位于随机坐标的随机数量的顶点构建一个多边形,然后判断构建的多边形是否是凸的。我受到这篇文章的启发:https://habr.com/ru/articles/144921/,但是,多边形尚未构建(我尚未开始第3步)。

我尝试了不同的方法,但最终选择了格雷厄姆的算法。显然,插入排序在其中无法正常工作,因为多边形的边有时会相交。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrueLab4_habrEdition
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Graphics g;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            g = CreateGraphics();
            Random random = new Random();
            int z = random.Next(6, 8);
            Point[] points = new Point[z];
            int[,] pointsS = new int[z, 2];
            Point[] newPoints = new Point[z];
            int[] P = new int[z];

            // генерация точек
            for (int i = 0; i < z; i++)
            {
                int x = random.Next(50, 100);
                int y = random.Next(70, 170);
                points[i] = new Point(x, y);
            }

            // заполнение массива индексов точек
            for (int i = 0; i < z; i++)
            {
                P[i] = i;
            }

            // копирование массива points в pointsS
            for (int i = 0; i < z; i++)
            {
                pointsS[i, 0] = points[i].X;
                pointsS[i, 1] = points[i].Y;
            }

            grahamscan(pointsS, P);

            int j = 0;
            for (int i = 0; i < P.Length; i++)
            { 
                int x = pointsS[P[i], 0];
                int y = pointsS[P[i], 1];
                newPoints[j++] = new Point(x, y);
                Console.WriteLine(P[i]);
            }
            show2d(pointsS);
            Pen pen = new Pen(Color.Red, 1);
            g.DrawPolygon(pen, newPoints);
        }
        void grahamscan(int[,] pointsS, int[]P)
        {
            for (int i = 1; i < pointsS.GetLength(0); i++) 
            {
                if (pointsS[P[i], 0] < pointsS[0, 0])
                {
                    (P[i], P[0]) = (P[0], P[i]);
                }
            }
            for (int i = 2; i < pointsS.GetLength(0); i++)
            {
                int j = i;
                int[] a = { pointsS[P[0], 0], pointsS[P[0], 1] };
                int[] b = { pointsS[P[j-1], 0], pointsS[P[j-1], 1] };
                int[] c = { pointsS[P[j], 0], pointsS[P[j], 1] };
                while (j > 1 && rotate(a, b, c) < 0)
                {
                    (P[j], P[j-1]) = (P[j-1], P[j]);
                    j -= 1;
                }
            }
        }
        double rotate(int[] A, int[] B, int[] C)
        {
            return (B[0] - A[0]) * (C[1] - B[1]) - (B[1] - A[1]) * (C[0] - B[0]);
        }

        void show2d(int[,] p)
        {
            for (int i = 0; i < p.GetLength(0); i++)
            {
                for (int j = 0; j < p.GetLength(1); j++)
                {
                    Console.Write(p[i, j] + "\t");
                }
                Console.WriteLine();
            }
        }
    }
}

在此输入图像描述

c#
  • 1 个回答
  • 30 Views
Martin Hope
Mark Mindrin
Asked: 2023-08-15 21:51:53 +0000 UTC

java中无法将字符串列表转换为二维数组

  • 5
public static String[][] toMatrix(List<String> data) {
    return data.stream()
        .map(str -> str.chars().mapToObj(e -> (char)e).collect(Collectors.toList()).stream().toArray(String[]::new))
        .toArray(String[][]::new);
} 

代码应该来自["aaa", "bbb", "ccc"]make[[a,a,a], [b,b,b], [c,c,c]]

java
  • 3 个回答
  • 41 Views
Martin Hope
Mark Mindrin
Asked: 2023-08-05 02:44:41 +0000 UTC

如何使用流 API 将 2D ArrayList<String> 转换为数组?

  • 4

创建 2D ArrayList:

ArrayList<String> map = new ArrayList<String>();
BufferedReader reader;
try {
    reader = new BufferedReader(new FileReader("map.txt"));
    String line = reader.readLine();
    while (line != null) {
        map.add(new String(line.strip()));
        line = reader.readLine();
    }
    reader.close();
} catch (IOException e) {
    e.printStackTrace();
}

我尝试以与JavaRush 文章中相同的方式转换为数组:

String[][] zzz = map.toArray(new String[map.size()][map.get(0).length()]);
java
  • 1 个回答
  • 54 Views
Martin Hope
Mark Mindrin
Asked: 2023-07-27 23:14:48 +0000 UTC

如何从java队列中的列表中获取数字?

  • 5
static void BFS(ArrayList<String> map, int [] s, int [] t){
    int n = map.size();
    int m = map.get(0).length();
    final int INF = (int) Math.pow(10, 9);
    int [][] delta = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
    int[][]arrayINFmap = new int[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            arrayINFmap[i][j] = INF;
        }
    }
    String[][]arrayTFmap = new String[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            arrayTFmap[i][j] = "False";
        }
    }
    // проблема тут
    ArrayDeque<List> deque = new ArrayDeque<>();
    arrayINFmap[s[0]][s[1]] = 0;
    arrayTFmap[s[0]][s[1]] = "True";
    deque.add(Arrays.asList(s));
    while (deque.size() != 0){
        int x = deque.peekFirst().get(0);
        int y = deque.peekFirst().get(1);
    }
}

тут проблема в том, что get возвращает Object. А мне int нужен
java
  • 1 个回答
  • 32 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5