Finite Element Analysis (FEA): 3D Surface Normal Cross Product
Problem Statement
In 3D CAD modeling and finite element stress analysis:
Given three 3D vertices of a planar triangle: $A(x_1, y_1, z_1)$, $B(x_2, y_2, z_2)$, $C(x_3, y_3, z_3)$ in counter-clockwise order:
Write a function that calculates the **unit normal vector** $\hat{n} = (n_x, n_y, n_z)$ perpendicular to the triangle surface using the cross product:
$$\vec{u} = B - A, \quad \vec{v} = C - A$$
$$\vec{N} = \vec{u} \times \vec{v}$$
$$\hat{n} = \frac{\vec{N}}{\|\vec{N}\|}$$
Format each component to 1 decimal place (e.g., `0.0 0.0 1.0`).
### Input Format
- Line 1: `Ax Ay Az`
- Line 2: `Bx By Bz`
- Line 3: `Cx Cy Cz`
### Output Format
- Print three space-separated floats: `nx ny nz`, each formatted to 1 decimal place.
### Constraints
- Vertices define a non-degenerate triangle (magnitude of cross product $> 0$).
Sample Cases
Example 1Sample Case
Input: 0 0 0
1 0 0
0 1 0
Output: 0.0 0.0 1.0
Example 2Sample Case
Input: 0 1 0
1 0 0
0 0 0
Output: 0.0 0.0 -1.0
Example 3Sample Case
Input: 0 0 0
-1 0 0
0 -1 0
Output: 0.0 0.0 1.0
Example 4Sample Case
Input: 0 0 2
0 2 0
0 0 0
Output: -1.0 0.0 0.0
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.