How to place marker inside google maps polygon - google-maps-api-3

How to place marker inside polygon (this polygon already on map)?
My thoughts are: find a way to inscribe for example circle to the polygon and find a center of this circle (it is not problem), but can't find way to inscribe circle.
Method getCenter() on LatLngBounds works not as expected, because math center of polygon can be out of this polygon visually.

As said Dr.Molle this is really duplicate of this question. So, for get center of polygon need to use programm realization of anything math algorithm for find center of polygon, there is no more easy way unfortunately.

Related

Google Maps API v3 - circle sector

I would like to draw sector of circle on map defined by point, radius, startAngle and stopAngle. I found lots of exmaples but with polygons etc whitch was too complicated for my case.
Thanks for any help!
a Circle is an object with no defined sides. Only a radius and a center point.
You are required to use a polygon to build a semi circle as it is a two sied object
There is not always an easy way out in coding, and typicaly they are the bad ways to do things (unless your talking about somthing like JQ/Bootstrap)
Here is a fairly stright forware implementation
http://googlemaps.googlermania.com/google_maps_api_v3/en/draw-semi-circle.html
This was refered in this question
Google Maps Polygon Incorrectly Rendered
they even provide a working example for you to rip apart
http://maps.forum.nu/temp/gm_bearing.html

Get Bounding Box from a lat/lon polygon

i have a list of boundaries (polygons) and a list of ways all represented by latitudes and longitudes. i would like to find out if one way is inside a polygon.
i do this in perl but cant find anything useful to calculate. Math::Polygon (::Calc) has interesting functions, but not for lat/lon only for x/y.
So im thinking about making it easier and generating a bounding box of each polygon, so its easier for me to check if one point of a way is inside a bounding box.
Does anyone know how the algorithm looks like to get the bounding box. a pseudo code would be enough so i can code it in perl.
It would be even better to check for being inside a polygon without converting a polygon into a bounding box, but i wasnt able to find anything useful on the net. There are some for simple 2d x/y based coordinate systems, but not for spherical lat/lon.
First, place the start and end points of each of the polygon's line segments in an array. Then iterate over the array to find MinX, MinY, MaxX and MaxY. Then the point (MinX, MinY) is the lower left corner of your box, and (MaxX, MaxY) is the upper right corner.

Forcing polygon inside/outside in Google Maps V3?

My question is similar to this one on another SE site, which didn't seem to get answered very usefully:
https://gis.stackexchange.com/questions/10741/google-maps-js-api-v3-polygon-formation
I'm trying to shade large areas of the globe in Google Maps V3 using polygons. My issue is that that algorithm decides on its own which part of the map is "inside" the polygon and which is "outside".
From what I've been able to tell, the map always sets the South pole outside the polygon. Example jsfiddle: http://jsfiddle.net/YFJ6a/6/
I'm guessing from earlier questions about filling in the area outside a polygon (eg. Google Maps Polygon Outer Fill) that there's no way to simply invert a polygon. I've had some success in using the method described in the link, combining my polygon with a polygon that tightly circles the South pole:
[new google.maps.LatLng(-89.99,180), new google.maps.LatLng(-89.99,-120),
new google.maps.LatLng(-89.99,-60), new google.maps.LatLng(-89.99,0),
new google.maps.LatLng(-89.99,60), new google.maps.LatLng(-89.99,120),
new google.maps.LatLng(-89.99,180)]
The path above generates a polygon that covers pretty much the entire globe. But this is messy and only works if my shape doesn't actually intersect with this polygon, which I can't guarantee. (It's easy for me to wind up with polygons that cross directly at the pole, for example.)
Is there any cleaner or more direct way to accomplish this?

2d point to 3d point on a sphere

i haven’t been entirely sure what to google or search for to help solve my problem, really hoping someone here can help a little…
currently i have a 3d scene, it has a massive sphere with a texture mapped to it and the camera at the center of the sphere, so it’s much like a qtvr viewer.
i’d like a way to click on the polygons within the sphere and update the texture at that position with something and dot etc..
the only part of the process where i need help is converting the 2d mouse position to a point on the inside of the sphere.
hope this makes sense…
fyi, im only looking for a pure math solution..
The first thing you need to do is convert the screen coordinate into a line in 3d space. This will pass through the point you click and your eyepoint.
Once you have this line you can then intersect this line with your sphere to find the intersection point on the sphere.
You may get 2d coordinates of the polygons (triangles?) that are making up the sphere and then find the one that contains the mouse pointer point.

Collision detection with oddly shaped polygons

I am planning to make a program which will have some circular shapes moving inside of a oddly shaped Polygon.
I can't seem to figure out how to do the collision detection with the edges and have the shapes bounce back correctly.
I am sure this problem has been solved before, but I can't find a nice example.
My main problems are:
Figuring out if the circle has hit the edge of its surrounding polygon.
Once a hit occurs calculate the normal of the hit point to figure out the reflection vector.
Can anyone point me in the right direction?
Thanks, Jason
You need to do a circle line intersection test.
To make it faster, you can first check the bounding boxes. For example, if the start and end point of the line are both to the left of the leftmost coordinate of the circle, there can't be an intersection.

Resources