Python找到一个点相对于其他四个已知点的x,y位置

2024-04-27 10:38:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想再加一个接受者或者换言之是第四个点。关于如何修改此函数以在绘图中找到与四个蓝点(已知X,y位置)相关的红色X(具有X,y形式和未知坐标),而不是仅三个(请参见下面的绘图链接),有什么想法吗?你知道吗

注意:我没有做多向定位。我正在根据信号功率来定位。函数中返回的公式来自Power ~ 1/R^2,(R是距离)&功率比是gammajk = Pj/Pk = Rk^2/Rj^2。你知道吗

% pylab inline
import pylab
from scipy.optimize import fsolve

Solving nonlinear equations with fsolve

    def equations(p):
        # Define these outside of the function before calling this function.
        global gamma01,x0,y0,gamma12,x1,y1,x2,y2,gamma10
        # x,y represent the red-X & x1,y1,x2,y2,... represent Blue dots (Recievers)
        x,y = p
        # The returned equations are from Power ~ 1/r**2, so
        # the power ratio gammajk = Pj/Pk = rk**2/rj**2.
        return ( gamma01*(x1-x)**2+gamma01*(y1-y)**2-(x0-x)**2-(y0-y)**2,
                 gamma12*(x2-x)**2+gamma12*(y2-y)**2-(x1-x)**2-(y1-y)**2 )

    gamma01 = 1.0  # Received power antenna 1 over received power antenna 0
    gamma12 = 1.0  # Received power antenna 2 over received power antenna 1

    x0,y0 = 0.0, 1000.0  # Position receive antenna 0
    x1,y1 = 1000.0, 0.0  # Position receive antenna 1
    x2,y2 = 0.0, -1000.0 # Position receive antenna 2

    # Numerically solve our nonlinear system of equations
    # (1.0,1.0) is the initial guessed position
    x, y =  fsolve(equations, (1.0, 1.0))
    print('answer x y (m)',x,y)

    pylab.figure()
    pylab.plot([x0,x1,x2],[y0,y1,y2],'bo',markersize=8.0,label='Receive Antenna')
    pylab.plot([x],[y],'rx',markersize=8.0,label='Transmitter')
    pylab.axis('equal')
    pylab.xlabel('x (m)')
    pylab.ylabel('y (m)')
    pylab.title('All Power Ratios = 1.0')
    pylab.legend()
    pylab.grid()
    pylab.show()

绘图:在蓝点之间找到红x Finding red-x in between Blue dots


Tags: the绘图powerx1x2antennay1pylab