15,568,965 members
See more:
I am trying to create an indoor map and track the user inside a building. All I have is a simple image of the floor plan, with each corner having a certain lon/lat.

The problem is that the floor plan of the building is not aligned north and is in an awkward position on an actual map:

[Position of building image on an actual map]

I've tried numerous different formulas and calculations and they were loosely accurate when the lon/lat point was somewhere in the middle of the image between the top left and bottom right. Any deviation towards the bottom left or top right and the results got wild.

I think it might be weird because of how weirdly the image is rotated.

Is there any formula I've missed that would help here?

What I have tried:

I have tried pretty much the exact same code as used in the sources below, using the lat/lon of the top left (0, 0) of the image as my min and the bottom right as my max:

https://www.codeproject.com/Questions/1156300/Convert-longitude-and-latitude-coordinates-to-imag

android - How to plot a GPS location on an image being used as a map? - Stack Overflow[^]

java - get x y coordinates of image of particular longitude latitude and vice versa - Stack Overflow[^]
Posted
Updated 30-Dec-20 10:44am
v2

## Solution 1

The floor plan is just another "coordinate system".

Create another "layer" for the floor plan; work within that using it's coordinate system; then "rotate" it to align with the other "layer(s)" / coordinate systems.

I'll venture that the user will want to be able to rotate the whole building at some point so they can "face" a particular direction (that suits them).

## Solution 2

```// cx, cy - center of square coordinates
// x, y - coordinates of a corner point of the square
// theta is the angle of rotation

// translate point to origin
float tempX = x - cx;
float tempY = y - cy;

// now apply rotation
float rotatedX = tempX*cos(theta) - tempY*sin(theta);
float rotatedY = tempX*sin(theta) + tempY*cos(theta);

// translate back
x = rotatedX + cx;
y = rotatedY + cy;```

Finding the center might be the hard part though, if it's not a rectangle.