computational-geometry

Testing if a line has a point within a triangle

How can I test whether a line has a point that lies within (not on the edge of) a triangle. (All in 2D). Currently I'm thinking I'll do this: Define the line, and each side of the triangle as Ax+By+C=0, and have an xrange. Check if the line intersects any of the lines of the triangle. If it does, check that this is NOT at the end of t...

What's the opposite of polygon triangulation?

After I've done a 2D triangulation, some triangles have the same color and I want to recombine them for drawing into like-colored graphics paths. I find that if I just draw the triangles one by one, some graphic renderers shows seams between the triangles (at least if anti-aliasing and/or transparency is involved). So how do I take a se...

How do you generate the non-convex hull from a series of points?

I am currently trying to construct the area covered by a device over an operating period. The first step in this process appears to be constructing a polygon of the covered area. Since the pattern is not a standard shape, convex hulls overstate the covered area by jumping to the largest coverage area possible. I have found a paper th...

Geo-region data for countries/states/oceans

I'm developing an application where entities are located at positions on Earth. I want to have a set of data from which I can determine what region(s) a point is contained within. Regions may be of types: Continent Country Lake Sea DMZ Desert Ice Shelf ...and so forth. I'm envisioning representing each region as a polygon. For an...

Finding the polygon in a 2d mesh which contains a point

I have a 3d polygon mesh and a corresponding 2d polygon mesh (actually from a uv map) which I'm using to map the geometry onto a 2d plane. Given a point on the plane, how can I efficiently find the polygon on which it's resting in order to map that 2d point back into 3d? The best approach I can think of is to store the polygons in a 2d ...

Infinite initial bounding triangle in iterative Delaunay triangulators.

Most iterative algorithms require an initial empty triangle to get the ball rolling. It seems like a commonly used trick is just to make the super triangle very large in comparison with the point set. But according to "Numerical recipes: the art of scientific computing": "...if the distance is merely finite (to the boundary points) th...

3D Connected Points Labeling based on Euclidean distances

Hi guys, Currently, I am working on a project that is trying to group 3d points from a dataset by specifying connectivity as a minimum euclidean distance. My algorithm right now is simply a 3d adaptation of the naive flood fill. size_t PointSegmenter::growRegion(size_t & seed, size_t segNumber) { size_t numPointsLabeled = 0; /...

What is the fastest algorithm to calculate the minimum distance between two sets of points?

I wanna find the minimum distance between two polygon. I mean, I have to find the minimum of shortest distance between each vertex of first shape with the all the vertexes of the other one. Something like Hausdorff Distance but I need minimum instead of maximum. I appreciate any suggestion. Thank you. ...

Smooth a convex polygonal shape so that it becomes as large as possible while retaining diameter

Given a convex polygon, I am trying to grow its shape (as in "maximal area") while preserving its diameter. The diameter is defined as the length of the longest segment that can be placed within the polygon. Since the polygon is convex, I assume that this diameter can always be found by scanning all vertex pairs. For example, given an e...

How can I fill an outline with predefined tangram shapes ?

I am interested in using shapes like these: Usually a tangram is made of 7 shapes(5 triangles, 1 square and 1 parallelogram). What I want to do is fill a shape only with tangram shapes, so at this point, the size and repetition of shapes shouldn't matter. Here's something I manually tried: I am a bit lost on how to approach this...

Theoretical Algorithm for finding closet 2 points on a circle in O(n)

Given n points on the outline of the unit circle, I want to calculate the closest 2 points. The points are not ordered, and I need to do it in O(n) (so I cannot sort them clockwise...) I once knew the solution for this, but forgot it... the solution includes hashing, and splitting the circle to n or more slices. If you found an algori...

segment-polygon intersection

Greetings, I would like to detect if a segment only 'touches' a polygon or cross it. The Figure explains my doubt. How to know the difference between cases A and B? Note that in both situations the red line crosses the polygons in two vertices, one touching by outside and other crossing by inside. I have a segment-segment intersecti...

Expand fill of convex polygon

I have a convex polygon P1 of N points. This polygon could be any shape or proportion (as long as it is still convex). I need to compute another polygon P2 using the original polygons geometry, but "expanded" by a given number of units. What might the algorithm be for expanding a convex polygon? ...

map points between two triangles in 3D space

Hello, EDIT I don't know is it important, but destination triangle angles may be different than these of source. Does that fact makes transformation non-affine ? (i'm not sure) I have two triangles in 3D space. Given that i know (x,y,z) of point in first triangle and i know vectors V1,V2,V3. I need to find point (x',y',z'). What tra...

Best line equation to use for computational geometry.

Hi, I'm looking to write a little comp-geom library, in Ruby. I'm about to write the code for lines, and was wondering which line equation I should use: ax + by + c = 0 r + tv (where r and v are vectors) Thanks. ...

How To Slice a Simple Polygon with a Line

I have a simple polygon (convex or concave, but no holes) that I need to slice into parts with a line segment. I'm not sure how to actually determine how many polygons result after the slice, or how to group the vertices. Basic convex cases the always results in 2 sub-polygons are easy, but how would I deal with a complicated concave sh...

Adaptive implicit surface polygonization

I've been using one of the older implicit surface algorithms, due to Bloomenthal, as found here, basically the tetrahedral-based algorithm. This works fairly well, but has a shortcoming. Since it uses a fixed grid, it either wastes polygons or ignores detail, depending on the grid size selected. So my question is, what are my option...

How to find the bisector of an angle in MATLAB

I have a question connected to this code: t = -20:0.1:20; plot3(zeros(size(t)),t,-t.^2); grid on hold on i = 1; h = plot3([0 0],[0 t(i)],[0 -t(i)^2],'r'); h1 = plot3([-1 0],[0 0],[-400 -200],'g'); for(i=2:length(t)) set(h,'xdata',[-1 0],'ydata',[0 t(i)],'zdata',[-400 -t(i)^2]); pause(0.01); end In this code, I plot two in...

comparing two DEMs

Hi, i have two Lidar las files, one is original let's say with X points. And the other is copy of the first las file but with Y points, where Y is less than X. Now, i wanted to compare how the Digital Elevation Models of these two las files vary... I wanted to get information like RMSE, standard deviation, etc... I would appreciate, if a...

Google Maps Circle Overlay and Vincenty Formula

Hi - I'm using the Circle overlay as part of the V3 of the Google Maps Javascript API (i.e., see below - we have a subsequent call that actually sets radius/etc.) to display goe-spatial locations in our application. var circle = new google.maps.Circle({ fillColor: lCircleColor, strokeWeight: 2 }); We also have a ...