Bowyer-Watson算法

2024-06-06 05:28
文章标签 算法 watson bowyer

本文主要是介绍Bowyer-Watson算法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

数学原理及算法过程

Delaunay 三角剖分是一种特殊的三角剖分方法,它满足以下两个重要性质:

  • 最大化最小角性质:Delaunay 三角剖分通过避免细长的三角形来最大化所有三角形的最小角。
  • 空外接圆性质:在 Delaunay 三角剖分中,每个三角形的外接圆不包含任何其他点。这意味着,对于三角剖分中的任意三角形,其外接圆内没有其他输入点。

基于这些性质,Delaunay 三角剖分算法的一种实现方式是 Bowyer-Watson 算法,这是一种增量算法。以下是具体的算法步骤:

算法过程
  1. 初始化超级三角形:
  • 创建一个足够大的超级三角形,包含所有输入点。这个三角形的三个顶点坐标远离实际输入点的范围,使其能够覆盖所有点。
  1. 逐点插入:
  • 对于每个输入点,找到所有包含该点的外接圆的三角形。这些三角形被称为“坏三角形”。
  1. 构建多边形:
  • 对于所有坏三角形,它们的每条边,如果只被一个坏三角形共享,则称其为边界边。这些边将形成一个多边形。
  1. 删除坏三角形:
  • 将所有坏三角形从三角剖分中删除。
  1. 重新三角化多边形:
  • 用新插入的点和多边形的边构成新的三角形,并将这些三角形加入三角剖分中。
  1. 移除超级三角形的影响:
  • 在所有点都插入后,移除包含超级三角形顶点的所有三角形,得到最终的 Delaunay 三角剖分。

数学原理

  • 外接圆计算

    • 对于每个三角形,计算其外接圆。外接圆的圆心(外心)和半径可以通过三角形顶点的坐标计算。
    • 设三角形顶点为 ( x 1 , y 1 ) , ( x 2 , y 2 ) , ( x 3 , y 3 ) (x_1, y_1), (x_2, y_2), (x_3, y_3) (x1,y1),(x2,y2),(x3,y3)。外接圆的圆心 ( u , v ) (u, v) (u,v) 计算如下:
      d = 2 ( x 1 ( y 2 − y 3 ) + x 2 ( y 3 − y 1 ) + x 3 ( y 1 − y 2 ) ) d = 2 \left( x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) \right) d=2(x1(y2y3)+x2(y3y1)+x3(y1y2))

    u = ( ( x 1 2 + y 1 2 ) ( y 2 − y 3 ) + ( x 2 2 + y 2 2 ) ( y 3 − y 1 ) + ( x 3 2 + y 3 2 ) ( y 1 − y 2 ) ) d u = \frac{((x_1^2 + y_1^2)(y_2 - y_3) + (x_2^2 + y_2^2)(y_3 - y_1) + (x_3^2 + y_3^2)(y_1 - y_2))}{d} u=d((x12+y12)(y2y3)+(x22+y22)(y3y1)+(x32+y32)(y1y2))

    v = ( ( x 1 2 + y 1 2 ) ( x 3 − x 2 ) + ( x 2 2 + y 2 2 ) ( x 1 − x 3 ) + ( x 3 2 + y 3 2 ) ( x 2 − x 1 ) ) d v = \frac{((x_1^2 + y_1^2)(x_3 - x_2) + (x_2^2 + y_2^2)(x_1 - x_3) + (x_3^2 + y_3^2)(x_2 - x_1))}{d} v=d((x12+y12)(x3x2)+(x22+y22)(x1x3)+(x32+y32)(x2x1))

    r = ( x 1 − u ) 2 + ( y 1 − v ) 2 r = \sqrt{(x_1 - u)^2 + (y_1 - v)^2} r=(x1u)2+(y1v)2

import matplotlib.pyplot as plt
import numpy as npclass Point:def __init__(self, x, y):self.x = xself.y = yclass Triangle:def __init__(self, p1, p2, p3):self.p1 = p1self.p2 = p2self.p3 = p3self.circumcenter, self.circumradius = self.circumcircle()def circumcircle(self):"""Calculate the circumcenter and circumradius of the triangle."""ax, ay = self.p1.x, self.p1.ybx, by = self.p2.x, self.p2.ycx, cy = self.p3.x, self.p3.yd = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by))ux = ((ax*ax + ay*ay) * (by - cy) + (bx*bx + by*by) * (cy - ay) + (cx*cx + cy*cy) * (ay - by)) / duy = ((ax*ax + ay*ay) * (cx - bx) + (bx*bx + by*by) * (ax - cx) + (cx*cx + cy*cy) * (bx - ax)) / dcircumcenter = Point(ux, uy)circumradius = np.sqrt((ax - ux)**2 + (ay - uy)**2)return circumcenter, circumradiusdef contains_point(self, p):"""Check if the point p is inside the circumcircle of the triangle."""return np.sqrt((p.x - self.circumcenter.x)**2 + (p.y - self.circumcenter.y)**2) < self.circumradiusdef delaunay_triangulation(points):"""Perform Delaunay triangulation on a set of points."""super_triangle = Triangle(Point(-1e5, -1e5), Point(1e5, -1e5), Point(0, 1e5))triangulation = [super_triangle]for p in points:bad_triangles = []for tri in triangulation:if tri.contains_point(p):bad_triangles.append(tri)polygon = []for tri in bad_triangles:for edge in [(tri.p1, tri.p2), (tri.p2, tri.p3), (tri.p3, tri.p1)]:is_shared = Falsefor other in bad_triangles:if other != tri and (edge in [(other.p1, other.p2), (other.p2, other.p3), (other.p3, other.p1)] or edge[::-1] in [(other.p1, other.p2), (other.p2, other.p3), (other.p3, other.p1)]):is_shared = Truebreakif not is_shared:polygon.append(edge)for tri in bad_triangles:triangulation.remove(tri)for edge in polygon:triangulation.append(Triangle(edge[0], edge[1], p))triangulation = [tri for tri in triangulation if not (super_triangle.p1 in [tri.p1, tri.p2, tri.p3] or super_triangle.p2 in [tri.p1, tri.p2, tri.p3] or super_triangle.p3 in [tri.p1, tri.p2, tri.p3])]return triangulationdef plot_triangulation(triangles, points):for tri in triangles:plt.plot([tri.p1.x, tri.p2.x], [tri.p1.y, tri.p2.y], 'b-')plt.plot([tri.p2.x, tri.p3.x], [tri.p2.y, tri.p3.y], 'b-')plt.plot([tri.p3.x, tri.p1.x], [tri.p3.y, tri.p1.y], 'b-')for p in points:plt.plot(p.x, p.y, 'ro')plt.show()
# Generate random points in the unit square
rectangle_corners = [Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)]
random_points = [Point(np.random.rand(), np.random.rand()) for _ in range(20)]
points = rectangle_corners + random_pointstriangles = delaunay_triangulation(points)
plot_triangulation(triangles, points)

在这里插入图片描述

这篇关于Bowyer-Watson算法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1035212

相关文章

Python中的随机森林算法与实战

《Python中的随机森林算法与实战》本文详细介绍了随机森林算法,包括其原理、实现步骤、分类和回归案例,并讨论了其优点和缺点,通过面向对象编程实现了一个简单的随机森林模型,并应用于鸢尾花分类和波士顿房... 目录1、随机森林算法概述2、随机森林的原理3、实现步骤4、分类案例:使用随机森林预测鸢尾花品种4.1

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

康拓展开(hash算法中会用到)

康拓展开是一个全排列到一个自然数的双射(也就是某个全排列与某个自然数一一对应) 公式: X=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[i]*(i-1)!+...+a[1]*0! 其中,a[i]为整数,并且0<=a[i]<i,1<=i<=n。(a[i]在不同应用中的含义不同); 典型应用: 计算当前排列在所有由小到大全排列中的顺序,也就是说求当前排列是第

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

【数据结构】——原来排序算法搞懂这些就行,轻松拿捏

前言:快速排序的实现最重要的是找基准值,下面让我们来了解如何实现找基准值 基准值的注释:在快排的过程中,每一次我们要取一个元素作为枢纽值,以这个数字来将序列划分为两部分。 在此我们采用三数取中法,也就是取左端、中间、右端三个数,然后进行排序,将中间数作为枢纽值。 快速排序实现主框架: //快速排序 void QuickSort(int* arr, int left, int rig

poj 3974 and hdu 3068 最长回文串的O(n)解法(Manacher算法)

求一段字符串中的最长回文串。 因为数据量比较大,用原来的O(n^2)会爆。 小白上的O(n^2)解法代码:TLE啦~ #include<stdio.h>#include<string.h>const int Maxn = 1000000;char s[Maxn];int main(){char e[] = {"END"};while(scanf("%s", s) != EO

秋招最新大模型算法面试,熬夜都要肝完它

💥大家在面试大模型LLM这个板块的时候,不知道面试完会不会复盘、总结,做笔记的习惯,这份大模型算法岗面试八股笔记也帮助不少人拿到过offer ✨对于面试大模型算法工程师会有一定的帮助,都附有完整答案,熬夜也要看完,祝大家一臂之力 这份《大模型算法工程师面试题》已经上传CSDN,还有完整版的大模型 AI 学习资料,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

dp算法练习题【8】

不同二叉搜索树 96. 不同的二叉搜索树 给你一个整数 n ,求恰由 n 个节点组成且节点值从 1 到 n 互不相同的 二叉搜索树 有多少种?返回满足题意的二叉搜索树的种数。 示例 1: 输入:n = 3输出:5 示例 2: 输入:n = 1输出:1 class Solution {public int numTrees(int n) {int[] dp = new int

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯: