sphere.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:s2sphere 作者: sidewalklabs 项目源码 文件源码
def intersects_lat_edge(cls, a, b, lat, lng):
        assert is_unit_length(a)
        assert is_unit_length(b)

        z = robust_cross_prod(a, b).normalize()
        if z[2] < 0:
            z = -z

        y = robust_cross_prod(z, Point(0, 0, 1)).normalize()
        x = y.cross_prod(z)
        assert is_unit_length(x)
        assert x[2] >= 0

        sin_lat = math.sin(lat)
        if math.fabs(sin_lat) >= x[2]:
            return False

        assert x[2] > 0
        cos_theta = sin_lat / x[2]
        sin_theta = math.sqrt(1 - cos_theta * cos_theta)
        theta = math.atan2(sin_theta, cos_theta)

        ab_theta = SphereInterval.from_point_pair(
            math.atan2(a.dot_prod(y), a.dot_prod(x)),
            math.atan2(b.dot_prod(y), b.dot_prod(x)),
        )

        if ab_theta.contains(theta):
            isect = x * cos_theta + y * sin_theta
            if lng.contains(math.atan2(isect[1], isect[0])):
                return True
        if ab_theta.contains(-theta):
            isect = x * cos_theta - y * sin_theta
            if lng.contains(math.atan2(isect[1], isect[0])):
                return True
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号