# pboyer/verb

Compute gaussian, mean, principal curvatures on >degree 2 surface inc…

`…luding basic unit test`
1 parent 7d99dca commit 02e43ac61e1fee29cb5a0175f2e26bc83abc2da6 committed Feb 1, 2014
Showing with 1,806 additions and 579 deletions.
1. +183 −71 build/verb.js
2. +3 −3 build/verb.min.js
3. +183 −71 build/verbEval.js
4. +3 −2 build/verbEval.min.js
5. +1,100 −319 docs/verb.html
6. +90 −0 src/eval/eval.js
7. +11 −11 src/eval/geom.js
8. +81 −59 src/eval/tesselate.js
9. +152 −43 test/test.js
254 build/verb.js
6 build/verb.min.js
254 build/verbEval.js
5 build/verbEval.min.js
1,419 docs/verb.html
1,100 additions, 319 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
90 src/eval/eval.js
 @@ -1,4 +1,94 @@ +// +// ####surface_curvature( degree_u, knots_u, degree_v, knots_v, control_points, u, v, options ) +// +// Compute the gaussian curvature on a non-uniform, non-rational B spline surface +// +// **params** +// + *Number*, integer degree of surface in u direction +// + *Array*, array of nondecreasing knot values in u direction +// + *Number*, integer degree of surface in v direction +// + *Array*, array of nondecreasing knot values in v direction +// + *Array*, 3d array of control points, where rows are the u dir, and columns run alonsg the positive v direction, +// and where each control point is an array of length (dim) +// + *Number*, u parameter at which to evaluate the derivatives +// + *Number*, v parameter at which to evaluate the derivatives +// +// **returns** +// + *Array*, a point represented by an array of length (dim) +// + +verb.eval.nurbs.rational_surface_curvature = function( degree_u, knots_u, degree_v, knots_v, homo_control_points, u, v ) { + + // compute the first fundamental form + + // symmetric matrix where + // + // I = [ E F; F G ] + // + // where: + // + // E = Xu * Xu + // F = Xu * Xv + // G = Xv * Xv + + // second fundamental form (shape operator) + + // symmetric matrix where + // + // II = [ L M; M N ] + // + // where: + // + // L = Xuu * n + // M = Xuv * n + // N = Xvv * n + + // principal curvatures are the eigenvalues of the second fundamental form + + var derivs = verb.eval.nurbs.rational_surface_derivs( degree_u, + knots_u, + degree_v, + knots_v, + homo_control_points, + 2, u, v ); + + // structure of the derivatives + + // pos du vuu + // dv duv + // dvv + + + var du = derivs[0][1]; + var dv = derivs[1][0]; + var duu = derivs[0][2]; + var dvv = derivs[2][0]; + var duv = derivs[1][1]; + + var n = numeric.cross( du, dv ); + var L = numeric.dot( duu, n ); + var M = numeric.dot( duv, n ); + var N = numeric.dot( dvv, n ); + + var shapeOperator = [ [ L, M ], [ M, N ] ]; + + var eigs = numeric.eig( shapeOperator ); + + // contains: lambda - x + // E - x + + var k1 = eigs.lambda.x[0]; + var k2 = eigs.lambda.x[1]; + var mean = 0.5 * ( k1 + k2 ); + var gaussian = k1 * k2; + var p1 = numeric.add( numeric.mul( eigs.E.x[0][0], du ), numeric.mul( eigs.E.x[0][1], dv ) ); + var p2 = numeric.add( numeric.mul( eigs.E.x[1][0], du ), numeric.mul( eigs.E.x[1][1], dv ) ); + + return { point: derivs[0][0], normal: n, mean: mean, gaussian: gaussian, shapeOperator: shapeOperator, k1: k1, k2: k2, p1: p1, p2: p2, p1p : eigs.E.x[0], p2p: eigs.E.x[1] }; + +}; + // // ####curve_knot_insert( degree, knots, control_points, u, s, r )
22 src/eval/geom.js
 @@ -314,28 +314,28 @@ verb.eval.nurbs.get_cone_surface = function( axis, xaxis, base, height, radius ) verb.eval.nurbs.get_extruded_surface = function( axis, length, prof_knots, prof_degree, prof_control_points, prof_weights){ - var control_points = verb.eval.nurbs.zeros_2d( 2, prof_control_points.length ) - , weights = verb.eval.nurbs.zeros_2d( 2, prof_control_points.length ); + var control_points = verb.eval.nurbs.zeros_2d( 3, prof_control_points.length ) + , weights = verb.eval.nurbs.zeros_2d( 3, prof_control_points.length ); + + var translation = numeric.mul(axis, length); + var halfTranslation = numeric.mul(axis, 0.5 * length); // original control points for (var j = 0; j < prof_control_points.length; j++){ control_points[0][j] = prof_control_points[j]; - weights[0][j] = prof_weights[j]; - } - - // build translated control points - var translation = numeric.mul(axis, length); + control_points[1][j] = numeric.add( halfTranslation, prof_control_points[j] ); + control_points[2][j] = numeric.add( translation, prof_control_points[j] ); - for (var j = 0; j < prof_control_points.length; j++){ - control_points[1][j] = numeric.add( translation, prof_control_points[j] ); + weights[0][j] = prof_weights[j]; weights[1][j] = prof_weights[j]; + weights[2][j] = prof_weights[j]; } // return all parameters - return {"knots_u": [0,0,1,1], + return {"knots_u": [0,0,0,1,1,1], "knots_v": prof_knots, "control_points": control_points, - "degree_u": 1, + "degree_u": 2, "degree_v": prof_degree, "weights": weights }; }
140 src/eval/tesselate.js