computational-geometry

Sort points in clockwise order?

六眼飞鱼酱① 提交于 2019-11-26 05:41:00
Given an array of x,y points, how do I sort the points of this array in clockwise order (around their overall average center point)? My goal is to pass the points to a line-creation function to end up with something looking rather "solid", as convex as possible with no lines intersecting. For what it's worth, I'm using Lua, but any pseudocode would be appreciated. Thanks so much for any help! Update: For reference, this is the Lua code based on Ciamej's excellent answer (ignore my "app" prefix): function appSortPointsClockwise(points) local centerPoint = appGetCenterPointOfPoints(points) app

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line

╄→гoц情女王★ 提交于 2019-11-26 04:27:53
问题 Below is the solution I am trying to implement /** * Definition for a point. * class Point { * int x; * int y; * Point() { x = 0; y = 0; } * Point(int a, int b) { x = a; y = b; } * } */ public class Solution { public int maxPoints(Point[] points) { int max=0; if(points.length==1) return 1; for(int i=0;i<points.length;i++){ for(int j=0;j<points.length;j++){ if((points[i].x!=points[j].x)||(points[i].y!=points[j].y)){ int coll=get_collinear(points[i].x,points[i].y,points[j].x,points[j].y,points)

How to determine if a list of polygon points are in clockwise order?

Deadly 提交于 2019-11-26 03:24:18
问题 Having a list of points, how do I find if they are in clockwise order? For example: point[0] = (5,0) point[1] = (6,4) point[2] = (4,5) point[3] = (1,5) point[4] = (1,0) would say that it is anti-clockwise (or counter-clockwise, for some people). 回答1: Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here's a simple one that will work with non-convex polygons (it'll even work with a self-intersecting polygon like a figure-eight, telling you

Finding holes in 2d point sets?

两盒软妹~` 提交于 2019-11-26 03:21:37
问题 I have a set of 2d points . They are X,Y coordinates on a standard Cartesian grid system(in this case a UTM zone ). I need to find the holes in that point set preferably with some ability to set the sensitivity of the algorithm that finds these holes. Typically these point sets are very dense but some can be much less dense. What they are, if it helps any, are points at which the soil in the field has been sampled for various properties that people in agriculture apparently find useful.

Sort points in clockwise order?

一个人想着一个人 提交于 2019-11-26 01:55:48
问题 Given an array of x,y points, how do I sort the points of this array in clockwise order (around their overall average center point)? My goal is to pass the points to a line-creation function to end up with something looking rather \"solid\", as convex as possible with no lines intersecting. For what it\'s worth, I\'m using Lua, but any pseudocode would be appreciated. Update: For reference, this is the Lua code based on Ciamej\'s excellent answer (ignore my \"app\" prefix): function

latitude/longitude find nearest latitude/longitude - complex sql or complex calculation

这一生的挚爱 提交于 2019-11-26 00:38:54
问题 I have latitude and longitude and I want to pull the record from the database, which has nearest latitude and longitude by the distance, if that distance gets longer than specified one, then don\'t retrieve it. Table structure: id latitude longitude place name city country state zip sealevel 回答1: What you need is to translate the distance into degrees of longitude and latitude, filter based on those to bound the entries that are roughly in the bounding box, then do a more precise distance

An algorithm for inflating/deflating (offsetting, buffering) polygons

末鹿安然 提交于 2019-11-26 00:17:32
问题 How would I \"inflate\" a polygon? That is, I want to do something similar to this: The requirement is that the new (inflated) polygon\'s edges/points are all at the same constant distance from the old (original) polygon\'s (on the example picture they are not, since then it would have to use arcs for inflated vertices, but let\'s forget about that for now ;) ). The mathematical term for what I\'m looking for is actually inward/outward polygon offseting . +1 to balint for pointing this out.

How to determine if a list of polygon points are in clockwise order?

为君一笑 提交于 2019-11-25 20:08:33
Having a list of points, how do I find if they are in clockwise order? For example: point[0] = (5,0) point[1] = (6,4) point[2] = (4,5) point[3] = (1,5) point[4] = (1,0) would say that it is anti-clockwise (or counter-clockwise, for some people). Beta Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here's a simple one that will work with non-convex polygons (it'll even work with a self-intersecting polygon like a figure-eight, telling you whether it's mostly clockwise). Sum over the edges, (x 2 − x 1 )(y 2 + y 1 ). If the result is positive the