【问题标题】:Print coordinates of convex polygons which are inside of another convex polygon in java打印java中另一个凸多边形内部的凸多边形的坐标
【发布时间】:2020-03-20 03:16:56
【问题描述】:

我正在绘制四个多边形。我需要确定其他多边形内的点的坐标。我已经在谷歌搜索但没有得到正确的代码。请在此处提出一种方法或使用我的一组坐标发布一些代码。

// Draw and fill polygons
import java.awt.Graphics;

public class Polygon2 extends java.applet.Applet
{
 int xCoords[] = { 10,90,200,270,200,90};
 int yCoords[] = { 50,20,20,50,130,130};
 //int xFillCoords[] = { 450, 600, 700, 550, 450, 450 };

 int x2Coords[] = { 120,230,200,150,100};
 int y2Coords[] = { 10,10,60,80,70};


 public void paint(Graphics g)
 {
  g.drawPolygon(xCoords, yCoords, 6);
  g.drawPolygon(x2Coords, y2Coords, 5);
  g.drawRect(60, 60, 30, 30);
  g.drawRect(100, 150, 150, 100); 
  //g.fillPolygon(xFillCoords, yCoords, 5);
 }
}

四个多边形

【问题讨论】:

  • This 可能会帮助您确定一个点是否在一个 poligon 内。

标签: java


【解决方案1】:

测试whether a point is in a polygon的问题有几个标准算法:这两个可能是最容易理解的。

  • The ray-casting algorithm - 从该点投射一条“射线”,并计算射线穿过多边形的多少条边。当且仅当它穿过奇数条边时,该点才在多边形中。
  • The winding number algorithm - 计算多边形围绕该点“绕”360 度的次数。当且仅当绕组数不为零时,该点才在多边形中。

这两种算法也适用于非凸多边形。除非这是一个学习练习,否则我建议您找到其中一种算法的现有实现,而不是自己编写。

【讨论】:

    猜你喜欢
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2019-02-14
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多