I am writing code to simulate a cylinder (with symmetric axis on "z-plane"), containing a fluid (meeting at a boundary). One of the physics equations requires using the divergence theorem, where I think the required "outward" unit normal at the solid/fluid interface will be the "inward" unit normal from the lateral surface going into the fluid.
Here is what I tried
Equation of cylinder of radius r and length h is $F(x,y,z) = x^2 + y^2 - r^2$
Normal is $$\vec{n} = \frac{\nabla{F}}{\sqrt{(\frac{\partial{F}}{\partial{x}})^2 + (\frac{\partial{F}}{\partial{y}})^2 + (\frac{\partial{F}}{\partial{z}})^2}}$$ $$ = \begin{bmatrix}(\frac{x}{r}) \\ (\frac{y}{r}) \\ 0\end{bmatrix}$$
but my calculus is rusty and I am not confident about this.
(1) Is this correct, including the sign?
(2) How can I obtain the two unit tangential vectors from this?
(3) Also, when I did this for 2D using a rectangle for the solid and a rectangle for the fluid, then at the boundary, this outward unit normal was simply (-1,0) pointing into the fluid from the solid part, and the corresponding unit tangential vector was (1,0). I am not sure how to do something similar in 3D.
In general for the normal of a level set of some scalar function $F$, you need to know whether $F$ is bigger inside or outside the level set in order to know whether the gradient of $F$ points in or out. In your case $F$ is bigger on the outside, so the gradient points outward.
If you want to simply use the normal to find a pair of tangent vectors, you can do that by obtaining two independent solutions to $n \cdot v=0$. So here you have
$$\frac{x}{r} v_1 + \frac{y}{r} v_2 + 0 v_3 = 0.$$
One solution is obtained by taking $v_2=1,v_3=0$, another is obtained by taking $v_2=0,v_3=1$. So assuming $x \neq 0$, two tangent vectors are $\begin{bmatrix} -\frac{y}{x} \\ 1 \\ 0 \end{bmatrix}$ and $\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$. The latter is of course already unit. Attempting to make the former unit reveals a way to simplify it to remove the assumption $x \neq 0$, giving $\begin{bmatrix} -y/r \\ x/r \\ 0 \end{bmatrix}$.
You could also have come up with this last vector by noticing that $\begin{bmatrix} x/r \\ y/r \\ 0 \end{bmatrix}=\begin{bmatrix} \cos(\theta) \\ \sin(\theta) \\ 0 \end{bmatrix}$, and then you can "take the negative reciprocal of the slope" by exchanging the $x$ and $y$ components and flipping one of the signs. This also avoids any need to normalize.
I don't really understand your third question.