%----------------------------------------------------------% %---Rational curves----------------------------------------% %----------------------------------------------------------% DEF myRationalize (functions::IsSeq) = (RTAIL ~ AA:NoExceptionDiv ~ DISTR): WHERE nth = LAST:functions, NoExceptionDiv = IF: END; % DEF out = Rationalize:<1, 2, 3, 4, 5>; % % DEF out = Rationalize:<1, 2, 3, 4, 0>; % DEF myRationalBlend (Basis::IsSeq) (ControlPoints::IsSeq) = myRationalize:( Blend:Basis:ControlPoints ) ; DEF myRationalBezier (ControlPoints::IsSeq) = myRationalBlend:(bernsteinbasis:S1:degree): ControlPoints WHERE degree = LEN:ControlPoints - 1 END; DEF myellipse (a,b::IsReal)(n::IsINtPos) = STRUCT:< half, S:1:-1, half > WHERE half = STRUCT:< quarter, S:2:-1, quarter >, quarter = MAP: mapping: (Intervals:1:n), mapping = myRationalBezier:<,,<0,b,1>>, c = SQRT:2/2 END; DEF out = myellipse:<1/2,1>:10; DEF out = myellipse:<1/2,1>:10 * QUOTE:<1/2>; %------------------------------------------------------------% %---NON UNIFORM RATIONAL B-SPLINES---------------------------% %------------------------------------------------------------% %------------------------------------------------------------% %---NURBSpline operator-------------------------------------% %------------------------------------------------------------% DEF myRationalBspline (dom::Ispol)(degree::Isint)(knots::IsSeq)(points::IsSeq) = STRUCT:maps WHERE order = degree + 1, basis = BsplineBasis: order: knots, segmentmaps = (AA:(INSL:APPLY ~ AL) ~ DISTL): < RationalBlend, (AA:TRANS ~ subsets:order ~ TRANS):< basis, points >>, domain = AS:SEL:(order..(LEN:points+1)): knots, nonempty = AS:SEL~CAT ~ AA:(IF:< EQ~S1, K:<>, [S2] >) ~ TRANS ~ [ID,INTSTO~LEN], nondegenerate = nonempty: subdomains, subdomains = subsets:2:domain, poldoms = AA:(STRUCT~[T:1~S1, S:1~(S2 - S1), K:dom]):subdomains, maps = (AA:(INSL:APPLY)~ nondegenerate ~TRANS): < #:(LEN:domain - 1):MAP, segmentmaps, poldoms >, subsets (h::IsIntPos)(seq::IsSeq) = (CONS ~ AA:(AS:SEL ~ FROMTO ~ [ID - K:h + K:1,ID])):(h..LEN:seq):seq END; DEF myNURBspline = myRationalBspline:(intervals:1:mysplineSampling); DEF myNURBsplineKnots = myRationalBspline: Knotzero WHERE Knotzero = MK:<0> END; %------------------------------------------------------------% %----NURBSpline display--------------------------------------% %------------------------------------------------------------% DEF myDisplayNURBspline (degree::Isint; knots::IsSeq ; points::IsSeq ) = (STRUCT ~ [ IF:< K:(GT:0:degree), myNURBspline:degree:knots, polymarker:3 >, polymarker:2 ~ S1 ~ UKPOL ~ myNURBsplineKnots:degree:knots , polyline, polymarker:1 ]): points; DEF mysplineSampling=11; DEF NurbCircle=STRUCT:, DisplayNUBspline:<2,knots,ctrlPts>> WHERE knots=<0,0,0,1,1,2,2,3,3,4,4,4>, ctrlPts=<<-1,0,1>,<-:c,c,c>, <0,1,1>,, <1,0,1>,, <0,-1,1>,<-:c,-:c,c>,<-1,0,1>>, c=(SQRT:2)/2 END; DEF mysplineSampling=10; DEF testNURB(homCoord::IsReal)=myDisplayNURBspline:<2,knots,ctrlPts> WHERE knots=<0,0,0,1,2,3,3,4,5,6,7,8,9,9,9>, ctrlPts=<<0,5,1>,<4,5,1>,<5,5,1>,<5,4,1>,<5,0,1>,<4,0,1>,<4,3,1>,<2,1,1>, <-1,0,1>,<-6,0,homCoord>,<0,3,1>,<0,5,1>> END; DEF out=testNurb:1; DEF out=STRUCT:(AA:testNurb:(1..4));