Comments (9)
I suppose one way is just to loop through each point (site point) and check the distance and then the minimum one is the site the point belongs in
from voronoi.
"Not sure where to put these comments / requests for info"
Me neither, but this is fine I think :)
So, for a random point(x,y) you want to find what cell/site it belongs to?
I'm guessing the simplest way would be to go through each cell, and check if the point is outside or not:
for each site:
for each edge:
normal = site.pos - edge.pos[0] // pointing "inwards"
v = testpos - edge.pos[0]
if dot(normal, v) < 0: // The normals are opposite each other
break // it's outside of this cell
from voronoi.
I'm not sure I understand why a negative dot product means it is outside ?
I assume if you get to the end of the inner loop, you must be inside ?
from voronoi.
Sorry for the lack of indentation, github took all spaces there :/
Oops, a bit sloppy there by me. The normal of course should to be orthogonal to the edge.
diff = edge.pos[1] - edge.pos[0]
normal = point(-diff.y, diff.x) // pointing inwards
It's a check to see if a point is in front or behind a plane. In this case the plane is in 2D (an edge), and the front face of the plane is facing the site. If the dot product between two vectors is negative, it means they point in opposite directions in relation to the plane.
from voronoi.
Ok, I think I understand. So the only way a point can be inside the plane is if the vector to it (from a point in the plane, e.g. edge.pos[1]) has a positive dot product with the plane normal ...
Makes sense. Thanks for the help !
from voronoi.
I'm getting strange anomolies near the edges - maybe the point algorithm doesn't work there ?
from voronoi.
Here is my code
int found=1;
while (edge) {
jcv_point diff;
diff.x = edge->pos[1].x - edge->pos[0].x;
diff.y = edge->pos[1].y - edge->pos[0].y;
// pointing inwards
jcv_point normal;
normal.x = -diff.y;
normal.y = diff.x;
jcv_point v;
v.x = x - edge->pos[0].x;
v.y = y - edge->pos[0].y;
double dot = normal.x * v.x + normal.y * v.y;
if (dot<0.0)
{
found=0;
break;
}
edge = edge->next;
}
from voronoi.
Think the algorithm is right. I used the distance algorithm I described earlier and I'm getting the same result.
I think the problem is that I'm plotting with dots so it inevitably looks aliased
from voronoi.
Yup. Looks better when I use smaller points image
from voronoi.
Related Issues (20)
- Please help me, I understand how get neigbors HOT 1
- Access to the site by its index HOT 1
- Suggestion for easier user experience HOT 1
- Support for Polygons with islands HOT 2
- Duplicate points for site HOT 2
- Bug: graph is missing edges HOT 3
- hsdjlfl
- Add linux compile support HOT 2
- Bug when generating voronoi clipped in a rectangle with only 2 vertices
- voronoi map:multiple polygons intersects HOT 8
- The example Voronoi relaxation is a bit different than Lloyd’s algorithm on Wikipedia. HOT 1
- An all-in-one `#define` directive for the `double` precision. HOT 1
- floor & ceil
- Building a project with code from the voronoi fails in Visual Studio HOT 4
- Clipping against 2D Bounding box HOT 21
- How to get the information of the voronoi vertices and which voronoi cells it is sharing with ? HOT 2
- Many very small edges HOT 7
- memory crash HOT 4
- An infinite loop in the function `jcv_boxshape_fillgaps`(line 1236 in jc_voronoi.h) HOT 6
- Wasm support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from voronoi.