polygon

How to draw a n sided regular polygon in cartesian coordinates?

自作多情 提交于 2019-11-27 05:19:46
问题 I have been trying to figure out how to write a simple program to compute the x,y points for creating a regular polygon of n sides. Can someone give me some code examples that don't use preexisting functions that draw polygons? I want to understand the process, which I assume is something like this: pick an angle to start from a radius and a center point somehow calculate the x,y position at that distance from the center(how?) divide 360 by the number of sides, move that distance and draw the

How do I determine if two convex polygons intersect?

帅比萌擦擦* 提交于 2019-11-27 04:25:58
Suppose there are a number of convex polygons on a plane, perhaps a map. These polygons can bump up against each other and share an edge, but cannot overlap. To test if two polygons P and Q overlap, first I can test each edge in P to see if it intersects with any of the edges in Q . If an intersection is found, I declare that P and Q intersect. If none intersect, I then have to test for the case that P is completely contained by Q , and vice versa. Next, there's the case that P == Q . Finally, there's the case that share a few edges, but not all of them. (These last two cases can probably be

Algorithm for creating rounded corners in a polygon

不想你离开。 提交于 2019-11-27 04:10:39
问题 I'm looking for an algorithm that allows me to create rounded corners from a polygon. In Input, I get an array of points that represents the polygon (red line) and in output, an array of points that represents the polygon with rounded corner (black line). I would also like to have a way to control the radius of each corner. I already tried to use Bezier and Subdivision but it's not what I'm looking for. Bezier and Subdivision are smoothing all the polygon. What I want, it's only make the

How to test if a point is inside of a convex polygon in 2D integer coordinates?

早过忘川 提交于 2019-11-27 03:58:00
The polygon is given as a list of Vector2I objects (2 dimensional, integer coordinates). How can i test if a given point is inside? All implementations i found on the web fail for some trivial counter-example. It really seems to be hard to write a correct implementation. The language does not matter as i will port it myself. fortran If it is convex, a trivial way to check it is that the point is laying on the same side of all the segments (if traversed in the same order). You can check that easily with the cross product (as it is proportional to the cosine of the angle formed between the

Polygon enclosing a set of points

匆匆过客 提交于 2019-11-27 03:57:54
I have a set S of points (2D : defined by x and y) and I want to find P, the smallest (meaning : with the smallest number of points) polygon enclosing all the points of the set, P being an ordered subset of S. Are there any known algorithms to compute this? (my lack of culture in this domain is astonishing...) Thanks for your help There are many algorithms for this problem. It is called " minimum bounding box ". You will find solutions too searching for " convex hull ", especially here . One way is to find the leftmost point and then repeat to search for a point where all other points are to

Sorting clockwise polygon points in MATLAB

前提是你 提交于 2019-11-27 02:44:21
问题 I have 2 vectors that are x and y coordinates of the 8 vertexes of a polygon x=[5 5 7 7 9 9 5 7] y=[8 6 6 8 6 8 10 10] I wanna sort them (clockwise) to obtain the right vectors (to draw the polygon correctly) x=[5 7 9 9 7 7 5 5] y=[6 6 6 8 8 10 10 8] 回答1: Step 1: Find the unweighted mean of the vertices: cx = mean(x); cy = mean(y); Step 2: Find the angles: a = atan2(y - cy, x - cx); Step 3: Find the correct sorted order: [~, order] = sort(a); Step 4: Reorder the coordinates: x = x(order); y =

Reduce number of points in line

試著忘記壹切 提交于 2019-11-27 01:42:17
问题 I'm searching for algorithms to reduce the LOD of polylines, lines (looped or not) of nodes. In simple words, I want to take hi-resolution coastline data and be able to reduce its LOD hundred- or thousandfold to render it in small-scale. I found polygon reduction algorithms (but they require triangles) and Laplacian smoothing, but that doesn't seem exactly what I need. 回答1: I've modified the code in culebrón's answer, removing the need for the Vec2D/Line classes, instead handling the points

How to draw polygons with CGPath?

99封情书 提交于 2019-11-27 01:23:53
问题 I have been reading thru the documentation however it is not immediatly clear to me how to draw a polygon using CGPath. All I need to do is to draw CGPath around something like this: __ \ \ \ \ \__\ Could anyone please provide an snippet on how to do this? Additionally I assume CGPathContainsPoint will help me determine if a point is inside such path?, or does the path have to be a solid drawing Also how can i move the cgpath around? Is this as easy as changing something like the origin just

Determine if a point reside inside a leaflet polygon

房东的猫 提交于 2019-11-27 01:23:48
问题 Suppose I Draw a polygan using leaflet like in the follow demo: http://leaflet.github.io/Leaflet.draw/ My question is how I can determine if a given point reside inside the polygon or not. 回答1: Use the Ray Casting algorithm for checking if a point (marker) lies inside of a polygon: function isMarkerInsidePolygon(marker, poly) { var polyPoints = poly.getLatLngs(); var x = marker.getLatLng().lat, y = marker.getLatLng().lng; var inside = false; for (var i = 0, j = polyPoints.length - 1; i <

Finding an axis-aligned rectangle inside a polygon

烂漫一生 提交于 2019-11-27 01:01:57
问题 I am looking for a good algorithm to find an axis-aligned rectangle inside a (not necessarily convex) polygon. A maximal rectangle would be nice, but is not necessary - any algorithm that can find a "fairly good" rectangle would be fine. The polygon may also have holes, but any pointers to algorithms that only work for convex or simple polygons would be helpful too. In my implementation, intersection testing for sides is fairly cheap, but "point in polygon" tests are expensive, so ideally