how to calculate the 3D cartesin position of a point based on lat and long?

I want to implement a code, where I get a user's latitude and longitude, and I will position it on a x, y, z cartezian plane, where (0,0,0) is the center of the earth.

My order of magnitude will be in millimeters, but if it is possible to leave it and a variable format, it will help a lot too.

I thought of something like:

Lo = longitude and La = latitude
So:
x = rcos (La) cos (Lo)
y = rcos (La) sin (Lo)
z = rsin (La)


can someone tell me if this is right? and how do I have these rapids in order of magnitude of millimeters?

$$X = \left(N\left(\phi\right)+h\right)\text{cos }\phi\text{ cos }\lambda$$ $$Y = \left(N\left(\phi\right)+h\right)\text{cos }\phi\text{ sin }\lambda$$ $$Z = \left(\frac{b^2}{a^2}N\left(\phi\right)+h\right)\text{ sin }\phi$$ $$\text{Where:}$$ $$N\left(\phi\right)=\frac{a}{\sqrt{1-e^2\text{ sin}^2\phi}}$$ $$e^2=1-\frac{b^2}{a^2}$$ $$a=6378137\text{ m (in WGS84)}$$ $$b=6356752.314\text{ m (in WGS84)}$$ ($$\phi, \lambda, h$$ are respectively latitudes, longitudes and ellipsoidal heights)