如何从(0,0)开始以长度和角度获取2D坐标

问题描述 投票:0回答:1

我有以下坐标

[-20, -20], [-20, 20], [-40, 0], [-40, 20], [-40, 40], [-20, 80], [20, 80], [40, 40], [80, 20], [80, -20]. 

我的任务是从[0,0]获得坐标起点。我可以从上面给定的坐标获得角度和长度。角度应介于0到360之间。

假设我现在没有原始坐标。我需要计算从0,0开始的角度和长度的坐标。我需要当前坐标,前一个坐标和下一个坐标。

例如:如果当前坐标段的长度为5,则坐标为(0,0)(0,5)。前置项的终点为(0,0),后继的起点为(0,5) )。

可能是什么公式,我需要计算记住象限并最终旋转它?

要找到我在象限1中使用的下一个和前一个坐标.x1=x+l * cos(angle), y1=y+l * sin(angle)

在我的情况下,上述公式如何改变w.r.t象限,或者它们是相同的。

x1=x-l*cos(angle), y1=y-l*sin(angle) etc (change w.r.t quadrants).

帮我看看。

实际图:

红色是当前的,蓝色是前身,黑色是后继者。

javascript math svg geometry computational-geometry
1个回答
0
投票

不是java,而是python,因为它被标记为'计算几何'。您可以根据需要进行翻译

不完全确定这是你需要的,但你有一个中心和一系列要点。可以计算角度(即从北方开始的方位角)和到这些点的距离。

如果它不是需要的,那么你可以从中取出你需要的东西。

a = np.array([[-20, -20], [-20, 20], [-40, 0], [-40, 20], [-40, 40], [-20, 80], [20, 80], [40, 40], [80, 20], [80, -20]])
pnt = np.array([0,0]

import numpy as np

def e_dist(a, b, metric='euclidean'):
    """Distance calculation for 1D, 2D and 3D points using einsum

    `a`, `b` : array like
        Inputs, list, tuple, array in 1, 2 or 3D form
    `metric` : string
        euclidean ('e', 'eu'...), sqeuclidean ('s', 'sq'...),
    -----------------------------------------------------------------------
    """
    a = np.asarray(a)
    b = np.atleast_2d(b)
    a_dim = a.ndim
    b_dim = b.ndim
    if a_dim == 1:
        a = a.reshape(1, 1, a.shape[0])
    if a_dim >= 2:
        a = a.reshape(np.prod(a.shape[:-1]), 1, a.shape[-1])
    if b_dim > 2:
        b = b.reshape(np.prod(b.shape[:-1]), b.shape[-1])
    diff = a - b
    dist_arr = np.einsum('ijk,ijk->ij', diff, diff)
    if metric[:1] == 'e':
        dist_arr = np.sqrt(dist_arr)
    dist_arr = np.squeeze(dist_arr)
    return dist_arr



def radial_sort(pnts, cent=None, as_azimuth=False):
    """Sort about the point cloud center or from a given point

    `pnts` : points
        An array of points (x,y) as array or list
    `cent` : coordinate
        list, tuple, array of the center's x,y coordinates
    >>> cent = [0, 0] or np.array([0, 0])

    Returns:
    -------
        The angles in the range -180, 180 x-axis oriented

    """
    pnts = np.asarray(pnts, dtype=np.float64)
    if cent is None:
        cent = _center(pnts, remove_dup=False)
    ba = pnts - cent
    ang_ab = np.arctan2(ba[:, 1], ba[:, 0])
    ang_ab = np.degrees(ang_ab)
    sort_order = np.argsort(ang_ab)
    if as_azimuth:
        ang_ab = np.where(ang_ab > 90, 450.0 - ang_ab, 90.0 - ang_ab)
    return ang_ab, sort_order

现在如果你使用上面的'a'和'pnt',你会得到以下结果。

    dist = e_dist(a, pnt)
    angles = radial_sort(a, pnt, True)[0]

    dist
    Out[36]: 
    array([28.284, 28.284, 40.   , 44.721, 56.569, 82.462, 82.462, 56.569, 82.462,
           82.462])

    angles
    Out[37]: 
    array([225.   , 315.   , 270.   , 296.565, 315.   , 345.964,  14.036,  45.   ,
            75.964, 104.036])
© www.soinside.com 2019 - 2024. All rights reserved.