Solution (source code)

= Solution

The basic <parametric surface interrogation> enquiries provide the parameter domain and patch adjacency; evaluation of $S(u,v)$; first <derivatives> $S_u,S_v$; and, for curvature or error-controlled stepping, second <derivatives> $S_{uu},S_{uv},S_{vv}$. Useful search enquiries also supply conservative <bounding volumes> over parameter rectangles, subdivision or restriction of a patch, and regularity/singularity information. A local inverse or closest-point enquiry can help seed a search but does not replace global component isolation.

At a regular point, $S_u,S_v$ are independent <tangent vectors>, and the oriented unit <normal vector> is
$$
\boxed{n=\frac{S_u\times S_v}{|S_u\times S_v|}.}
$$
The <tangent plane> consists of $S+\alpha S_u+\beta S_v$. If the cross product is zero, this chart does not define a normal; use a regular alternative chart or treat a true singularity separately.

For two surfaces, collect the four parameters in $w=(u_1,v_1,u_2,v_2)$ and set
$$
F(w)=S_1(u_1,v_1)-S_2(u_2,v_2),\qquad
J=DF=[A_1,-A_2],\qquad A_i=[S_{i,u},S_{i,v}].
$$
At a transverse intersection, $n_1\times n_2\ne0$ and $J$ has rank three. Hence the <implicit function theorem> makes $F=0$ locally a curve. Choose its physical unit <tangent vector>
$$
\tau=\frac{n_1\times n_2}{|n_1\times n_2|}.
$$
With $G_i=A_i^TA_i$, the parameter derivatives for physical arc length are
$$
\binom{u_i'}{v_i'}=G_i^{-1}A_i^T\tau.
$$
Since $\tau$ lies in both tangent planes, $A_i(u_i',v_i')^T=\tau$ exactly. Thus these two pairs form a vector $d$ in the kernel of $J$.

A practical <transversal intersection of two parametric surfaces> algorithm is:

* Subdivide parameter patches and reject patch pairs whose certified <bounding volumes> are disjoint. Isolate candidate components, including loops wholly inside a patch; edge crossings or a fixed sampling grid alone are not exhaustive. Obtain corrected seeds for all surviving regular components, using a root search on transverse sections where needed.
* At a seed or current point $w$, evaluate points, derivatives and normals, choose the sign of $\tau$ consistently with the preceding step, and predict $w_p=w+\Delta s\,d$ and $X_p=S_1(w)+\Delta s\,\tau$.
* Correct all four parameters by solving the four equations
$$
F(w_c)=0,\qquad \tau\cdot[S_1(u_{1,c},v_{1,c})-X_p]=0
$$
with <Newton method>. The final equation intersects the curve with the plane through $X_p$ perpendicular to the predicted tangent. Its Jacobian row is $[\tau^TA_1,0,0]$; together with $J$ it is nonsingular at a sufficiently nearby transverse point. This removes the otherwise free along-curve parameter in the three coincidence equations.
* Control $\Delta s$ using correction size, conditioning and curvature/chord error bounds. Reject failed steps and halve the step; keep parameters inside their domains or continue through the declared adjacent patch charts. Store the common corrected point and both parameter pairs.
* Trace both directions until a surface boundary is reached or a previously traced location on the same branch closes the loop. Maintain component/patch records so later seeds do not duplicate an already traced branch, and continue with every remaining seed.

A finite tolerance supplies a polygonal or fitted-curve approximation; regularity and certified bounds determine its accuracy. Parallel normals, singular charts, branch contacts and coincident patches require separate handling: their intersection may be a singular curve, an isolated point or a two-dimensional region. The transverse marching equations must not be used to claim a unique curve in those cases.