DEF helix (a,b::IsReal) = <K:a * cos ~ u, K:a * sin ~ u, K:b * u> WHERE u = ID / SQRT ~ K:(a*a + b*b) END;
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.
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) = <K:a * cos ~ u, K:a * sin ~ u, K:b * u> WHERE u = ID / SQRT ~ K:(a*a + b*b) END;
returns the "helixtangent" curve having as coordinate functions the first derivatives of the "helix" curve.
DEF helixtangent (a,b::IsReal) = AA:D:(helix:<a,b>);
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:<a,b>);
DEF helixbinormal (a,b::IsReal) = helixtangent:<a,b> VectProd helixnormal:<a,b>;
DEF helixcurvatureCenter (a,b::IsReal) = helix:<a,b> vectSum (K:((sqr:a + sqr:b)/a) scalarVectProd helixnormal:<a,b>) ; DEF helixOsculCircle (a,b,s::IsReal) = (T:<1,2,3>:center ~ Rotn:<angle, axis>):circle WHERE circle = MAP:((circle3D ~ radius):<a,b, s>):(intervals:(2*PI):24), angle = (- ~ ACOS ~ InnerProd):<ortho,<0,0,1>>, axis = CONS:(helixnormal:<a,b>):s, center = CONS:(helixCurvatureCenter:<a,b>):s, ortho = CONS:(helixbinormal:<a,b>):s END;
DEF circle3D (r::IsReal) = [K:r * COS, K:r * SIN, K:0] ~ s1; DEF radius (a,b,s::IsReal) = (VectNorm ~ VectDiff): < CONS:(helix:<a,b>):s, CONS:(helixcurvatureCenter:<a,b>):s >; DEF CurveGraph (f::IsSeqOf:IsFun) = MAP:(CONS:f ~ s1):(intervals:(6*PI):90);
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