问题
我最近发现需要确定我的点是否在多边形内部。所以我学习了C++中的这种方法并将其改编到Python中。但是,我认为我正在研究的 C++ 代码不太正确?我相信我已经解决了这个问题,但我不太确定,所以我希望比我聪明的人可以帮助我解决这个问题?
这个定理非常简单,其想法是这样的,给定一个闭合多边形,你画一条任意的线,如果你的点在里面,你的线将与边缘相交奇数次。否则,你将是均匀的并且它在多边形之外。非常酷。
我有以下测试用例:
polygon_x = [5, 5, 11, 10]
polygon_y = [5, 10, 5, 10]
test1_x = 6
test1_y = 6
result1 = point_in_polygon(test1_x, test1_y, polygon_x, polygon_y)
print(result1)
test2_x = 13
test2_y = 5
result2 = point_in_polygon(test2_x, test2_y, polygon_x, polygon_y)
print(result2)
Run Code Online (Sandbox Code Playgroud)
如果我将其定义如下,则上面的内容都会为 false:
if polygon_x[i] < polygon_x[(i+1) % length]:
temp_x = polygon_x[i]
temp_y = polygon_x[(i+1) % length]
else:
temp_x = polygon_x[(i+1) % length]
temp_y = polygon_x[i]
Run Code Online (Sandbox Code Playgroud)
这是错误的!我应该先为true然后result1再false为result2。很明显,有些东西很时髦。 …
我正在使用 Three.js r83。
我试图动态地将点添加到几何体中,但场景永远不会更新。
这有效:
var tmaterial = new THREE.PointsMaterial({
color: 0xff0000,
size: 5,
opacity: 1
});
var tgeometry = new THREE.Geometry();
var pointCloud = new THREE.Points(tgeometry, tmaterial);
for(var i = 0; i< 1000; i++) {
x = (Math.random() * 200) - 100;
y = (Math.random() * 200) - 100;
z = (Math.random() * 200) - 100;
tgeometry.vertices.push(new THREE.Vector3(x, y, z));
}
tgeometry.verticesNeedUpdate = true;
tgeometry.computeVertexNormals();
scene.add(pointCloud);
Run Code Online (Sandbox Code Playgroud)
这不起作用:
var tmaterial = new THREE.PointsMaterial({
color: 0xff0000,
size: 5,
opacity: 1
}); …Run Code Online (Sandbox Code Playgroud) 我在 python 中使用 shapely 并尝试在网格中生成均匀间隔的点,这些点在最快的 O(n) 时间内落在形状内。形状可以是任何闭合多边形,而不仅仅是正方形或圆形。我目前的做法是:
有没有更快的方法来做到这一点?
# determine maximum edges
polygon = shape(geojson['features'][i]['geometry'])
latmin, lonmin, latmax, lonmax = polygon.bounds
# construct a rectangular mesh
points = []
for lat in np.arange(latmin, latmax, resolution):
for lon in np.arange(lonmin, lonmax, resolution):
points.append(Point((round(lat,4), round(lon,4))))
# validate if each point falls inside shape
valid_points.extend([i for i in points if polygon.contains(i)])
Run Code Online (Sandbox Code Playgroud)
给定2D平面中的两个点,以及与这两个点相交的半径r的圆,计算该圆的中心的公式是什么?
我意识到圆圈可以放置两个位置.我想要的是,当从任意角度开始扫描连接这些点中的一个点的两个点的线时,首先以顺时针方向遇到中心的圆.在我找到第一部分的答案后,我想这是我问题的下一个阶段.
我希望整个计算可以在没有三角法的情况下完成.我从整数坐标开始,如果有帮助,将以整数坐标结束.
我需要在具有一定宽度和高度的矩形上平均分配 N 个点。
前任。给定一个 10x10 的盒子和 100 个点,点将设置为:
(1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) (1,9) (1,10)
(2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8) (2,9) (2,10)
(3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8) (3,9) (3,10)
...
...
Run Code Online (Sandbox Code Playgroud)
我如何将其概括为任何 N 点、宽度和高度组合?
注意:它不需要是完美的,但很接近,无论如何我都会随机化一点(从 X 和 Y 轴上的这个“起点”移动点 +/- x 像素),所以有一个剩下的几个点在最后随机添加可能就好了。
我正在寻找这样的东西(准随机):

我正在使用这个FLANN匹配算法来匹配下面显示代码的2张图片中的兴趣点.
有一段时间代码找到匹配点列表:
std::vector<DMatch> good_matches;
Run Code Online (Sandbox Code Playgroud)
我想在两张图片中得到点定位(x,y).创建置换贴图.我怎样才能访问这些点本地化?
干杯,
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
void readme();
/** @function main */
int main(int argc, char** argv) {
if (argc != 3) {
readme();
return -1;
}
// Transform in GrayScale
Mat img_1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img_2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
// Checks if the image could be loaded
if (!img_1.data || !img_2.data) {
std::cout << " --(!) Error reading images " << std::endl;
return -1; …Run Code Online (Sandbox Code Playgroud) 我对6点的轮换感到不满.这些点围绕中间的中心点旋转.但是会发生的是形状区域缩小,变得越来越小.
形状的绘图在带有PaintComponent的i JPanel上进行.这意味着画布只支持整数定位,尽管我可以在双打中存储位置.
我使用Point2D.Double存储点位置I在每个函数调用时将所有点旋转1个deegre
我认为我对旋转的理解是缺乏的,我可以在一次调用中旋转360 deegre,或180,这样可以正常工作.但45 deegres或90将完全把我的点变成一条线(下图).
这个问题一直困扰着我一段时间,但一如既往,我确信有一个简单的解决方案.
这是旋转功能
@Override
public synchronized void rotatePoints(int move_x, int move_y) {
// TODO Auto-generated method stub
super.rotatePoints(move_x, move_y);
BottomPanel.appendText("Area of Polygon is: " + UtilClass.calculateAreaOfPolygon(points)+ "\n");
double degrees=1.0;
double radians = degrees * (double)(Math.PI / 180.0);
//GET THE CENTER POINT C
Point2D.Double center = UtilClass.getCenterOfPolygon(points);
//ITERATE THROUGH THE POINTS
Iterator<PointClass> itr = points.iterator();
while(itr.hasNext()) {
//GET THE POINT
PointClass point_class = itr.next();
//point_class = points.get(3);
//FIRST TRANSLATE THE DIFFERENCE
double x1 = point_class.point.x …Run Code Online (Sandbox Code Playgroud) 我试图分别从ArrayList的点添加所有x和y坐标.
public static ArrayList knots = new ArrayList<Point>();
public Point centroid() {
Point center = new Point();
for(int i=0; i<knots.size(); i++) {
????????????????????
return center;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到质心?
我有2D点云,我想计算一个包含所有点的多边形的周长。
请问这个数学过程有什么名称吗?我可以用Google命名吗?有人可以告诉我如何开始思考这个问题吗?
这是我的代码片段 - 它应该围绕原点旋转点,然后将其平移回来
angle = angle * M_PI / 180;
point1.x = (point1.x) * cos(angle) - (point1.y) * sin(angle);
point1.y = (point1.x) * sin(angle) + (point1.y) * cos(angle);
Run Code Online (Sandbox Code Playgroud)
之后,对于应“移动”的平移点,将根据“旋转”后的象限所在的点来说明条件 - 例如,如果它在 1 中,则 x += 2*x 且 y += 2 *y。这里的问题是旋转:例如,对于 130 度的角度,对于点 (100,100),这里是新点 x:CGFloat-3.09086e-06,y:CGFloat100 的坐标。我究竟做错了什么?
points ×10
geometry ×3
polygon ×3
java ×2
python ×2
algorithm ×1
angle ×1
arraylist ×1
c++ ×1
centroid ×1
coordinates ×1
equals ×1
height ×1
intersection ×1
ios ×1
javascript ×1
match ×1
matcher ×1
opencv ×1
python-3.x ×1
rotation ×1
shapely ×1
three.js ×1
translation ×1
width ×1