Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw Camera Range with Postgis

i am working on some camera data. I have some points which consist of azimuth, angle, distance, and of course coordinate field attributes. In postgresql postgis I want to draw shapes like this with functions.

how can i draw this pink range shape? at first should i draw 360 degree circle then extracting out of my shape... i dont know how?

enter image description here

like image 268
Aragon Avatar asked Oct 07 '11 13:10

Aragon


1 Answers

I would create a circle around the point(x,y) with your radius distance, then use the info below to create a triangle that has a larger height than the radius.

Then using those two polygons do an ST_Intersection between the two geometries.

NOTE: This method only works if the angle is less than 180 degrees.

Note, that if you extend the outer edges and meet it with a 90 degree angle from the midpoint of your arc, you have a an angle, and an adjacent side. Now you can SOH CAH TOA!

Extend and make right triangles

Get Points B and C

Let point A = (x,y)

To get the top point:

point B = (x + radius, y + (r * tan(angle)))

to get the bottom point:

point C = (x + radius, y - (r * tan(angle)))

Rotate your triangle to you azimouth

Now that you have the triangle, you need to rotate it to your azimuth, with a pivot point of A. This means you need point A at the origin when you do the rotation. The rotation is the trickiest part. Its used in computer graphics all the time. (Actually, if you know OpenGL you could get it to do the rotation for you.)

NOTE: This method rotates counter-clockwise through an angle (theta) around the origin. You might have to adjust your azimuth accordingly.

First step: translate your triangle so that A (your original x,y) is at 0,0. Whatever you added/subtracted to x and y, do the same for the other two points.

(You need to translate it because you need point A to be at the origin)

Second step: Then rotate points B and C using a rotation matrix. More info here, but I'll give you the formula:

Rotation matrix

Your new point is (x', y')

Do this for points B and C.

Third step: Translate them back to the original place by adding or subtracting. If you subtracted x last time, add it this time.

Finally, use points {A,B,C} to create a triangle.

And then do a ST_Intersection(geom_circle,geom_triangle);

Because this takes a lot of calculations, it would be best to write a program that does all these calculations and then populates a table.

like image 149
Nate Avatar answered Sep 30 '22 00:09

Nate