使用 Postgis 绘制相机范围
我正在处理一些相机数据。我有一些点,其中包括方位角、角度、距离,当然还有坐标场属性。在 postgresql postgis 中,我想用函数绘制这样的形状。
我怎样才能画出这个粉红色范围的形状? 首先我应该画360度的圆,然后提取出我的形状...我不知道怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会用你的半径距离围绕点(x,y)创建一个圆,然后使用下面的信息创建一个高度大于半径的三角形。
然后使用这两个多边形在两个几何图形之间进行 ST_Intersection。
注意:此方法仅在角度小于 180 度时有效。
请注意,如果延伸外边缘并与弧的中点以 90 度角相交,则会有一个角度和一条相邻边。现在你可以SOH CAH TOA了!
获取点 B 和 C
令点 A = (x,y)
获取顶点:
point B = (x + radius, y + (r * tan(angle)))
得到底点:
点 C = (x + radius, y - (r * tan(angle)))
将三角形旋转到你的方位角
现在 你有三角形,您需要将其旋转到您的方位角,轴心点为 A。这意味着旋转时需要将 A 点置于原点。旋转是最棘手的部分。它一直用于计算机图形学。 (实际上,如果您了解 OpenGL,您可以让它为您执行旋转。)
注意: 此方法围绕原点逆时针旋转一定角度 (theta)。您可能需要相应地调整方位角。
第一步:平移你的三角形,使得A (你原来的 x,y)在 0,0 处。无论您对 x 和 y 添加/减去什么,对其他两点执行相同的操作。
(您需要平移它,因为您需要 A 点位于原点)
第二步:然后使用旋转矩阵旋转 B 点和 C 点。更多信息这里,但我会给你公式:
对 B 点和 C 点执行此操作。
第三步: 将它们平移回原始位置加或减。如果上次减去 x,这次加上。
最后,使用点 {A,B,C} 创建一个三角形。
然后执行 ST_Intersection(geom_circle,geom_triangle);
因为这需要大量计算,所以最好编写一个程序来执行所有这些计算,然后填充表。
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!
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:
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.
PostGIS 支持曲线,因此实现此目的的一种可能需要较少数学的方法是执行以下操作:
这描述了一个原点为 0,0、半径为 10 度(地理坐标)和开口的扇区45°角。
用附加函数包装它,将其从真实曲线转换为 LINESTRING,降低坐标精度,并将其转换为 WKT:
给出:
这需要几块的它具有预先计算的信息(中心的位置、两个相邻顶点以及线段边缘上的另一个点),但它具有实际生成真正弯曲的几何图形的明显优势。它还适用于张角大于 180° 的段。
提示:示例中使用的
7.071
x 和 y 位置可以这样计算:x = {radius} cos {angle} = 10 cos 45 ≈ 7.0171
y = {半径} sin {角度} = 10 sin 45 ≈ 7.0171
极端情况:在反子午线和两极。
PostGIS supports curves, so one way to achieve this that might require less math on your behalf would be to do something like:
This describes a sector with an origin at 0,0, a radius of 10 degrees (geographic coordinates), and an opening angle of 45°.
Wrapping that with additional functions to convert it from a true curve into a
LINESTRING
, reduce the coordinate precision, and to transform it into WKT:Gives:
This requires a few pieces of pre-computed information (the position of the centre, and the two adjacent vertices, and one other point on the edge of the segment) but it has the distinct advantage of actually producing a truly curved geometry. It also works with segments with opening angles greater than 180°.
A tip: the
7.071
x and y positions used in the example can be computed like this:x = {radius} cos {angle} = 10 cos 45 ≈ 7.0171
y = {radius} sin {angle} = 10 sin 45 ≈ 7.0171
Corner cases: at the antimeridian, and at the poles.