2

I am trying to create indoor positioning functionality in my app. So i did following things

1 : Took one floor map image and based on meter i set pixel for image so i can get proper location of beacon placed on map

2 : now by RSSI value of beacons i am getting distance in meter between BLE and iPhone

3 : now i am trying to use Trilateration algorithm so i can get proper location of user.

Now i am getting distance properly from device to phone but when i try to find location of phone i am using Trilateration algorithm, but every time i am getting same response, weather distance is high or low

so here it's my code for Trilateration algorithm.

func getCoordinateWithBeaconA(_ a: CGPoint, beaconB b: CGPoint, beaconC c: CGPoint, distanceA dA: CGFloat, distanceB dB: CGFloat, distanceC dC: CGFloat) -> CGPoint {
    var W: CGFloat
    var Z: CGFloat
    var x: CGFloat
    var y: CGFloat
    var y2: CGFloat
    W = dA * dA - dB * dB - a.x * a.x - a.y * a.y + b.x * b.x + b.y * b.y
    Z = dB * dB - dC * dC - b.x * b.x - b.y * b.y + c.x * c.x + c.y * c.y

    x = (W * (c.y - b.y) - Z * (b.y - a.y)) / (2 * ((b.x - a.x) * (c.y - b.y) - (c.x - b.x) * (b.y - a.y)))
    y = (W - 2 * x * (b.x - a.x)) / (2 * (b.y - a.y))
    //y2 is a second measure of y to mitigate errors
    y2 = (Z - 2 * x * (c.x - b.x)) / (2 * (c.y - b.y))

    y = (y + y2) / 2

    let roundedX : Float = Float(String(format: "%.6f", x)) ?? 0.0
    let xValue : CGFloat = CGFloat(roundedX)

    let roundedY : Float = Float(String(format: "%.6f", y)) ?? 0.0
    let yValue : CGFloat = CGFloat(roundedY)
    return CGPoint(x: xValue, y: yValue)
}

Please let me know if i am doing anything wrong.

0 Answers0