首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >计算从球体采样点的Voronoi图的单元面积

计算从球体采样点的Voronoi图的单元面积
EN

Stack Overflow用户
提问于 2014-03-06 00:26:30
回答 2查看 2.5K关注 0票数 1

更大的图景是,我使用QHULL来计算球面上点的凸包(这是球面的Delaunay Tesselation ),并将从凸包计算的Voronoi单元投影到球面上,然后使用球面三角形http://mathworld.wolfram.com/SphericalTriangle.html计算与每个节点相关的面积(将每个凸包三角形拆分为6个分数三角形,并分别计算分数球面三角形的面积,我得到的内角是从节点指向Voronoi顶点和三角形边缘中点的单位向量与球面相切的点积的弧余弦),但我可以处理这种复杂性。

我遇到的问题是,对于一些非常糟糕的样本设计,Voronoi顶点在delaunay三角形之外是的,可以看到http://www.mathopenref.com/trianglecircumcenter.html,但我没有预料到这一点,我不知道这个答案Compute the size of Voronoi regions from Delaunay triangulation?是否适用于Voronoi顶点在三角形之外的情况。我得到了具有负面积的点(使用球面三角形方法,基于将Voronoi顶点连接到三角形边缘中点和三角形节点来定义分数三角形)

该区域是否比三角形外部的Voronoi顶点(比同一三角形的其他2个节点更接近该节点)更接近节点,而不是比delaunay镶嵌中的任何其他节点更接近该节点?这样做还是很简单的,因为……

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    KS=sort(K,2);
    iK=(1:NK)';
    edges=sortrows([KS(:,1:2) iK; KS(:,[1 3]) iK; KS(:,2:3) iK]);
    edges=reshape(edges(:,3),2,1.5*NK);  %a consequence of this is that there will always be an even number of triangles on the convex hull of a sphere, otherwise Voronoi cells are not defined, which they must be because the convex hull is defined

“边”包含定义Voronoi顶点的凸包三角形的索引?与Voronoi单元格的边缘相关联的2个节点是在它们被丢弃之前的前2列边缘中的节点,所以就像我说的,这是一个简单的修改,但我不确定它在数学上是正确的。你知道是不是这样吗?

EN

回答 2

Stack Overflow用户

发布于 2014-03-06 19:32:37

你似乎让你的工作变得比你需要的更复杂。

最后,你得到了一个凸多边形,形成了围绕你的点的Voronoi单元。您可以通过对输入点定义的每个三角形以及每对相邻的Voronoi顶点求和来计算其面积。

至于你关于外接中心位于某些三角形外部的评论,这是意料之中的。你不需要将三角形从等边三角形变形很多,就可以达到这种情况。

1

票数 0
EN

Stack Overflow用户

发布于 2014-03-06 22:38:51

这似乎起作用了。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
function [x,y,z,ptArea,K,minRad,xv,yv,zv,xvc,yvc,zvc,VorTriNodes]=voronoiSphereArea2(x,y,z) 
%x, y, z are the inputs but normalized to be unit vectors (projected onto
%        the surface of the sphere centered at 0,0,0 with radius 1)
%ptArea  is a numel(x) by 1 vector (same size as x, y, and z) that contains
%        area of the surface of the unit sphere that is closer to the
%        corresponding x y z point than any other pt (this is the area of 
%        projection of the voronoi cell projected onto the surface of the 
%        sphere with radius of 1)
%K       is the output of convhulln([x y z]), it is the tesselation of 
%        points x y z (the list point indexes that make up the triangles 
%        on the convex hull of the sphere)
%minRad  is the minimum distance between the origin (center of the sphere)
%        and any triangle in the tesselation of (normalized) x y z; this is
%        less than 1 because the triangles are the equivalent of chords of
%        a circle (nodes of the triangle are on the surface of the sphere,
%        but the rest of the triangle is below the surface of the sphere,
%        the voronoi vertex of a triangle is the closest point in that 
%        triangle to the center of the sphere), minRad is highly useful
%        when doing barycentric interpolation in x y z space (putting 
%        points to be interpolated at this distance from the origin, [the 
%        largest distance guaranteed to be in the convex hull regardless of
%        angular position, actually you'll want to decrease this slightly
%        to protect against round off error] makes tsearchn [of volumetric
%        Delaunay tesselation formed augmenting each triangle in the 
%        convex hull tesselation with the origin] run faster, it's very 
%        slow if you use an interpolation radius of 0.5 but very fast if 
%        you put the interpolation points just under the surface of the 
%        sphere)
%xv, yv, zv are the x y z coordinates of the voronoi vertices of each
%        triangle in K projected up to the surface of the sphere (for use
%        in plotting "cells" associated with each point) these are listed
%        in the same order as K
%xvc, yvc, zvc are spherical triangular patches whose corners are 1 node 
%        (x, y, z) and 2 voronoi vertices (xv, yv, zv); this is a 
%        30 by 3*size(K,1) matrix, each triangle is a fraction of the
%        voronoi cell belonging to the node (x, y, z)
%VorTriNodes a 1 by 3*size(K,1) vector that identifies the node owning
%        the spherical triangle in the same columns of xvc, yvc, zvc; this
%        is used for plotting piecewise constant point values (where the
%        pieces are the voronoi cells belonging to their respective points)

Npts=numel(x);
invr=(x.^2+y.^2+z.^2).^-0.5;
x=x.*invr;
y=y.*invr;
z=z.*invr;

i4=[1:3 1]';
i3=[3 1 2]';

K=convhulln([x y z]); %right now this is K
NK=size(K,1);

%determine the voronoi cell edges (between the voronoi vertexes of 2 convex
%hull trianlges that share a convex hull triangle edge) and the 2 nodes (x,
%y, z points) that share that edge, these define triangles that are 
%components of the voronoi cells around the 2 nodes
KS=sort(K,2);
iK=(1:NK)';
VorTri=reshape(sortrows([KS(:,1:2) iK; KS(:,[1 3]) iK; KS(:,2:3) iK])',[3 2 1.5*NK]);
VorTriNodes=squeeze(VorTri(1:2,1,:)); %these 2 nodes (in a column) share 
VorTriVerts=squeeze(VorTri(3,:,:)); %the cell edge between these 2 vertices

K=K'; %right now this is K transpose
xn=x(K); %a 3 by NK matrix for the x coordinates of a convex hull triangle, n is for "nodes"
yn=y(K); %a 3 by NK matrix for the y coordinates of a convex hull triangle, n is for "nodes"
zn=z(K); %a 3 by NK matrix for the z coordinates of a convex hull triangle, n is for "nodes"

%calculate the 3 edge lengths (in x y and z coordinates) for each
%triangle in the convex hull tesselation
dx=diff(xn(i4,:));
dy=diff(yn(i4,:));
dz=diff(zn(i4,:));

%calculate the voronoi vertices
xv1=-(dz(1,:).*dy(3,:)-dy(1,:).*dz(3,:)); %negative needed to correct sign convention to keep vornoi vertex on same side of sphere as triangle when we normalize it
yv1=-(dx(1,:).*dz(3,:)-dz(1,:).*dx(3,:));
zv1=-(dy(1,:).*dx(3,:)-dx(1,:).*dy(3,:));
normconst=(xv1.^2+yv1.^2+zv1.^2).^-0.5; %voronoi vertex will be on surface of sphere (radius 1), negative needed to correct sign convention to keep vertex from being projected to opposite side of sphere
xv1=xv1.*normconst; %x component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)
yv1=yv1.*normconst; %y component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)
zv1=zv1.*normconst; %z component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)

xv2=-(dz(2,:).*dy(1,:)-dy(2,:).*dz(1,:));
yv2=-(dx(2,:).*dz(1,:)-dz(2,:).*dx(1,:));
zv2=-(dy(2,:).*dx(1,:)-dx(2,:).*dy(1,:));
normconst=(xv2.^2+yv2.^2+zv2.^2).^-0.5; %voronoi vertex will be on surface of sphere (radius 1), negative needed to correct sign convention to keep vertex from being projected to opposite side of sphere
xv2=xv2.*normconst; %x component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)
yv2=yv2.*normconst; %y component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)
zv2=zv2.*normconst; %z component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)

xv3=-(dz(3,:).*dy(2,:)-dy(3,:).*dz(2,:));
yv3=-(dx(3,:).*dz(2,:)-dz(3,:).*dx(2,:));
zv3=-(dy(3,:).*dx(2,:)-dx(3,:).*dy(2,:));
normconst=(xv3.^2+yv3.^2+zv3.^2).^-0.5; %voronoi vertex will be on surface of sphere (radius 1), negative needed to correct sign convention to keep vertex from being projected to opposite side of sphere
xv3=xv3.*normconst; %x component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)
yv3=yv3.*normconst; %y component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)
zv3=zv3.*normconst; %z component of unit vector pointing from origin through the triangle voronoi vertex (voronoi vertex projected up to the surface of the unit sphere)

%round off error is a big concern average all three possible calculations
xv=(xv1+xv2+xv3)/3;
yv=(yv1+yv2+yv3)/3;
zv=(zv1+zv2+zv3)/3;
normconst=(xv.^2+yv.^2+zv.^2).^-0.5; %use this to project voronoi vertex 
%up to surface of (radius 1) sphere 
xv=xv.*normconst;
yv=yv.*normconst;
zv=zv.*normconst;

if(any(imag(normconst(:)))||any(isnan(normconst(:))))
    error('imaginary numbers or NANs at A');
end

minRad=min(abs(xv.*xn(1,:)+yv.*yn(1,:)+zv.*zn(1,:))); %the minimum distance
%from the origin to any point on the tesselation of the sphere (which will 
%be less than 1 because convex hull facets cut below the surface of the 
%sphere like a chord on a circle) found by taking the dot product of a node
%and the unit vector that passes through the origin (center of sphere) and 
%voronoi vertex of the convex hull triangle determines the distance of the 
%convex hull triangle's voronoi vertex from the center of the sphere.

%define shape of fractional spherical triangle patches to be used in
%piecewise constant plotting of point values
ds=(0:0.1:0.9)';
j1=ones(10,1);
j2=2*j1;
xn=x(VorTriNodes);
xV=xv(VorTriVerts);
yn=y(VorTriNodes);
yV=yv(VorTriVerts);
zn=z(VorTriNodes);
zV=zv(VorTriVerts);
VorTriNodes=VorTriNodes(:); %column vector to do the dot product easily

xvc=reshape(...
    [xn(j1,:)+ds*(xV(1,:)-xn(1,:)); xV(j1,:)+ds*diff(xV); xV(j2,:)+ds*(xn(1,:)-xV(2,:));...
     xn(j2,:)+ds*(xV(1,:)-xn(2,:)); xV(j1,:)+ds*diff(xV); xV(j2,:)+ds*(xn(2,:)-xV(2,:))],...
    30,3*NK);

yvc=reshape(...
    [yn(j1,:)+ds*(yV(1,:)-yn(1,:)); yV(j1,:)+ds*diff(yV); yV(j2,:)+ds*(yn(1,:)-yV(2,:));...
     yn(j2,:)+ds*(yV(1,:)-yn(2,:)); yV(j1,:)+ds*diff(yV); yV(j2,:)+ds*(yn(2,:)-yV(2,:))],...
    30,3*NK);

zvc=reshape(...
    [zn(j1,:)+ds*(zV(1,:)-zn(1,:)); zV(j1,:)+ds*diff(zV); zV(j2,:)+ds*(zn(1,:)-zV(2,:));...
     zn(j2,:)+ds*(zV(1,:)-zn(2,:)); zV(j1,:)+ds*diff(zV); zV(j2,:)+ds*(zn(2,:)-zV(2,:))],...
    30,3*NK);

invrvc=(xvc.^2+yvc.^2+zvc.^2).^-0.5;
xvc=xvc.*invrvc;
yvc=yvc.*invrvc;
zvc=zvc.*invrvc;

if(any(imag(invrvc(:)))||any(isnan(invrvc(:))))
    error('imaginary numbers or NANs at B');
end


%time to compute the area of the spherical triangle components of the
%voronoi cells areound each point

%first define the corners of the voronoi cell triangles and their edge
%lengths (direction matters)
xt=reshape([xn(1,:); xV; xn(2,:); xV],3,3*NK); dx=diff(xt(i4,:));
yt=reshape([yn(1,:); yV; yn(2,:); yV],3,3*NK); dy=diff(yt(i4,:));
zt=reshape([zn(1,:); zV; zn(2,:); zV],3,3*NK); dz=diff(zt(i4,:));


%now going to compute unit vectors tangent to surface in direction of
%great circles connection nodes of voronoi cell component triangles

%dx, dy, dz are chord distances in forward (a) direction
yada=xt.*dx+yt.*dy+zt.*dz;
dirxa=dx-xt.*yada; %x component of derivative/tangent vector at point
dirya=dy-yt.*yada; %y component of derivative/tangent vector at point
dirza=dz-zt.*yada; %z component of derivative/tangent vector at point
yada=(dirxa.^2+dirya.^2+dirza.^2);
yada=(yada+(yada==0)).^-0.5; %protect against zero magnitude vectors which 
%causes NaNs without this protection, yes it happened in a Tensor Product 
%grid (vornoi vertex was outside triangle on top of other voronoi vertex)
dirxa=dirxa.*yada; %x component of unit vector direction 
dirya=dirya.*yada; %y component of unit vector direction
dirza=dirza.*yada; %z component of unit vector direction

if(any(imag(yada(:)))||any(isnan(yada(:))))
    error('imaginary numbers or NANs at C');
end

%make dx, dy, dz chord distances in backward (b) direction
dx=-dx(i3,:); dy=-dy(i3,:); dz=-dz(i3,:);
yada=xt.*dx+yt.*dy+zt.*dz;
dirxb=dx-xt.*yada; %x component of derivative/tangent vector at point
diryb=dy-yt.*yada; %y component of derivative/tangent vector at point
dirzb=dz-zt.*yada; %z component of derivative/tangent vector at point
yada=(dirxb.^2+diryb.^2+dirzb.^2);
yada=(yada+(yada==0)).^-0.5;%protect against zero magnitude vectors which 
%causes NaNs without this protection, yes it happened in a Tensor Product 
%grid (vornoi vertex was outside triangle on top of other voronoi vertex)
dirxb=dirxb.*yada; %x component of unit vector direction 
diryb=diryb.*yada; %y component of unit vector direction
dirzb=dirzb.*yada; %z component of unit vector direction

if(any(imag(yada(:)))||any(isnan(yada(:))))
    error('imaginary numbers or NANs at D');
end

%fractional spherical triangle area is the sum of the 3 interior angles
%minus pi times the square of the sphere's radius (which is 1).  Interior
%angle is the arc cosine of the dot product of the forward and backward
%unit vectors (in the directions away from one corner of spherical triangle
%to the other 2 corners)
%min and max are needed to fix round off error that could cause imaginary 
%angles via arc-hyperbolic-cosine, but max would replace NaN with -1 which 
%makes angle pi when should have been zero, see the 
%yada=(yada+(yada==0)).^-0.5; protection above
areacontrib=sum(acos(min(max(dirxa.*dirxb+dirya.*diryb+dirza.*dirzb,-1),1)))-pi;

%fix round off error that could cause "negative zero" areas
areacontrib=areacontrib.*~((areacontrib<0)&(areacontrib>-(2^-35)));

if(any(imag(areacontrib))||any(areacontrib<0))
    %area might be imaginary or negative if there's a bug (other than round
    %off error which should have been fixed).
    save DEBUGME_voronoiSphereArea
    error('imaginary or negative areas at E Npts=%d',Npts);
end

ptArea=zeros(Npts,1);
for ipt=1:Npts
    ptArea(ipt)=areacontrib*(VorTriNodes==ipt); %matrix ops dot product to
    %sum the areas of all spherical triangles that make of the point's 
    %voronoi cell
end

%SphereAreaDiv4pi=sum(ptArea)/(4*pi) %is 1 to 8+ sig figs
ptArea=ptArea*(4*pi/sum(ptArea)); %"fix" round off error in ptArea

K=K'; %this is no longer K transpose
xv=xv(:); %for drawing voronoi cell edges
yv=yv(:);
zv=zv(:);
VorTriNodes=VorTriNodes'; %for plotting piecewise constant voronoi cells as
%being made up of triangles with 1 node and 2 vertices.
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22212394

复制
相关文章
当删库时如何避免跑路
删库跑路也是个老梗了,可见在运维数据库的过程中误删除数据,或者开发的代码有bug,造成数据的误删除屡见不鲜。不过现在也有许多用于恢复或预防误删除的方案,例如SQL管理系统,将要执行的SQL先交由管理员审核,然后由管理员备份一个镜像数据库,在镜像上执行该SQL,并在执行后还原镜像。这样经过层层把关就可以大大减小出现误操作的几率。
端碗吹水
2020/09/23
1K0
当删库时如何避免跑路
SpringBoot同一个服务多个端口启动
设置完端口后点击下 空白处,否则有可能端口设置不上去 如果没有这个选项,则执行以下步骤即可看到:
星辰sea
2022/10/29
1.2K0
SpringBoot同一个服务多个端口启动
1000多个项目中的十大JavaScript错误以及如何避免
通过统计数据库中的1000多个项目,我们发现在 JavaScript 中最常出现的错误有10个。下面会向大家介绍这些错误发生的原因以及如何防止。
一墨编程学习
2018/10/20
6.2K0
1000多个项目中的十大JavaScript错误以及如何避免
通过统计数据库中的1000多个项目,我们发现在 JavaScript 中最常出现的错误有10个。下面会向大家介绍这些错误发生的原因以及如何防止。 对于这些错误发生的次数,我们是通过收集的数据统计得出的
葡萄城控件
2018/03/27
8.4K0
1000多个项目中的十大JavaScript错误以及如何避免
构建知识库时,如何避免最常见的几个错误?
建立知识库并不像单击几个按钮并将其实施到现有网站那么容易。实际上,建立知识库就像建立一个全新的网站,只是它集成到您​​现有的网站中。它是您网站的一个部分,您的客户每次需要有关您的服务的一些信息或有问题需要解决时都会前往该部分。
用户9912463
2022/07/22
6540
使用 React Hooks 时要避免的6个错误
这个组件接收一个参数id,在useEffect中会使用这个id作为参数去请求游戏的信息。并将获取的数据保存在状态变量game中。 ​
玖柒的小窝
2021/11/28
2.4K0
使用 React Hooks 时要避免的6个错误
使用React Hooks 时要避免的5个错误!
最近开源了一个 Vue 组件,还不够完善,欢迎大家来一起完善它,也希望大家能给个 star 支持一下,谢谢各位了。
前端小智@大迁世界
2021/03/11
4.3K0
使用React Hooks 时要避免的5个错误!
服务集成时需避免的两个错误
随着面向服务架构(下文简称 SOA,Service Oriented Architecture)的出现,企业通过将业务功能分解为多重服务 [1],它们迅速地从整体应用程序设计(Monolithic application design)过渡到了异构设计(Heterogeneous design)。在将这些服务集成起来之时,企业架构师应当小心,因为劣质的服务集成将会导致一团乱麻的结局。很多时候,企业假定仅采用如企业服务总线(下文简称 ESB,Enterprise Service Bus)和微服务这样的模式就能避免出现混乱的局面 [2],并且能够提供一个可行的解决方案。当它被 “部分地” 完成时,很不幸这些模式并不能解决某些隐藏的挑战。危险的是,在开发和部署的初始化阶段,它们通常不会被注意到,但是当系统在生产环境中工作时,它们就会出现。等我们意识到后果,为时已晚。本文旨在详细阐述其中的一些挑战,并明确指出,我们可以采取哪些措施来避免这些挑战。
Techeek
2018/06/20
1.4K0
服务集成时需避免的两个错误
学习Java时应避免的10个致命错误
要编码还是不编码?看来您已经选择了第一个选项。编程是专业发展的绝佳领域,它使您有机会参与有趣的项目并在任何需要的地方工作。
可大可小
2020/04/07
5450
如何使用 SSD 避免 VDI 启动风暴
桌面虚拟化,或虚拟桌面基础架构(VDI),可以为IT部门带来诸多好处,包括更简单的系统管理,集中的安全性和数据保护。不过支撑VDI的存储环境需要仔细的规划,以避免VDI启动风暴的问题,即当大量的用户同时登录系统时所造成的系统反应非常缓慢。有许多方法可以解决这个问题,但最有效的方法是将数据巧妙的放置在固态硬盘(SSD)上。
SuperDream
2019/02/28
1.3K0
IL3002:当发布为单个文件时,避免调用
将应用发布为单个文件(例如将项目中的 PublishSingleFile 属性设置为 true)时,调用使用 RequiresAssemblyFilesAttribute 属性注释的成员与单文件不兼容。 这些调用可能不兼容,因为使用此属性注释的成员要求程序集文件位于磁盘上,而嵌入单文件应用的程序集已加载到内存中。
呆呆
2022/02/26
4580
nginx重写url】之 当项目有多个入口文件时
但当我们的php项目有多个入口文件时,(假如有index.php, admin.php, app.php, api.php 四个入口文件),在不处理的状态下,url会呈现出这般景象:
PM吃瓜
2019/08/13
1.8K0
gRPC: 如何在启动多个端口?
为了验证,我们启动了 commonService,commonService 里包含了一系列常用 API,例如 /rk/v1/healthy。
尹东勋
2021/10/20
1.5K0
gRPC: 如何在启动多个端口?
训练机器学习模型时应避免的 6 个错误
对人工智能模型进行训练的同时,还需要进行多阶段任务,以充分利用训练数据,获得满意的结果。为了保证人工智能模型的性能,本文列出了六个需要避免的常见错误。
深度学习与Python
2021/06/08
9430
如何避免数据科学领域的新手错误?
原标题 | How to avoid rookie mistakes in the field of Data Science作 者 | Pritha Saha 翻 译 | CONFIDANT(福建师范大学) 编 辑 | Pita 我最近开始通过自学成为数据科学家的旅程,这条路并不总是一帆风顺的,因为没有人给我详细而有序的教学大纲。我尝试做了几件事,都没有很成功,但后来又有所收获。如果您是一位有抱负的数据科学家,本文可能会帮助您避免犯我曾经所犯的错误。 首先,永远不要试图通过死记硬背学习机器学习算法,大脑只
AI研习社
2019/08/09
7660
如何避免数据科学领域的新手错误?
windows如何安装多个版本mysql,如何同时启动
ini文件里面 端口也要改为不一样,比如改为3307 以管理员身份打开cmd命令窗口,将目录切换到MySQL的安装目录的bin目录下 进入mysql的bin目录后执行
一写代码就开心
2022/06/12
4K1
windows如何安装多个版本mysql,如何同时启动
开始使用Vue 3时应避免的10个错误
Vue 3 稳定已经有一段时间了。许多代码库正在生产中使用它,其他人最终也必须进行迁移。我有机会与它一起工作,并记录了我的错误,这可能是你想避免的。
前端小智@大迁世界
2023/07/09
3020
开始使用Vue 3时应避免的10个错误
点击加载更多

相似问题

Numpy点积

11

numpy点积和矩阵积

27

Numpy点积问题

32

Numpy数组点积

224

Numpy元素点积

23
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文