This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Point in Polygon aka hit test
I need some help for my problem ;):
I've got a polygon definied with 3 or more longitude/latitude points.
Now I've got another longitude/latitude point and I need to check if this point is in the polygon area or not.
I need this function in .NET. Can anyone help me?
Thank you very much for your help.
Here is one answer: http://alienryderflex.com/polygon/
You could also use Microsoft's Geometry classes. Create two geometries (one point, one polygon), then do an Intersection of them. If there is an intersection
http://msdn.microsoft.com/en-us/library/system.windows.media.combinedgeometry.geometrycombinemode.aspx
If these methods take too long, you could first wrap the polygon in a bounding box and test if the point is within the min/max lat/long of the box
Note: If your polygon crosses international dateline you may need to add additional code up front before these tests (i.e. add 360 degrees to longitude of polygon's vertices and to point if the longitude is negative so the algorithms work).
Related
I have a question. I am trying to calculate the area of the following layer (see picture)
intersect area
I used the intersection tool to find the intersection between the layer of 4 overlapping buffers with another polygon (transformed from raster and therefore consists of many other polygons). This layers now consists of more than 200 polygons and most of them on top of each other. I actually want to calculate the 2D area of this layer, so I actually want to transform this layer of many polygons into one polygon so that you are able to calculate the area of this one polygon. My question is therefore, is there a possibility to transform this layer into polygons that are adjacent of each other and that there are no overlapping polygons anymore so I can calculate the area? Maybe there is another way to do this?
If understand your question correctly, you should be able to use the Dissolve Boundaries tool in ArcGIS; dissolve into one polygon; then calculate the area of that polygon.
The two most common point in polygon test methods (Ray casting method and Winding number method) does not work in my case, when the polygon looks like below:
As you can see, the polygon is splitted by the boundaries of coordinate system. Points A and B are inside, C is outside. All of the methods posted in other threads failed for such polygon. Any idea or a good algorithm? A working C# implementation would be really helpful!
In the meantime I've found the solution.
But first a better visualization of the problem, below is the polygon displayed on the surface of a cylinder, where the vertical dashed line represent both beginning and end of X coordinate range of values:
The original polygon must be divided into 2 subpolygons by the coordinate system boundary "line" and algorithm must be executed on those 2 subpolygons.
For drawing or any visualization however still the original polygon must be used.
This question already has answers here:
How to calculate Tangent and Binormal?
(4 answers)
Closed 9 years ago.
Currently I am trying to do some bump mapping but would like to know how to find the tangents of a flat surface. I have already defined my normals but not sure about tangents, I have drawn a diagram and would like some confirmation on whether this is correct or not.
T representing tangent and N representing normals
Here is a link for you showing pretty pictures for tangents and explaining why certain directions for tangents are chosen. Keep in mind that any vector that is perpendicular to the normal is a valid tangent (an entire circle of vectors around the normal that will travel along the tangent plane.) Therefore, your diagram is technically correct. The tangent (and bitangent) vectors aren normally chosen to move along the positive U and V direction of the texture at right angles to each other though to simplify bump/normal mapping. See the link.
I have a set of dense, irregurarly distributed 2D points ("scattered all over the place"). They can be stored in a single MULTIPOINT WKT object including "holes" or - if needed - as delaunay triangles.
How would you convert this into a polygon, i.e. one outer boundary and zero, one or more inner boundaries?
P.S. It's not the largest enclosing polygon I'm looking for (that would be solved by ConvexHull or ConcaveHull). I'm looking for a true polygon with the same shape as the scattered point set (including inner boundary).
Your question reads to me like “find a polygon which has a given set of points as vertices.” Is that interpretation correct?
If so, you can do the following: Create the convex hull of your points. Remove those points from consideration, and take the convex hull of the remaining points. Proceed in this fashion until there are no more remaining points. The intermediate result will be a sequence of convex polygones nested inside one another. You can turn them into a single polygon by connecting each subsequent pair of polygons. You connect two polygons by removing an edge from each, and connecting the resulting endpoints ”the other way round”. Some care has to be taken that these connections don't overlap anything else, but that shouldn't be too hard.
Note that there are many possible results fulfilling the specification as I read it. If you need a specific one, you'll have to give details on the criteria for that choice.
Use QHull: http://www.qhull.org/
It is the de facto standard for this sort of thing.
I'm writing a mapping application that I am writing in python and I need to get the lat/lon centroid of N points.
Say I have two locations
a.lat = 101
a.lon = 230
b.lat = 146
b.lon = 200
Getting the center of two points is fairly easy using a euclidean formula. I would like
to be able to do it for more then two points.
Fundamentally I'm looking to do something like http://a.placebetween.us/ where one can enter multiple addresses and find a the spot that is equidistant for everyone.
Have a look at the pdf document linked below. It explains how to apply the plane figure algorithm that Bill the Lizard mentions, but on the surface of a sphere.
poster thumbnail and some details http://img51.imageshack.us/img51/4093/centroidspostersummary.jpg
Source: http://www.jennessent.com/arcgis/shapes_poster.htm
There is also a 25 MB full-size PDF available for download.
Credit goes to mixdev for finding the link to the original source, and of course to Jenness Enterprises for making the information available. Note: I am in no way affiliated with the author of this material.
Adding to Andrew Rollings' answer.
You will also need to make sure that if you have points on either side of the 0/360 longitude line that you are measuring in the "right direction"
Is the center of (0,359) and (0, 1) at (0,0) or (0,180)?
If you are averaging angles and have to deal with them crossing the 0/360 then it is safer to sum the sin and cos of each value and then Average = atan2(sum of sines,sum of cosines)
(be careful of the argument order in your atan2 function)
The math is pretty simple if the points form a plane figure. There's no guarantee, however, that a set of latitudes and longitudes are that simple, so it may first be necessary to find the convex hull of the points.
EDIT: As eJames points out, you have to make corrections for the surface of a sphere. My fault for assuming (without thinking) that this was understood. +1 to him.
The below PDF has a bit more detail than the poster from Jenness Enterprises. It also handles conversion in both directions and for a spheroid (such as the Earth) rather than a perfect sphere.
Converting between 3-D Cartesian and ellipsoidal latitude, longitude and height coordinates
Separately average the latitudes and longitudes.