Conversion GPS (longitude,latitude) to (x,y) of local reference frame?

I would like to use GPS data as measurement input for an extended kalman filter. Therefore I need to convert from GPS longitude and lattitude to x and y coordinate. I found information about the equirectangular projection given these formulas: $$\ X = r_{earth} \cdot \lambda \cdot cos(\phi_0)$$ $$\ Y = r_{earth} \cdot \phi$$

However I think these formulas are only for use when the axis x- and y-axis of my local frame are parallel to north and south axis of the earth. But my vehicle is starting in my local reference frame in the origin and heading straight in y-direction. In whatever compas angle I put my vehicle, this should always be the starting position. I can measure the angle $\alpha$ to north with a compass on my vehicle.

Now what is the relationship between (longitude,lattitude) an (x,y) of my local frame?

Why not have your starting frame be magnetic north and then adjust your starting position by whatever value your compass is reading?

Set your local frame equal to global frame one time, at the start, and you can use global reference sensors (GPS) without transforming for every sample thereafter (beyond the rectangular transform).

Your alternative (the way you do it), means you don't have to transform the starting sample, but then every sample afterwards you need to get your GPS position, reference that to your start position, then reference your start heading to get to the local frame.

The way you want to do it means you need to find the differential distance and apply a rotation to every sample. Do it the easy way - leave everything in global coordinates.

• Because the track I want to plot with this vehicle is in this frame as I've drawn it. If I measure the available space (like a few m² asphalt), and I know how big the drawing is at max in X and Y direction, than I can position my vehicle the way I want. If the heading is fixed and my drawing in X or Y direction is too wide to fit on that space, it would be a pitty if it would fit on it in another angle.
– Eva
Aug 12 '16 at 10:02
• I could do the rotation calculation in the beginning, if I know the angle and recalculate the coordinates to plot in the new frame, but then why not do it while driving? I have to do the calculcation for the rectangular transform anyway.
– Eva
Aug 12 '16 at 10:05

Using formula's for rotation of frame: $$x' = x \cdot \cos{\alpha} - y \cdot\sin{\alpha}$$ $$y' = x \cdot \sin{\alpha} + y \cdot\cos{\alpha}$$

Could this be the solution? $$X = (r_{earth} \cdot \lambda \cdot cos(\phi_0)) \cdot \cos{\alpha} - (r_{earth} \cdot \phi) \cdot\sin{\alpha}$$ $$Y = (r_{earth} \cdot \lambda \cdot cos(\phi_0)) \cdot \sin{\alpha} + (r_{earth} \cdot \phi) \cdot\cos{\alpha}$$

with $X,Y$ the coordinate of my vehicle in local coordinate system, $r_{earth}$ radius of the earth, $\lambda$ longitude in degrees, $\phi$ latitude in degrees, $\phi_0$ initial measured latitude and $\alpha$ initial measured compass angle

Could anyone please confirm these formulas would work?

Some testing gave me the following solution:

converting from (longitude,latitude) to (X,Y) $$X = r \cdot cos(lat.) \cdot cos(long.)$$ $$Y = r \cdot cos(lat.) \cdot sin(long.)$$

rotating the frame so that the Y-axis is always in front of you $$X' = [r \cdot cos(lat.) \cdot cos(long.)-X_0]\cdot cos(\alpha-90°)- [r \cdot cos(lat.) \cdot sin(long.)-Y_0] \cdot sin(\alpha-90°)$$ $$Y' = [r \cdot cos(lat.) \cdot cos(long.)-X_0]\cdot sin(\alpha-90°)+ [r \cdot cos(lat.) \cdot sin(long.)-Y_0] \cdot cos(\alpha-90°)$$

$r$ : earth radius 6371000 m

$\alpha$ : heading at start (so vehicle pointing east $\alpha = 90°$, pointing north $\alpha = 0°$)

$X_0$ and $Y_0$ : first formula's filled in with start longitude and latitude