I'm trying to compute the shadow of 3D objects on the ground. To do this I'm assuming parallel rays from Sun origin.
Let's assume the Sun direction is given by azimuth $\varphi$ and elevation $\theta$ angles. So the direction unit vector is retrieved as:
$$ \hat{\mathbf{s}} = \mathbf{R}_y\left(\theta\right)\mathbf{R}_z\left(\varphi\right)\hat{\boldsymbol{\imath}}$$
where $\mathbf{R}_{x/y/z}$ are the rotation matrices along the $x, y, z$ axes given by, for example, Euler-Rodrigues equation, and $\hat{\boldsymbol{\imath}}$ is the unit vector along $x$-axis.
A point on a ray-line has the equation: \begin{equation} \mathbf{r} = \mathbf{r}_p + \lambda\hat{\mathbf{s}} \tag{1} \end{equation}
being $\mathbf{r}_p$ a point on that line.
A point on a general plane is given by the equation:
\begin{equation} \left(\mathbf{r} - \mathbf{r_0}\right)\cdot \hat{\mathbf{n}} = 0 \tag{2} \end{equation}
being $\mathbf{r}_0$ a point on the plane and $\hat{\mathbf{n}}$ the unit vector normal to that plane.
Ensuring the validity of both equations (1) and (2) allows to compute the $\lambda$ multiplier and retrieve the position vector of the projected point (writing $\tilde{\mathbf{r}} = \mathbf{r_p} - \mathbf{r_o}$)
\begin{gather} \lambda = - \left(\frac{\tilde{\mathbf{r}}\cdot \hat{\mathbf{n}}} {\hat{\mathbf{s}}\cdot\hat{\mathbf{n}}}\right) \\ \mathbf{r}_\text{proj} = \mathbf{r}_p - \left(\frac{\tilde{\mathbf{r}}\cdot \hat{\mathbf{n}}} {\hat{\mathbf{s}}\cdot\hat{\mathbf{n}}}\right)\hat{\mathbf{s}} \tag{3} \end{gather}
Applying eq. (3) to all the vertices of a mesh $\left\{\mathbf{r}_{p_i}\right\}$ gives the shadow.
A problem can be noted: $\hat{\mathbf{s}}\cdot \hat{\mathbf{n}}$ can be zero (e.g. Sun is horizontal, i.e. the ray is ortogonal to the normal of plane).
Are there some conceptual mistakes in my reasoning? Is there a way to rewrite the operation as a linear operator applied to the set of vertices position vectors?
$$ \left[\mathbf{A}\right]\left\{\mathbf{r}_{p_i}\right\} = \mathbf{r}_\text{proj}$$
