def __init__( self, viewpointLatitude, viewpointLongitude ): "Initialize the view vectors." longitudeComplex = euclidean.getPolar( math.radians( 90.0 - viewpointLongitude ) ) self.viewpointLatitudeRatio = euclidean.getPolar( math.radians( viewpointLatitude ) ) self.viewpointVector3 = Vector3( self.viewpointLatitudeRatio.imag * longitudeComplex.real, self.viewpointLatitudeRatio.imag * longitudeComplex.imag, self.viewpointLatitudeRatio.real ) self.viewXVector3 = Vector3( - longitudeComplex.imag, longitudeComplex.real, 0.0 ) self.viewXVector3.normalize() self.viewYVector3 = self.viewpointVector3.cross( self.viewXVector3 ) self.viewYVector3.normalize()
def addArc( self, afterCenterDifferenceAngle, afterPoint, beforeCenterSegment, beforePoint, center ): "Add arc segments to the filleted skein." curveSection = 0.5 absoluteDifferenceAngle = abs( afterCenterDifferenceAngle ) steps = int( math.ceil( max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection ) ) ) stepPlaneAngle = euclidean.getPolar( afterCenterDifferenceAngle / steps, 1.0 ) for step in xrange( 1, steps ): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment ) arcPoint = center + beforeCenterSegment self.addLinearMovePoint( self.getCornerFeedrate(), arcPoint ) self.addLinearMovePoint( self.getCornerFeedrate(), afterPoint )
def helicalMove(self, isCounterclockwise, splitLine): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedRateToSplitLine(splitLine) location += self.oldLocation center = self.oldLocation.copy() indexOfR = gcodec.indexOfStartingWithSecond("R", splitLine) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) halfLocationMinusOld = location - self.oldLocation halfLocationMinusOld *= 0.5 halfLocationMinusOldLength = halfLocationMinusOld.magnitude() centerMidpointDistanceSquared = radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength centerMidpointDistance = math.sqrt(max(centerMidpointDistanceSquared, 0.0)) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis(halfLocationMinusOld) centerMinusMidpoint.normalize() centerMinusMidpoint *= centerMidpointDistance if isCounterclockwise: center.setToVector3(halfLocationMinusOld + centerMinusMidpoint) else: center.setToVector3(halfLocationMinusOld - centerMinusMidpoint) else: center.x = gcodec.getDoubleForLetter("I", splitLine) center.y = gcodec.getDoubleForLetter("J", splitLine) curveSection = 0.5 center += self.oldLocation afterCenterSegment = location - center beforeCenterSegment = self.oldLocation - center afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference(afterCenterSegment, beforeCenterSegment) absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) steps = int( round( 0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection, ) ) ) stepPlaneAngle = euclidean.getPolar(afterCenterDifferenceAngle / steps, 1.0) zIncrement = (afterCenterSegment.z - beforeCenterSegment.z) / float(steps) for step in xrange(1, steps): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle(stepPlaneAngle, beforeCenterSegment) beforeCenterSegment.z += zIncrement arcPoint = center + beforeCenterSegment self.addToPath(arcPoint) self.addToPath(location)
def helicalMove( self, isCounterclockwise, splitLine ): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedrateToSplitLine( splitLine ) location += self.oldLocation center = self.oldLocation.copy() indexOfR = gcodec.indexOfStartingWithSecond( "R", splitLine ) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfR ] ) halfLocationMinusOld = location - self.oldLocation halfLocationMinusOld *= 0.5 halfLocationMinusOldLength = halfLocationMinusOld.magnitude() centerMidpointDistance = math.sqrt( radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength ) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis( halfLocationMinusOld ) centerMinusMidpoint.normalize() centerMinusMidpoint *= centerMidpointDistance if isCounterclockwise: center.setToVec3( halfLocationMinusOld + centerMinusMidpoint ) else: center.setToVec3( halfLocationMinusOld - centerMinusMidpoint ) else: center.x = gcodec.getDoubleForLetter( "I", splitLine ) center.y = gcodec.getDoubleForLetter( "J", splitLine ) curveSection = 0.5 center += self.oldLocation afterCenterSegment = location - center beforeCenterSegment = self.oldLocation - center afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference( afterCenterSegment, beforeCenterSegment ) absoluteDifferenceAngle = abs( afterCenterDifferenceAngle ) steps = int( round( 0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection ) ) ) stepPlaneAngle = euclidean.getPolar( afterCenterDifferenceAngle / steps, 1.0 ) zIncrement = ( afterCenterSegment.z - beforeCenterSegment.z ) / float( steps ) for step in xrange( 1, steps ): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment ) beforeCenterSegment.z += zIncrement arcPoint = center + beforeCenterSegment self.addToPath( arcPoint ) self.addToPath( location )
def setShape( self, matrix4By4 ): "Set the shape of this carvable object info." numberOfSides = 31 height = float( self.object.attributeTable[ 'height' ] ) halfHeight = 0.5 * height radiusX = float( self.object.attributeTable[ 'rx' ] ) ratioTopOverBottom = float( self.object.attributeTable[ 'ratio' ] ) radiusZ = float( self.object.attributeTable[ 'rz' ] ) vertices = [] sideAngle = 2.0 * math.pi / float( numberOfSides ) halfSideAngle = 0.5 * sideAngle edgeTriples = [] vertexPairs = [] numberOfVertices = numberOfSides + numberOfSides numberOfCircumferentialEdges = numberOfVertices + numberOfVertices for side in xrange( numberOfSides ): bottomAngle = float( side ) * sideAngle bottomComplex = euclidean.getPolar( bottomAngle, 1.0 ) bottomPoint = Vector3( bottomComplex.real * radiusX, - halfHeight, bottomComplex.imag * radiusZ ) vertices.append( bottomPoint ) topPoint = Vector3( bottomPoint.x * ratioTopOverBottom, halfHeight, bottomPoint.z * ratioTopOverBottom ) vertices.append( topPoint ) vertexPairBottom = [ side + side, ( side + side + 2 ) % numberOfVertices ] vertexPairBottomIndex = len( vertexPairs ) vertexPairs.append( vertexPairBottom ) vertexPairDiagonal = [ ( side + side + 2 ) % numberOfVertices, side + side + 1 ] vertexPairDiagonalIndex = len( vertexPairs ) vertexPairs.append( vertexPairDiagonal ) vertexPairVertical = [ side + side + 1, side + side ] vertexPairVerticalIndex = len( vertexPairs ) vertexPairs.append( vertexPairVertical ) vertexPairTop = [ side + side + 1, ( side + side + 3 ) % numberOfVertices ] vertexPairTopIndex = len( vertexPairs ) vertexPairs.append( vertexPairTop ) edgeTripleBottomVertical = [ vertexPairBottomIndex, vertexPairDiagonalIndex, vertexPairVerticalIndex ] edgeTriples.append( edgeTripleBottomVertical ) edgeTripleBottomVertical = [ vertexPairTopIndex, vertexPairDiagonalIndex, ( vertexPairVerticalIndex + 4 ) % numberOfCircumferentialEdges ] edgeTriples.append( edgeTripleBottomVertical ) for side in xrange( 2, numberOfSides - 1 ): vertexPairBottomHorizontal = [ 0, side + side ] vertexPairs.append( vertexPairBottomHorizontal ) vertexPairTopHorizontal = [ 1, side + side + 1 ] vertexPairs.append( vertexPairTopHorizontal ) for side in xrange( 1, numberOfSides - 1 ): vertexPairBottomIndex = 4 * side vertexPairBottomDiagonalIndex = vertexPairBottomIndex + 4 vertexPairBottomBeforeIndex = vertexPairBottomIndex - 4 vertexPairTopIndex = 4 * side + 3 vertexPairTopDiagonalIndex = vertexPairTopIndex + 4 vertexPairTopBeforeIndex = vertexPairTopIndex - 4 if side > 1: vertexPairBottomBeforeIndex = numberOfCircumferentialEdges + 2 * side - 4 vertexPairTopBeforeIndex = vertexPairBottomBeforeIndex + 1 if side < numberOfSides - 2: vertexPairBottomDiagonalIndex = numberOfCircumferentialEdges + 2 * side - 2 vertexPairTopDiagonalIndex = vertexPairBottomDiagonalIndex + 1 edgeTripleBottomHorizontal = [ vertexPairBottomIndex, vertexPairBottomDiagonalIndex, vertexPairBottomBeforeIndex ] edgeTriples.append( edgeTripleBottomHorizontal ) edgeTripleTopHorizontal = [ vertexPairTopIndex, vertexPairTopDiagonalIndex, vertexPairTopBeforeIndex ] edgeTriples.append( edgeTripleTopHorizontal ) self.setBottomTopTriangleMesh( edgeTriples, matrix4By4, vertexPairs, vertices )