def __init__(self, viewpointLatitude, viewpointLongitude): "Initialize the view vectors." longitudeComplex = euclidean.getUnitPolar(math.radians(90.0 - viewpointLongitude)) self.viewpointLatitudeRatio = euclidean.getUnitPolar(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 createShape( self, matrixChain ): "Create the shape." numberOfSides = 31 halfHeight = 0.5 * self.height sideAngle = 2.0 * math.pi / float( numberOfSides ) polygonBottom = [] polygonTop = [] imaginaryRadius = self.radiusZ if self.isYImaginaryAxis: imaginaryRadius = self.radiusY for side in xrange( numberOfSides ): angle = float( side ) * sideAngle unitComplex = euclidean.getUnitPolar( angle ) pointBottom = complex( unitComplex.real * self.radiusX, unitComplex.imag * imaginaryRadius ) polygonBottom.append( pointBottom ) if self.topOverBottom > 0.0: polygonTop.append( pointBottom * self.topOverBottom ) if self.topOverBottom <= 0.0: polygonTop.append( complex() ) bottomTopPolygon = [ triangle_mesh.getAddIndexedLoop( polygonBottom, self.vertices, - halfHeight ), triangle_mesh.getAddIndexedLoop( polygonTop, self.vertices, halfHeight ) ] triangle_mesh.addPillarFromConvexLoops( self.faces, bottomTopPolygon ) if not self.isYImaginaryAxis: for vertex in self.vertices: oldY = vertex.y vertex.y = vertex.z vertex.z = oldY self.transformSetBottomTopEdges( matrixChain )
def createShape(self, matrixChain): "Create the shape." numberOfSides = 31 halfHeight = 0.5 * self.height sideAngle = 2.0 * math.pi / float(numberOfSides) polygonBottom = [] polygonTop = [] imaginaryRadius = self.radiusZ if self.isYImaginaryAxis: imaginaryRadius = self.radiusY for side in xrange(numberOfSides): angle = float(side) * sideAngle unitComplex = euclidean.getUnitPolar(angle) pointBottom = complex(unitComplex.real * self.radiusX, unitComplex.imag * imaginaryRadius) polygonBottom.append(pointBottom) if self.topOverBottom > 0.0: polygonTop.append(pointBottom * self.topOverBottom) if self.topOverBottom <= 0.0: polygonTop.append(complex()) bottomTopPolygon = [ triangle_mesh.getAddIndexedLoop(polygonBottom, self.vertices, -halfHeight), triangle_mesh.getAddIndexedLoop(polygonTop, self.vertices, halfHeight) ] triangle_mesh.addPillarFromConvexLoops(self.faces, bottomTopPolygon) if not self.isYImaginaryAxis: for vertex in self.vertices: oldY = vertex.y vertex.y = vertex.z vertex.z = oldY self.transformSetBottomTopEdges(matrixChain)
def addArc( self, afterCenterDifferenceAngle, afterPoint, beforeCenterSegment, beforePoint, center ): "Add arc segments to the filleted skein." absoluteDifferenceAngle = abs( afterCenterDifferenceAngle ) # steps = int( math.ceil( absoluteDifferenceAngle * 1.5 ) ) steps = int( math.ceil( min( absoluteDifferenceAngle * 1.5, absoluteDifferenceAngle * abs( beforeCenterSegment ) / self.curveSection ) ) ) stepPlaneAngle = euclidean.getUnitPolar( afterCenterDifferenceAngle / steps ) 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 addArc(self, afterCenterDifferenceAngle, afterPoint, beforeCenterSegment, beforePoint, center): "Add arc segments to the filleted skein." absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) # steps = int( math.ceil( absoluteDifferenceAngle * 1.5 ) ) steps = int( math.ceil( min( absoluteDifferenceAngle * 1.5, absoluteDifferenceAngle * abs(beforeCenterSegment) / self.curveSection))) stepPlaneAngle = euclidean.getUnitPolar(afterCenterDifferenceAngle / steps) 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.getUnitPolar( afterCenterDifferenceAngle / steps ) 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 getMoveCoordinate(self): "Get the movement coordinate from the class relative latitude and longitude." motionRadius = (0.75 + self.relativeLatitude) * self.window.getCanvasRadius() return self.window.getScreenComplex(motionRadius * euclidean.getUnitPolar(self.relativeLongitude))