我工作的三角物体(最终,我想实现一个Delaunay三角,但三角甚至不合法化的边缘前工作,所以我想专注于一个简单的三角测量第一).我在下面列出了相关代码.我正在实施类似于Mark de Berg的"Computation Geometry:Algorithms and Application Third Edition"中描述的三角测量方法等.给出的伪代码如下(如果需要,我将删除它):
注意:我通过创建一个边界三角形来修改伪代码,而不是使用"按字典顺序排列的最高点P",因为我不太确定如何定义p -1和p -2,因为教科书说它"象征性地"定义它们而不是定义确切的单位(我当然可能误解了它试图说的是公平的).此外,合法化不是我的代码的一部分(但是)因为这对于Delaunay三角测量是必要的,但我想确保简单的三角测量按预期工作.
问题是我得到了一些诸如此类的三角测量
其中蓝线来自原始多边形.
其中一些行没有被添加,因为它们是点p0,p1和p2的三角形的一部分,我没有在findSmallest方法中添加它们.然而,如果我也添加这些三角形,我得到这样的东西:
(注意p0,p1和p2超出了图片的范围).来自原始多边形的一些线(此时为绿色)仍未添加到三角测量中.我不确定我哪里出错了.
我希望代码是清楚的,但我将解释一些方法/结构以防万一:
TriPoint
Run Code Online (Sandbox Code Playgroud)
是Point结构的子代.
p0, p1, p2
Run Code Online (Sandbox Code Playgroud)
是三个点形成多边形周围的边界三角形.我从这篇文章中得到了这个想法.
contains(Point p)
Run Code Online (Sandbox Code Playgroud)
如果某个点位于三角形内或其中一条边上,则返回true.
findCommonTriangle(TriPoint *a, TriPoint *b, Triangle *t)
Run Code Online (Sandbox Code Playgroud)
沿着边缘ab返回t的三角形事件.(我没有使用Edges来计算三角测量因此我决定以这种方式得到事件三角形).
isOnTriangle(Point s)
Run Code Online (Sandbox Code Playgroud)
在三角形abc上调用,如果该点位于边缘ab,则返回1;如果该点位于边缘bc,则返回2;如果该点位于边缘cd,则返回3.如果它在三角形内,则返回0.
三角测量本身的代码位于:
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
#include <array>
#include <vector>
#include "predicates.h"
struct Point {
float x, y;
Point() { }
Point(float a, float b) {
x = a;
y = b;
}
};
struct Triangle;
struct Triangulation;
std::vector<Triangulation *> …Run Code Online (Sandbox Code Playgroud) 我找到了这篇文章并想稍微修改脚本以将图像下载到特定文件夹。我编辑的文件如下所示:
import re
import requests
from bs4 import BeautifulSoup
import os
site = 'http://pixabay.com'
directory = "pixabay/" #Relative to script location
response = requests.get(site)
soup = BeautifulSoup(response.text, 'html.parser')
img_tags = soup.find_all('img')
urls = [img['src'] for img in img_tags]
for url in urls:
#print(url)
filename = re.search(r'/([\w_-]+[.](jpg|gif|png))$', url)
with open(os.path.join(directory, filename.group(1)), 'wb') as f:
if 'http' not in url:
url = '{}{}'.format(site, url)
response = requests.get(url)
f.write(response.content)
Run Code Online (Sandbox Code Playgroud)
这对于pixabay似乎工作正常,但如果我尝试不同的网站,如imgur或heroimages,它似乎不起作用。如果我用
site = 'http://heroimages.com/portfolio'
Run Code Online (Sandbox Code Playgroud)
没有下载任何东西。打印语句(未注释时)不打印任何内容,所以我猜它没有找到任何图像标签?我不知道。
另一方面,如果我用 …