def __init__(self, elementNode): "Set defaults." self.bevelOverRadius = evaluate.getEvaluatedFloat(0.2, elementNode, "bevelOverRadius") self.boltRadiusOverRadius = evaluate.getEvaluatedFloat(0.0, elementNode, "boltRadiusOverRadius") self.columns = evaluate.getEvaluatedInt(2, elementNode, "columns") self.elementNode = elementNode self.heightOverRadius = evaluate.getEvaluatedFloat(2.0, elementNode, "heightOverRadius") self.interiorOverhangRadians = setting.getInteriorOverhangRadians(elementNode) self.overhangSpan = setting.getOverhangSpan(elementNode) self.pegClearanceOverRadius = evaluate.getEvaluatedFloat(0.0, elementNode, "pegClearanceOverRadius") self.pegRadians = math.radians(evaluate.getEvaluatedFloat(2.0, elementNode, "pegAngle")) self.pegHeightOverHeight = evaluate.getEvaluatedFloat(0.4, elementNode, "pegHeightOverHeight") self.pegRadiusOverRadius = evaluate.getEvaluatedFloat(0.7, elementNode, "pegRadiusOverRadius") self.radius = lineation.getFloatByPrefixBeginEnd(elementNode, "radius", "width", 5.0) self.rows = evaluate.getEvaluatedInt(1, elementNode, "rows") self.topBevelOverRadius = evaluate.getEvaluatedFloat(0.2, elementNode, "topBevelOverRadius") # Set derived values. self.bevel = evaluate.getEvaluatedFloat(self.bevelOverRadius * self.radius, elementNode, "bevel") self.boltRadius = evaluate.getEvaluatedFloat(self.boltRadiusOverRadius * self.radius, elementNode, "boltRadius") self.boltSides = evaluate.getSidesMinimumThreeBasedOnPrecision(elementNode, self.boltRadius) self.bottomLeftCenter = complex(-float(self.columns - 1), -float(self.rows - 1)) * self.radius self.height = evaluate.getEvaluatedFloat(self.heightOverRadius * self.radius, elementNode, "height") self.hollowPegSockets = [] centerY = self.bottomLeftCenter.imag diameter = self.radius + self.radius self.pegExistence = CellExistence( self.columns, self.rows, evaluate.getEvaluatedValue(None, elementNode, "pegs") ) self.socketExistence = CellExistence( self.columns, self.rows, evaluate.getEvaluatedValue(None, elementNode, "sockets") ) for rowIndex in xrange(self.rows): centerX = self.bottomLeftCenter.real for columnIndex in xrange(self.columns): hollowPegSocket = HollowPegSocket(complex(centerX, centerY)) hollowPegSocket.shouldAddPeg = self.pegExistence.getIsInExistence(columnIndex, rowIndex) hollowPegSocket.shouldAddSocket = self.socketExistence.getIsInExistence(columnIndex, rowIndex) self.hollowPegSockets.append(hollowPegSocket) centerX += diameter centerY += diameter self.pegClearance = evaluate.getEvaluatedFloat( self.pegClearanceOverRadius * self.radius, elementNode, "pegClearance" ) halfPegClearance = 0.5 * self.pegClearance self.pegHeight = evaluate.getEvaluatedFloat(self.pegHeightOverHeight * self.height, elementNode, "pegHeight") self.pegRadius = evaluate.getEvaluatedFloat(self.pegRadiusOverRadius * self.radius, elementNode, "pegRadius") sides = 24 * max(1, math.floor(evaluate.getSidesBasedOnPrecision(elementNode, self.pegRadius) / 24)) self.socketRadius = self.pegRadius + halfPegClearance self.pegSides = evaluate.getEvaluatedInt(sides, elementNode, "pegSides") self.pegRadius -= halfPegClearance self.pegRadiusArealized = evaluate.getRadiusArealizedBasedOnAreaRadius( elementNode, self.pegRadius, self.pegSides ) self.socketSides = evaluate.getEvaluatedInt(sides, elementNode, "socketSides") self.socketRadiusArealized = evaluate.getRadiusArealizedBasedOnAreaRadius( elementNode, self.socketRadius, self.socketSides ) self.topBevel = evaluate.getEvaluatedFloat(self.topBevelOverRadius * self.radius, elementNode, "topBevel") self.topBevelPositions = evaluate.getEvaluatedString("nwse", elementNode, "topBevelPositions").lower() self.topRight = complex(float(self.columns), float(self.rows)) * self.radius
def getTeardropPath(inclination, radius, xmlElement): "Get vector3 teardrop path." teardropSides = evaluate.getSidesMinimumThreeBasedOnPrecision(radius, xmlElement) sideAngle = 2.0 * math.pi / float(teardropSides) overhangAngle = evaluate.getOverhangSupportAngle(xmlElement) overhangPlaneAngle = euclidean.getWiddershinsUnitPolar(overhangAngle) overhangAngle = math.atan2(overhangPlaneAngle.imag, overhangPlaneAngle.real * math.cos(inclination)) tanOverhangAngle = math.tan(overhangAngle) beginAngle = overhangAngle beginMinusEndAngle = math.pi + overhangAngle + overhangAngle withinSides = int(math.ceil(beginMinusEndAngle / sideAngle)) withinSideAngle = -beginMinusEndAngle / float(withinSides) teardropPath = [] for side in xrange(withinSides + 1): unitPolar = euclidean.getWiddershinsUnitPolar(beginAngle) teardropPath.append(unitPolar * radius) beginAngle += withinSideAngle firstPoint = teardropPath[0] overhangSpan = evaluate.getOverhangSpan(xmlElement) if overhangSpan <= 0.0: teardropPath.append(complex(0.0, firstPoint.imag + firstPoint.real / tanOverhangAngle)) else: deltaX = (radius - firstPoint.imag) * tanOverhangAngle overhangPoint = complex(firstPoint.real - deltaX, radius) remainingDeltaX = max(0.0, overhangPoint.real - 0.5 * overhangSpan ) overhangPoint += complex(-remainingDeltaX, remainingDeltaX / tanOverhangAngle) teardropPath.append(complex(-overhangPoint.real, overhangPoint.imag)) teardropPath.append(overhangPoint) return euclidean.getVector3Path(teardropPath)
def __init__(self, elementNode): 'Set defaults.' self.bevelOverRadius = evaluate.getEvaluatedFloat( 0.25, elementNode, 'bevelOverRadius') self.clearanceOverRadius = evaluate.getEvaluatedFloat( 0.0, elementNode, 'clearanceOverRadius') self.elementNode = elementNode self.endZ = evaluate.getEvaluatedFloat(10.0, elementNode, 'endZ') self.start = evaluate.getVector3ByPrefix(Vector3(), elementNode, 'start') self.radius = lineation.getFloatByPrefixBeginEnd( elementNode, 'radius', 'diameter', 2.0) self.sides = evaluate.getSidesMinimumThreeBasedOnPrecision( elementNode, max(self.radius.real, self.radius.imag)) self.radiusArealized = evaluate.getRadiusArealizedBasedOnAreaRadius( elementNode, self.radius, self.sides) self.topOverBottom = evaluate.getEvaluatedFloat( 0.8, elementNode, 'topOverBottom') setTopOverBottomByRadius(self, self.endZ, self.radiusArealized, self.start.z) # Set derived variables. self.bevel = evaluate.getEvaluatedFloat( self.bevelOverRadius * self.radiusArealized, elementNode, 'bevel') self.clearance = evaluate.getEvaluatedFloat( self.clearanceOverRadius * self.radiusArealized, elementNode, 'clearance')
def getNumberOfBezierPoints(begin, end, xmlElement): "Get the numberOfBezierPoints." numberOfBezierPoints = int( math.ceil(0.5 * evaluate.getSidesMinimumThreeBasedOnPrecision( abs(end - begin), xmlElement))) return evaluate.getEvaluatedIntDefault(numberOfBezierPoints, 'sides', xmlElement)
def createShape(self): 'Create the shape.' sides = evaluate.getSidesMinimumThreeBasedOnPrecision( max(self.inradius.x, self.inradius.y), self.xmlElement) addCylinderByInradius(self.faces, self.inradius, sides, self.topOverBottom, self.vertexes, self.xmlElement)
def getTeardropPath(inclination, radius, xmlElement): "Get vector3 teardrop path." teardropSides = evaluate.getSidesMinimumThreeBasedOnPrecision( radius, xmlElement) sideAngle = 2.0 * math.pi / float(teardropSides) overhangAngle = evaluate.getOverhangSupportAngle(xmlElement) overhangPlaneAngle = euclidean.getWiddershinsUnitPolar(overhangAngle) overhangAngle = math.atan2(overhangPlaneAngle.imag, overhangPlaneAngle.real * math.cos(inclination)) tanOverhangAngle = math.tan(overhangAngle) beginAngle = overhangAngle beginMinusEndAngle = math.pi + overhangAngle + overhangAngle withinSides = int(math.ceil(beginMinusEndAngle / sideAngle)) withinSideAngle = -beginMinusEndAngle / float(withinSides) teardropPath = [] for side in xrange(withinSides + 1): unitPolar = euclidean.getWiddershinsUnitPolar(beginAngle) teardropPath.append(unitPolar * radius) beginAngle += withinSideAngle firstPoint = teardropPath[0] overhangSpan = evaluate.getOverhangSpan(xmlElement) if overhangSpan <= 0.0: teardropPath.append( complex(0.0, firstPoint.imag + firstPoint.real / tanOverhangAngle)) else: deltaX = (radius - firstPoint.imag) * tanOverhangAngle overhangPoint = complex(firstPoint.real - deltaX, radius) remainingDeltaX = max(0.0, overhangPoint.real - 0.5 * overhangSpan) overhangPoint += complex(-remainingDeltaX, remainingDeltaX / tanOverhangAngle) teardropPath.append(complex(-overhangPoint.real, overhangPoint.imag)) teardropPath.append(overhangPoint) return euclidean.getVector3Path(teardropPath)
def createShape(self): 'Create the shape.' sides = evaluate.getSidesMinimumThreeBasedOnPrecision(self.elementNode, max(self.inradius.x, self.inradius.y)) if self.elementNode.getCascadeBoolean(False, 'radiusAreal'): radiusArealizedMultiplier = euclidean.getRadiusArealizedMultiplier(sides) self.inradius.x *= radiusArealizedMultiplier self.inradius.y *= radiusArealizedMultiplier addCylinder(self.faces, self.inradius, sides, self.topOverBottom, self.vertexes)
def addNegativePeg(derivation, negatives, x, y): 'Add negative cylinder at x and y.' negativePegRadius = derivation.pegRadiusArealized + derivation.halfPegClearance inradius = complex(negativePegRadius, negativePegRadius) copyShallow = derivation.elementNode.getCopyShallow() start = Vector3(x, y, derivation.height) sides = evaluate.getSidesMinimumThreeBasedOnPrecision(copyShallow, negativePegRadius) cylinder.addCylinderOutputByEndStart(0.0, inradius, negatives, sides, start, derivation.topOverBottom)
def addNegativePeg(derivation, negatives, x, y): 'Add negative cylinder at x and y.' negativePegRadius = derivation.pegRadius + derivation.halfPegClearance inradius = complex(negativePegRadius, negativePegRadius) copyShallow = derivation.xmlElement.getCopyShallow() start = Vector3(x, y, derivation.height) sides = evaluate.getSidesMinimumThreeBasedOnPrecision(negativePegRadius, copyShallow ) cylinderOutput = cylinder.getGeometryOutputByEndStart(0.0, inradius, sides, start, derivation.topOverBottom, copyShallow) negatives.append(cylinderOutput)
def addNegativePeg(derivation, negatives, x, y): 'Add negative cylinder at x and y.' negativePegRadius = derivation.pegRadius + derivation.halfPegClearance inradius = complex(negativePegRadius, negativePegRadius) copyShallow = derivation.xmlElement.getCopyShallow() start = Vector3(x, y, derivation.height) sides = evaluate.getSidesMinimumThreeBasedOnPrecision( negativePegRadius, copyShallow) cylinderOutput = cylinder.getGeometryOutputByEndStart( 0.0, inradius, sides, start, derivation.topOverBottom, copyShallow) negatives.append(cylinderOutput)
def addCollarShaftSetDerivation(collarDerivation, collarThickness, derivation, negatives, positives, xmlElement): 'Add collar and shaft.' collarSides = evaluate.getSidesMinimumThreeBasedOnPrecision(derivation.shaftRimRadius, xmlElement) collarProfile = euclidean.getComplexPolygon(complex(), derivation.shaftRimRadius, collarSides) vector3CollarProfile = euclidean.getVector3Path(collarProfile) extrude.addNegativesPositives(collarDerivation, negatives, [vector3CollarProfile], positives) addShaft(derivation, negatives, positives) drillZ = derivation.pinionThickness + 0.5 * collarThickness drillEnd = Vector3(0.0, derivation.shaftRimRadius, drillZ) drillStart = Vector3(0.0, 0.0, drillZ) teardrop.addNegativesByRadius(drillEnd, negatives, derivation.keywayRadius, drillStart, xmlElement)
def __init__(self, elementNode): 'Set defaults.' self.bevelOverRadius = evaluate.getEvaluatedFloat(0.25, elementNode, 'bevelOverRadius') self.clearanceOverRadius = evaluate.getEvaluatedFloat(0.0, elementNode, 'clearanceOverRadius') self.elementNode = elementNode self.endZ = evaluate.getEvaluatedFloat(10.0, elementNode, 'endZ') self.start = evaluate.getVector3ByPrefix(Vector3(), elementNode, 'start') self.radius = lineation.getFloatByPrefixBeginEnd(elementNode, 'radius', 'diameter', 2.0) self.sides = evaluate.getSidesMinimumThreeBasedOnPrecision(elementNode, max(self.radius.real, self.radius.imag)) self.radiusArealized = evaluate.getRadiusArealizedBasedOnAreaRadius(elementNode, self.radius, self.sides) self.topOverBottom = evaluate.getEvaluatedFloat(0.8, elementNode, 'topOverBottom') setTopOverBottomByRadius(self, self.endZ, self.radiusArealized, self.start.z) # Set derived variables. self.bevel = evaluate.getEvaluatedFloat(self.bevelOverRadius * self.radiusArealized, elementNode, 'bevel') self.clearance = evaluate.getEvaluatedFloat(self.clearanceOverRadius * self.radiusArealized, elementNode, 'clearance')
def getManipulatedPaths(close, loop, prefix, sideLength, xmlElement): "Get round loop." if len(loop) < 3: return [loop] radius = lineation.getRadiusByPrefix(prefix, sideLength, xmlElement) if radius == 0.0: return loop roundLoop = [] sidesPerRadian = 0.5 / math.pi * evaluate.getSidesMinimumThreeBasedOnPrecision(sideLength, xmlElement) for pointIndex in xrange(len(loop)): begin = loop[(pointIndex + len(loop) - 1) % len(loop)] center = loop[pointIndex] end = loop[(pointIndex + 1) % len(loop)] roundLoop += getRoundPath(begin, center, close, end, radius, sidesPerRadian) return [euclidean.getLoopWithoutCloseSequentialPoints(close, roundLoop)]
def getManipulatedPaths(close, elementNode, loop, prefix, sideLength): "Get round loop." if len(loop) < 3: return [loop] derivation = RoundDerivation(elementNode, prefix, sideLength) if derivation.radius == 0.0: return loop roundLoop = [] sidesPerRadian = 0.5 / math.pi * evaluate.getSidesMinimumThreeBasedOnPrecision(elementNode, sideLength) for pointIndex in xrange(len(loop)): begin = loop[(pointIndex + len(loop) - 1) % len(loop)] center = loop[pointIndex] end = loop[(pointIndex + 1) % len(loop)] roundLoop += getRoundPath(begin, center, close, end, derivation.radius, sidesPerRadian) return [euclidean.getLoopWithoutCloseSequentialPoints(close, roundLoop)]
def __init__(self, xmlElement): 'Set defaults.' self.bevelOverRadius = evaluate.getEvaluatedFloat(0.2, 'bevelOverRadius', xmlElement) self.boltRadiusOverRadius = evaluate.getEvaluatedFloat(0.0, 'boltRadiusOverRadius', xmlElement) self.columns = evaluate.getEvaluatedInt(2, 'columns', xmlElement) self.heightOverRadius = evaluate.getEvaluatedFloat(2.0, 'heightOverRadius', xmlElement) self.interiorOverhangRadians = setting.getInteriorOverhangRadians(xmlElement) self.overhangSpan = setting.getOverhangSpan(xmlElement) self.pegClearanceOverRadius = evaluate.getEvaluatedFloat(0.0, 'pegClearanceOverRadius', xmlElement) self.pegRadians = math.radians(evaluate.getEvaluatedFloat(2.0, 'pegAngle', xmlElement)) self.pegHeightOverHeight = evaluate.getEvaluatedFloat(0.4, 'pegHeightOverHeight', xmlElement) self.pegRadiusOverRadius = evaluate.getEvaluatedFloat(0.7, 'pegRadiusOverRadius', xmlElement) self.radius = lineation.getFloatByPrefixBeginEnd('radius', 'width', 5.0, xmlElement) self.rows = evaluate.getEvaluatedInt(1, 'rows', xmlElement) self.topBevelOverRadius = evaluate.getEvaluatedFloat(0.2, 'topBevelOverRadius', xmlElement) self.xmlElement = xmlElement # Set derived values. self.bevel = evaluate.getEvaluatedFloat(self.bevelOverRadius * self.radius, 'bevel', xmlElement) self.boltRadius = evaluate.getEvaluatedFloat(self.boltRadiusOverRadius * self.radius, 'boltRadius', xmlElement) self.boltSides = evaluate.getSidesMinimumThreeBasedOnPrecision(self.boltRadius, xmlElement) self.bottomLeftCenter = complex(-float(self.columns - 1), -float(self.rows - 1)) * self.radius self.height = evaluate.getEvaluatedFloat(self.heightOverRadius * self.radius, 'height', xmlElement) self.hollowPegSockets = [] centerY = self.bottomLeftCenter.imag diameter = self.radius + self.radius self.pegExistence = CellExistence(self.columns, self.rows, evaluate.getEvaluatedValue(None, 'pegs', xmlElement)) self.socketExistence = CellExistence(self.columns, self.rows, evaluate.getEvaluatedValue(None, 'sockets', xmlElement)) for rowIndex in xrange(self.rows): centerX = self.bottomLeftCenter.real for columnIndex in xrange(self.columns): hollowPegSocket = HollowPegSocket(complex(centerX, centerY)) hollowPegSocket.shouldAddPeg = self.pegExistence.getIsInExistence(columnIndex, rowIndex) hollowPegSocket.shouldAddSocket = self.socketExistence.getIsInExistence(columnIndex, rowIndex) self.hollowPegSockets.append(hollowPegSocket) centerX += diameter centerY += diameter self.pegClearance = evaluate.getEvaluatedFloat(self.pegClearanceOverRadius * self.radius, 'pegClearance', xmlElement) halfPegClearance = 0.5 * self.pegClearance self.pegHeight = evaluate.getEvaluatedFloat(self.pegHeightOverHeight * self.height, 'pegHeight', xmlElement) self.pegRadius = evaluate.getEvaluatedFloat(self.pegRadiusOverRadius * self.radius, 'pegRadius', xmlElement) sides = 24 * max(1, math.floor(evaluate.getSidesBasedOnPrecision(self.pegRadius, xmlElement) / 24)) self.socketRadius = self.pegRadius + halfPegClearance self.pegSides = evaluate.getEvaluatedInt(sides, 'pegSides', xmlElement) self.socketSides = evaluate.getEvaluatedInt(sides, 'socketSides', xmlElement) self.pegRadius -= halfPegClearance self.topBevel = evaluate.getEvaluatedFloat(self.topBevelOverRadius * self.radius, 'topBevel', xmlElement) self.topBevelPositions = evaluate.getEvaluatedString('nwse', 'topBevelPositions', xmlElement).lower() self.topRight = complex(float(self.columns), float(self.rows)) * self.radius
def __init__(self, xmlElement): """Set defaults.""" self.bevelOverRadius = evaluate.getEvaluatedFloat(0.2, 'bevelOverRadius', xmlElement) self.boltRadiusOverRadius = evaluate.getEvaluatedFloat(0.0, 'boltRadiusOverRadius', xmlElement) self.columns = evaluate.getEvaluatedInt(2, 'columns', xmlElement) self.heightOverRadius = evaluate.getEvaluatedFloat(2.0, 'heightOverRadius', xmlElement) self.interiorOverhangRadians = setting.getInteriorOverhangRadians(xmlElement) self.overhangSpan = setting.getOverhangSpan(xmlElement) self.pegClearanceOverRadius = evaluate.getEvaluatedFloat(0.0, 'pegClearanceOverRadius', xmlElement) self.pegRadians = math.radians(evaluate.getEvaluatedFloat(2.0, 'pegAngle', xmlElement)) self.pegHeightOverHeight = evaluate.getEvaluatedFloat(0.4, 'pegHeightOverHeight', xmlElement) self.pegRadiusOverRadius = evaluate.getEvaluatedFloat(0.7, 'pegRadiusOverRadius', xmlElement) self.radius = lineation.getFloatByPrefixBeginEnd('radius', 'width', 5.0, xmlElement) self.rows = evaluate.getEvaluatedInt(1, 'rows', xmlElement) self.topBevelOverRadius = evaluate.getEvaluatedFloat(0.2, 'topBevelOverRadius', xmlElement) self.xmlElement = xmlElement # Set derived values. self.bevel = evaluate.getEvaluatedFloat(self.bevelOverRadius * self.radius, 'bevel', xmlElement) self.boltRadius = evaluate.getEvaluatedFloat(self.boltRadiusOverRadius * self.radius, 'boltRadius', xmlElement) self.boltSides = evaluate.getSidesMinimumThreeBasedOnPrecision(self.boltRadius, xmlElement) self.bottomLeftCenter = complex(-float(self.columns - 1), -float(self.rows - 1)) * self.radius self.height = evaluate.getEvaluatedFloat(self.heightOverRadius * self.radius, 'height', xmlElement) self.hollowPegSockets = [] centerY = self.bottomLeftCenter.imag diameter = self.radius + self.radius self.pegExistence = CellExistence(self.columns, self.rows, evaluate.getEvaluatedValue(None, 'pegs', xmlElement)) self.socketExistence = CellExistence(self.columns, self.rows, evaluate.getEvaluatedValue(None, 'sockets', xmlElement)) for rowIndex in xrange(self.rows): centerX = self.bottomLeftCenter.real for columnIndex in xrange(self.columns): hollowPegSocket = HollowPegSocket(complex(centerX, centerY)) hollowPegSocket.shouldAddPeg = self.pegExistence.getIsInExistence(columnIndex, rowIndex) hollowPegSocket.shouldAddSocket = self.socketExistence.getIsInExistence(columnIndex, rowIndex) self.hollowPegSockets.append(hollowPegSocket) centerX += diameter centerY += diameter self.pegClearance = evaluate.getEvaluatedFloat(self.pegClearanceOverRadius * self.radius, 'pegClearance', xmlElement) halfPegClearance = 0.5 * self.pegClearance self.pegHeight = evaluate.getEvaluatedFloat(self.pegHeightOverHeight * self.height, 'pegHeight', xmlElement) self.pegRadius = evaluate.getEvaluatedFloat(self.pegRadiusOverRadius * self.radius, 'pegRadius', xmlElement) sides = 24 * max(1, math.floor(evaluate.getSidesBasedOnPrecision(self.pegRadius, xmlElement) / 24)) self.socketRadius = self.pegRadius + halfPegClearance self.pegSides = evaluate.getEvaluatedInt(sides, 'pegSides', xmlElement) self.socketSides = evaluate.getEvaluatedInt(sides, 'socketSides', xmlElement) self.pegRadius -= halfPegClearance self.topBevel = evaluate.getEvaluatedFloat(self.topBevelOverRadius * self.radius, 'topBevel', xmlElement) self.topBevelPositions = evaluate.getEvaluatedString('nwse', 'topBevelPositions', xmlElement).lower() self.topRight = complex(float(self.columns), float(self.rows)) * self.radius
def addPeg(bevel, endZ, outputs, radius, start, topOverBottom, xmlElement): 'Add beveled cylinder to outputs given bevel, endZ, radius and start.' height = abs(start.z - endZ) bevelStartRatio = max(1.0 - bevel / height, 0.5) oneMinusBevelStartRatio = 1.0 - bevelStartRatio trunkEndZ = bevelStartRatio * endZ + oneMinusBevelStartRatio * start.z trunkTopOverBottom = bevelStartRatio * topOverBottom + oneMinusBevelStartRatio sides = evaluate.getSidesMinimumThreeBasedOnPrecision(max(radius.real, radius.imag), xmlElement ) outputs.append(cylinder.getGeometryOutputByEndStart(trunkEndZ, radius, sides, start, trunkTopOverBottom, xmlElement)) capRadius = radius * trunkTopOverBottom capStart = bevelStartRatio * Vector3(start.x, start.y, endZ) + oneMinusBevelStartRatio * start radiusMaximum = max(radius.real, radius.imag) endRadiusMaximum = radiusMaximum * topOverBottom - bevel trunkRadiusMaximum = radiusMaximum * trunkTopOverBottom capTopOverBottom = endRadiusMaximum / trunkRadiusMaximum outputs.append(cylinder.getGeometryOutputByEndStart(endZ, capRadius, sides, capStart, capTopOverBottom, xmlElement))
def addSphere(faces, radius, vertexes, xmlElement): 'Add sphere by radius.' bottom = -radius.z sides = evaluate.getSidesMinimumThreeBasedOnPrecision(max(radius.x, radius.y, radius.z), xmlElement ) sphereSlices = max(sides / 2, 2) equator = euclidean.getComplexPolygonByComplexRadius(complex(radius.x, radius.y), sides) polygons = [triangle_mesh.getAddIndexedLoop([complex()], vertexes, bottom)] zIncrement = (radius.z + radius.z) / float(sphereSlices) z = bottom for sphereSlice in xrange(1, sphereSlices): z += zIncrement zPortion = abs(z) / radius.z multipliedPath = euclidean.getComplexPathByMultiplier(math.sqrt(1.0 - zPortion * zPortion), equator) polygons.append(triangle_mesh.getAddIndexedLoop(multipliedPath, vertexes, z)) polygons.append(triangle_mesh.getAddIndexedLoop([complex()], vertexes, radius.z)) triangle_mesh.addPillarByLoops(faces, polygons)
def createShape(self): "Create the shape." polygonBottom = [] polygonTop = [] sides = evaluate.getSidesMinimumThreeBasedOnPrecision(max(self.inradius.x, self.inradius.y), self.xmlElement ) sideAngle = 2.0 * math.pi / sides for side in xrange(int(sides)): angle = float(side) * sideAngle unitComplex = euclidean.getWiddershinsUnitPolar(angle) pointBottom = complex(unitComplex.real * self.inradius.x, unitComplex.imag * self.inradius.y) polygonBottom.append(pointBottom) if self.topOverBottom > 0.0: polygonTop.append(pointBottom * self.topOverBottom) if self.topOverBottom <= 0.0: polygonTop.append(complex()) bottomTopPolygon = [ trianglemesh.getAddIndexedLoop(polygonBottom, self.vertexes, - self.inradius.z), trianglemesh.getAddIndexedLoop(polygonTop, self.vertexes, self.inradius.z)] trianglemesh.addPillarFromConvexLoops(self.faces, bottomTopPolygon)
def addCylinderByInradius(faces, inradius, topOverBottom, vertexes, xmlElement): 'Add cylinder by radius.' polygonBottom = [] polygonTop = [] sides = evaluate.getSidesMinimumThreeBasedOnPrecision(max(inradius.x, inradius.y), xmlElement ) sideAngle = 2.0 * math.pi / sides for side in xrange(int(sides)): angle = float(side) * sideAngle unitComplex = euclidean.getWiddershinsUnitPolar(angle) pointBottom = complex(unitComplex.real * inradius.x, unitComplex.imag * inradius.y) polygonBottom.append(pointBottom) if topOverBottom > 0.0: polygonTop.append(pointBottom * topOverBottom) if topOverBottom <= 0.0: polygonTop.append(complex()) bottomTopPolygon = [ trianglemesh.getAddIndexedLoop(polygonBottom, vertexes, -inradius.z), trianglemesh.getAddIndexedLoop(polygonTop, vertexes, inradius.z)] trianglemesh.addPillarByLoops(faces, bottomTopPolygon)
def setAssemblyCage(self): 'Set two piece assembly parameters.' self.grooveDepthOverRadius = evaluate.getEvaluatedFloat(0.15, self.elementNode, 'grooveDepthOverRadius') self.grooveDepth = self.grooveDepthOverRadius * self.radius self.grooveDepth = evaluate.getEvaluatedFloat(self.grooveDepth, self.elementNode, 'grooveDepth') self.grooveWidthOverRadius = evaluate.getEvaluatedFloat(0.6, self.elementNode, 'grooveWidthOverRadius') self.grooveWidth = self.grooveWidthOverRadius * self.radius self.grooveWidth = evaluate.getEvaluatedFloat(self.grooveWidth, self.elementNode, 'grooveWidth') self.pegClearanceOverRadius = evaluate.getEvaluatedFloat(0.0, self.elementNode, 'pegClearanceOverRadius') self.pegClearance = self.pegClearanceOverRadius * self.radius self.pegClearance = evaluate.getEvaluatedFloat(self.pegClearance, self.elementNode, 'pegClearance') self.halfPegClearance = 0.5 * self.pegClearance self.pegRadiusOverRadius = evaluate.getEvaluatedFloat(0.5, self.elementNode, 'pegRadiusOverRadius') self.pegRadius = self.pegRadiusOverRadius * self.radius self.pegRadius = evaluate.getEvaluatedFloat(self.pegRadius, self.elementNode, 'pegRadius') self.sides = evaluate.getSidesMinimumThreeBasedOnPrecision(self.elementNode, self.pegRadius) self.pegRadiusArealized = evaluate.getRadiusArealizedBasedOnAreaRadius(self.elementNode, self.pegRadius, self.sides) self.pegBevelOverPegRadius = evaluate.getEvaluatedFloat(0.25, self.elementNode, 'pegBevelOverPegRadius') self.pegBevel = self.pegBevelOverPegRadius * self.pegRadiusArealized self.pegBevel = evaluate.getEvaluatedFloat(self.pegBevel, self.elementNode, 'pegBevel') self.pegMaximumRadius = self.pegRadiusArealized + abs(self.halfPegClearance) self.separationOverRadius = evaluate.getEvaluatedFloat(0.5, self.elementNode, 'separationOverRadius') self.separation = self.separationOverRadius * self.radius self.separation = evaluate.getEvaluatedFloat(self.separation, self.elementNode, 'separation') self.topOverBottom = evaluate.getEvaluatedFloat(0.8, self.elementNode, 'topOverBottom') peg.setTopOverBottomByRadius(self, 0.0, self.pegRadiusArealized, self.height) self.quarterHeight = 0.5 * self.demiheight self.pegY = 0.5 * self.wallThickness + self.pegMaximumRadius cagePegRadius = self.cageRadius + self.pegMaximumRadius halfStepX = 0.5 * self.stepX pegHypotenuse = math.sqrt(self.pegY * self.pegY + halfStepX * halfStepX) if cagePegRadius > pegHypotenuse: self.pegY = math.sqrt(cagePegRadius * cagePegRadius - halfStepX * halfStepX) self.demiwidth = max(self.pegY + self.pegMaximumRadius + self.wallThickness, self.demiwidth) self.innerDemiwidth = self.demiwidth self.demiwidth += self.grooveDepth self.halfSeparationWidth = self.demiwidth + 0.5 * self.separation if self.pegRadiusArealized <= 0.0: self.pegCenterXs = [] else: self.pegCenterXs = getPegCenterXs(self.numberOfSteps, self.bearingCenterX + halfStepX, self.stepX)
def addPegOutput(bevel, endZ, outputs, radius, start, topOverBottom, xmlElement): 'Add beveled cylinder to outputs given bevel, endZ, radius and start.' height = abs(start.z - endZ) bevelStartRatio = max(1.0 - bevel / height, 0.5) oneMinusBevelStartRatio = 1.0 - bevelStartRatio trunkEndZ = bevelStartRatio * endZ + oneMinusBevelStartRatio * start.z trunkTopOverBottom = bevelStartRatio * topOverBottom + oneMinusBevelStartRatio sides = evaluate.getSidesMinimumThreeBasedOnPrecision( max(radius.real, radius.imag), xmlElement) cylinder.addCylinderOutputByEndStart(trunkEndZ, radius, outputs, sides, start, trunkTopOverBottom) capRadius = radius * trunkTopOverBottom capStart = bevelStartRatio * Vector3( start.x, start.y, endZ) + oneMinusBevelStartRatio * start radiusMaximum = max(radius.real, radius.imag) endRadiusMaximum = radiusMaximum * topOverBottom - bevel trunkRadiusMaximum = radiusMaximum * trunkTopOverBottom capTopOverBottom = endRadiusMaximum / trunkRadiusMaximum cylinder.addCylinderOutputByEndStart(endZ, capRadius, outputs, sides, capStart, capTopOverBottom)
def addCylinderByInradius(faces, inradius, topOverBottom, vertexes, xmlElement): 'Add cylinder by radius.' polygonBottom = [] polygonTop = [] sides = evaluate.getSidesMinimumThreeBasedOnPrecision( max(inradius.x, inradius.y), xmlElement) sideAngle = 2.0 * math.pi / sides for side in xrange(int(sides)): angle = float(side) * sideAngle unitComplex = euclidean.getWiddershinsUnitPolar(angle) pointBottom = complex(unitComplex.real * inradius.x, unitComplex.imag * inradius.y) polygonBottom.append(pointBottom) if topOverBottom > 0.0: polygonTop.append(pointBottom * topOverBottom) if topOverBottom <= 0.0: polygonTop.append(complex()) bottomTopPolygon = [ trianglemesh.getAddIndexedLoop(polygonBottom, vertexes, -inradius.z), trianglemesh.getAddIndexedLoop(polygonTop, vertexes, inradius.z) ] trianglemesh.addPillarByLoops(faces, bottomTopPolygon)
def getNumberOfBezierPoints(begin, elementNode, end): 'Get the numberOfBezierPoints.' numberOfBezierPoints = int(math.ceil(0.5 * evaluate.getSidesMinimumThreeBasedOnPrecision(elementNode, abs(end - begin)))) return evaluate.getEvaluatedInt(numberOfBezierPoints, elementNode, 'sides')
def createShape(self): 'Create the shape.' sides = evaluate.getSidesMinimumThreeBasedOnPrecision(max(self.inradius.x, self.inradius.y), self.xmlElement ) addCylinderByInradius(self.faces, self.inradius, sides, self.topOverBottom, self.vertexes, self.xmlElement)
def getNumberOfBezierPoints(begin, end, xmlElement): "Get the numberOfBezierPoints." numberOfBezierPoints = int(math.ceil(0.5 * evaluate.getSidesMinimumThreeBasedOnPrecision(abs(end - begin), xmlElement))) return evaluate.getEvaluatedIntDefault(numberOfBezierPoints, 'sides', xmlElement)
def getNumberOfBezierPoints(begin, elementNode, end): 'Get the numberOfBezierPoints.' numberOfBezierPoints = int( math.ceil(0.5 * evaluate.getSidesMinimumThreeBasedOnPrecision( elementNode, abs(end - begin)))) return evaluate.getEvaluatedInt(numberOfBezierPoints, elementNode, 'sides')