Helix and osculating circles ============================ This example generates a graphic representation of the helix 3D curve, parametrized on the arc lenght, and using some intrinsic vectors (tangent and normal) computes the curve of the center of curvature and displays both curves and the osculating circle in a given position. Helix curve ----------- Parametric representation of the curve as a function of the radius 'a' and the height 'b'. The function return the triple of coordinate functions < x(a,b), y(a,b), z(a,b) > // ------------------------------------------------------------------------- DEF helix (a,b::IsReal) = WHERE u = ID / SQRT ~ K:(a*a + b*b) END; ------------------------------------------------------------------------- Tangent curve ------------- returns the "helixtangent" curve having as coordinate functions the first derivatives of the "helix" curve. // ------------------------------------------------------------------------- DEF helixtangent (a,b::IsReal) = AA:D:(helix:); ------------------------------------------------------------------------- Normal and binormal curve ------------------------- returns the "helixnormal" curve, having as coordinate functions the first derivatives of the "helix" curve, and the and "helixbinormal" generated as the vector product of the previous ones. Please notice that the "VectProd" operator send two vector functions to a vector function. // ------------------------------------------------------------------------- DEF helixnormal (a,b::IsReal) = K:((a*a + b*b)/a) scalarVectProd AA:(D ~ D):(helix:); DEF helixbinormal (a,b::IsReal) = helixtangent: VectProd helixnormal:; ------------------------------------------------------------------------- Curvature center and Osculating circle -------------------------------------- // ------------------------------------------------------------------------- DEF helixcurvatureCenter (a,b::IsReal) = helix: vectSum (K:((sqr:a + sqr:b)/a) scalarVectProd helixnormal:) ; DEF helixOsculCircle (a,b,s::IsReal) = (T:<1,2,3>:center ~ Rotn:):circle WHERE circle = MAP:((circle3D ~ radius):):(intervals:(2*PI):24), angle = (- ~ ACOS ~ InnerProd):>, axis = CONS:(helixnormal:):s, center = CONS:(helixCurvatureCenter:):s, ortho = CONS:(helixbinormal:):s END; ------------------------------------------------------------------------- A small auxiliary toolkit ------------------------- // ------------------------------------------------------------------------- DEF circle3D (r::IsReal) = [K:r * COS, K:r * SIN, K:0] ~ s1; DEF radius (a,b,s::IsReal) = (VectNorm ~ VectDiff): < CONS:(helix:):s, CONS:(helixcurvatureCenter:):s >; DEF CurveGraph (f::IsSeqOf:IsFun) = MAP:(CONS:f ~ s1):(intervals:(6*PI):90); ------------------------------------------------------------------------- The final output ---------------- STRUCT is the PLaSM generator of hierarchical assemblies, used in this case to aggregate the geometrical values generated by the three expressions within its input sequence into the same reference frame. The "out" value adds to the "assembly" value its boxed-projection in the 'x,y' subspace. // ------------------------------------------------------------------------- DEF assembly = STRUCT:< (CurveGraph ~ helix):<1,2>, (CurveGraph ~ helixcurvatureCenter):<1,2>, (JOIN ~ helixOsculCircle):<1,2, 2*PI> >; DEF out = (STRUCT ~ [ID, BOX:<1,2>]):assembly VIEW:out -------------------------------------------------------------------------