The eci coordinate system is the earth centered inertial frame. The z-axis of this coordinate system aligns with the earth's rotation axis. And the x-axis aligns with the direction of vernal equinox. The vernal equinox is the point at which the sun crosses the equator as it moves from the southern hemisphere to the northern hemisphere. In other words, it is the point where the ecliptic plane and the equator plane intersect.
The orbital coordinate system is a two-dimensional coordinate system on the orbital plan. The x-axis aligns with the direction of semi-major axis, the z-axis aligns with the direction of angular momentum, and the y-axis is in the right-handed coordinate system.
When we know the position and velocity of a satellite at a particular time, we can transform its coordinates into the orbital coordinate system and find the classical orbit elements
Let position vector $\vec{r}$ and velocity vector $\vec{v}$
1. Angular Momentum
The angular momentum vector can be found by cross product of the position vector and the velocity vector
$$\vec{h} = \vec{r} \times \vec{v}$$
2. Semi - major
The Semi-major is only related to the total energy. so it can be founded from total energy equation
$$\epsilon = \frac{1}{2}v^2-\frac{\mu}{r}=-\frac{\mu}{2a}$$
$$a = \frac{1}{\frac{2}{r}-\frac{v^2}{\mu}}$$
3. Node vector and right ascension of ascending node
The node vector can be found by cross product of the z-axis vector and the angular momentum vector.
$$\vec{n} = [0,0,1] \times \vec{h}$$
$$\Omega = tan^{-1}(\frac{n(2)}{n(1)})$$
$$0 \leq \Omega \leq 2\pi$$
you should handled quadrant ambiguity using atan2
4. Eccentricity vector
The eccentricity vector can be found from the formula below
$$\vec{e} = (\vec{v}\times\vec{h} - \frac{\mu}{r}\vec{r})/\mu$$
5. Inclination
The inclination means how much is the orbit inclinated from x-y plane, so it is the same as angle between the angular momentum and the z-axis
$$i = cos^{-1}(\frac{\vec{h}\cdot[0,0,1]}{|\vec{h}|}) = cos^{-1}(\frac{h(3)}{norm(\vec{h})})$$
$$0 < i < \pi$$
6. Argument of perigee
The argument of perigee is a angle between node vector and semi-major. So it means how mush is the orbit rotated from ascending node.
$$w = cos^{-1}(\frac{\vec{n}\cdot\vec{e}}{|\vec{n}||\vec{e}|})$$
It has quadrant ambiguity, so we need checking. if $\vec{e}(3) < 0, w=360-w$
7. True anomaly
True anomaly is a angle of satellite from eccentricity in orbit plane.
$$f = cos^{-1}(\frac{\vec{r}\cdot\vec{e}}{|\vec{r}||\vec{e}|})$$
$$0 < f < 2\pi$$
it has quardrant ambifuity
if z-axis element of cross product of the $\vec{e}$ and $\vec{n}$ is negative, $f = 360-f$
And circular orbit has no eccentricity vector, you should handled it well
7. DCM : ECI frame to Orbital frame
ECI to Orbital frame is a 3$(\Omega)$-1$(i)$-3$(w)$ rotation. so it's direction cosine matrix is
$$C_I^{orbit} = R_3(w)R_1(i)R_3(\Omega) =$$
$$\begin{bmatrix} cos(w)cos(\Omega)-sin(w)cos(i)sin(\Omega)& cos(w)sin(\Omega)+sin(w)cos(i)cos(\Omega)& sin(w)sin(i) \\ -sin(w)cos(\Omega)-cos(w)cos(i)sin(\Omega)& -sin(w)sin(\Omega)+cos(w)cos(i)cos(\Omega)&cos(w)sin(i) \\ sin(i)sin(\Omega)& -sin(i)cos(\Omega)& cos(i)\end{bmatrix}$$
Also, direction cosine matrix about orbital frame to eci frame is $[C_I^{orbit}]^T$
Summarize
$a = \frac{1}{\frac{2}{r}-\frac{v^2}{\mu}}$
$\Omega = atan2(n(2), n(1))$
$\vec{e} = (\vec{v}\times\vec{h} - \frac{\mu}{r}\vec{r})/\mu$
$ i = cos^{-1}(\frac{h(3)}{norm(\vec{h})})$
$\begin{cases} w = cos^{-1}(\frac{\vec{n}\cdot\vec{e}}{|\vec{n}||\vec{e}|}) \\ \text{if } \vec{e}(3)<0, w=360-w\end{cases}$
$\begin{cases} f = cos^{-1}(\frac{\vec{r}\cdot\vec{e}}{|\vec{r}||\vec{e}|}) \\ \text{if z-axis element of } \vec{e} \times \vec{n} \text{ is negative, } f = 360-f \end{cases}$
$C_I^{orbit}=$
$\begin{bmatrix} cos(w)cos(\Omega)-sin(w)cos(i)sin(\Omega)& cos(w)sin(\Omega)+sin(w)cos(i)cos(\Omega)& sin(w)sin(i) \\ -sin(w)cos(\Omega)-cos(w)cos(i)sin(\Omega)& -sin(w)sin(\Omega)+cos(w)cos(i)cos(\Omega)&cos(w)sin(i) \\ sin(i)sin(\Omega)& -sin(i)cos(\Omega)& cos(i)\end{bmatrix}$