Hi Brian,
Here's a function for checking if a pair of curves is G1.
- Peer
code:
// returns true if curve1 is tangent to curve2
function getCurvePairIsG1(curve1, curve2) {
var curve1startPt = curve1.getStartPt();
var curve1endPt = curve1.getEndPt();
var curve1startTan = curve1.evaluateTangent(curve1.domainMin);
var curve1endTan = curve1.evaluateTangent(curve1.domainMax);
var curve2startPt = curve2.getStartPt();
var curve2endPt = curve2.getEndPt();
var curve2startTan = curve2.evaluateTangent(curve2.domainMin);
var curve2endTan = curve2.evaluateTangent(curve2.domainMax);
// flip one of the tangent vectors in the pair being compared for end-end and start-start cases
var curve1startTanNeg = moi.vectorMath.createPoint(curve1startTan.x, curve1startTan.y, curve1startTan.z);
curve1startTanNeg.scale(-1.0);
var curve1endTanNeg = moi.vectorMath.createPoint(curve1endTan.x, curve1endTan.y, curve1endTan.z);
curve1endTanNeg.scale(-1.0);
var tol = moi.geometryDatabase.tolerance;
// curve1 start curve2 end
if (
moi.vectorMath.distance(curve1startPt, curve2endPt) < tol &&
moi.vectorMath.distance(curve1startTan, curve2endTan) < tol
) {
return true;
}
// curve1 end curve2 start
else if (
moi.vectorMath.distance(curve1endPt, curve2startPt) < tol &&
moi.vectorMath.distance(curve1endTan, curve2startTan) < tol
) {
return true;
}
// curve1 start curve2 start
else if (
moi.vectorMath.distance(curve1startPt, curve2startPt) < tol &&
moi.vectorMath.distance(curve1startTanNeg, curve2startTan) < tol
) {
return true;
}
// curve2 end curve2 end
else if (
moi.vectorMath.distance(curve1endPt, curve2endPt) < tol &&
moi.vectorMath.distance(curve1endTanNeg, curve2endTan) < tol
) {
return true;
}
else {
return false;
}
}
|