如何计算边界框的中心? [英] How to calculate the center of the bounding box?

查看:99
本文介绍了如何计算边界框的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用这些给定的点来计算边界框的中心

Im trying to calculate the center of the bounding box with these given points

(50.607041876988994, -1.3187316344406208, 52.40735812301099, 1.5737316344406207)

已解决编辑问题:这是我在python中完成的代码

Edit Solved : This is the code i done in python

from math import cos, sin, atan2, sqrt

    def center_geolocation(geolocations):
        """
        Provide a relatively accurate center lat, lon returned as a list pair, given
        a list of list pairs.
        ex: in: geolocations = ((lat1,lon1), (lat2,lon2),)
            out: (center_lat, center_lon)
        """
        x = 0
        y = 0
        z = 0

        for lat, lon in geolocations:
            lat = float(lat)
            lon = float(lon)
            x += cos(lat) * cos(lon)
            y += cos(lat) * sin(lon)
            z += sin(lat)

        x = float(x / len(geolocations))
        y = float(y / len(geolocations))
        z = float(z / len(geolocations))

        return (atan2(y, x), atan2(z, sqrt(x * x + y * y)))

谢谢:)

推荐答案

from math import *

def center_geolocation(geolocations):
    """
    Provide a relatively accurate center lat, lon returned as a list pair, given
    a list of list pairs.
    ex: in: geolocations = ((lat1,lon1), (lat2,lon2),)
        out: (center_lat, center_lon)
"""
x = 0
y = 0
z = 0

for lat, lon in geolocations:
    lat = float(lat)
    lon = float(lon)
    x += cos(lat) * cos(lon)
    y += cos(lat) * sin(lon)
    z += sin(lat)

x = float(x / len(geolocations))
y = float(y / len(geolocations))
z = float(z / len(geolocations))

return (atan2(y, x), atan2(z, sqrt(x * x + y * y)))


center_geolocation( 
 ((50.607041876988994, -1.3187316344406208),   
  (52.40735812301099, 1.5737316344406207)))

在您给出的示例中没有浮动错误....我不喜欢输出-但这不是问题.

There is not float error in the example you have given .... I do not like the output - but that was not the question.

这篇关于如何计算边界框的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆