Discussion:
Angle between three points
Carlos Eduardo
2010-09-17 17:51:37 UTC
Permalink
Hello,

I'm building a google maps application, and I need to do some
calculation with polygons. I have several points in cartesian system
(lat/lng)
that I use to create the polygons. I need to remove some of this points,
because they are irrelevants (i.e. are too close to each other, or is a
point
in the middle of a line, so it could be removed for sure) and are consuming
memory vainly.
So, the logic that I thinked was to get three of the points of the polygon,
and taking the middle point as the origin point, and the two others to
make the lines, and then calc the angle between this two lines. if it is
close to 180 degrees,
i can remove the middle point. And so I would do this sequentially.

I couldn't find a postgis function that can return me the angle between two
lines,
so any suggestions???


Thank you all
Mike Toews
2010-09-17 19:27:39 UTC
Permalink
Post by Carlos Eduardo
So, the logic that I thinked was to get three of the points of the polygon,
and taking the middle point as the origin point, and the two others to
make the lines, and then calc the angle between this two lines. if it is close to 180 degrees,
i can remove the middle point.
I wouldn't be too sure about that. Just because there are three points
in lat/long with 180 degrees apart does not mean that it is a straight
line when projected (e.g., in Google Maps). The distortion increases
when you get near the poles, and when you have large polygons/lines.
It all depends on how the great circles are used/interpreted since
lat/long is _not_ Cartesian, unless you are in a small region near the
equator.

To get to your base question, you can determine the angle of two
points with ST_Azimuth(pointA, pointB). So you can use this function
with some vector math to get the angle between three points. Also, try
ST_Simplify(geomA, tolerance) to see if it does what you are trying to
accomplish. It will probably be easier than reinventing the wheel.

-Mike

Loading...