Exemple #1
0
def getRandomGrid(diameter, loopsComplex, maximumComplex, minimumComplex, xmlElement):
	"Get rectangular grid."
	packingDensity = evaluate.getEvaluatedFloatByKeys(0.2, ['packingDensity', 'density'], xmlElement)
	gridPath = []
	diameterReciprocal = complex(1.0 / diameter.real, 1.0 / diameter.imag)
	diameterSquared = diameter.real * diameter.real + diameter.imag * diameter.imag
	elements = int(math.ceil(packingDensity * euclidean.getAreaLoops(loopsComplex) / diameterSquared / math.sqrt(0.75)))
	elements = evaluate.getEvaluatedIntDefault(elements, 'elements', xmlElement)
	failedPlacementAttempts = 0
	pixelDictionary = {}
	seed = evaluate.getEvaluatedIntDefault(None, 'seed', xmlElement)
	if seed != None:
		random.seed(seed)
	successfulPlacementAttempts = 0
	while failedPlacementAttempts < 100:
		point = euclidean.getRandomComplex(minimumComplex, maximumComplex)
		if getIsPointInsideZoneAwayOthers(diameterReciprocal, loopsComplex, point, pixelDictionary):
			gridPath.append(point)
			euclidean.addElementToPixelListFromPoint(point, pixelDictionary, point)
			successfulPlacementAttempts += 1
		else:
			failedPlacementAttempts += 1
		if successfulPlacementAttempts >= elements:
			return gridPath
	return gridPath
Exemple #2
0
def getRandomGrid(derivation, diameter, elementNode, loopsComplex,
                  maximumComplex, minimumComplex):
    'Get rectangular grid.'
    gridPath = []
    diameterReciprocal = complex(1.0 / diameter.real, 1.0 / diameter.imag)
    diameterSquared = diameter.real * diameter.real + diameter.imag * diameter.imag
    elements = int(
        math.ceil(derivation.density * euclidean.getAreaLoops(loopsComplex) /
                  diameterSquared / math.sqrt(0.75)))
    elements = evaluate.getEvaluatedInt(elements, elementNode, 'elements')
    failedPlacementAttempts = 0
    pixelDictionary = {}
    if derivation.seed != None:
        random.seed(derivation.seed)
    successfulPlacementAttempts = 0
    while failedPlacementAttempts < 100:
        point = euclidean.getRandomComplex(minimumComplex, maximumComplex)
        if getIsPointInsideZoneAwayOthers(diameterReciprocal, loopsComplex,
                                          point, pixelDictionary):
            gridPath.append(point)
            euclidean.addElementToPixelListFromPoint(point, pixelDictionary,
                                                     point)
            successfulPlacementAttempts += 1
        else:
            failedPlacementAttempts += 1
        if successfulPlacementAttempts >= elements:
            return gridPath
    return gridPath
	def __init__(self, elementNode):
		'Initialize.'
		elementNode.attributes['closed'] = 'true'
		self.density = evaluate.getEvaluatedFloat(1.0, elementNode, 'density')
		self.minimumRadiusOverThickness = evaluate.getEvaluatedFloat(1.0, elementNode, 'minimumRadiusOverThickness')
		self.mobile = evaluate.getEvaluatedBoolean(False, elementNode, 'mobile')
		self.inradius = lineation.getInradius(complex(10.0, 10.0), elementNode)
		self.path = None
		if 'path' in elementNode.attributes:
			self.path = evaluate.getPathByKey([], elementNode, 'path')
		self.searchAttempts = evaluate.getEvaluatedInt(0, elementNode, 'searchAttempts')
		self.searchRadiusOverRadius = evaluate.getEvaluatedFloat(1.0, elementNode, 'searchRadiusOverRadius')
		self.seed = evaluate.getEvaluatedInt(None, elementNode, 'seed')
		self.wallThickness = evaluate.getEvaluatedFloat(2.0 * setting.getPerimeterWidth(elementNode), elementNode, 'wallThickness')
		# Set derived variables.
		self.halfWallThickness = 0.5 * self.wallThickness
		self.inradiusMinusThickness = self.inradius - complex(self.wallThickness, self.wallThickness)
		self.minimumRadius = evaluate.getEvaluatedFloat(self.minimumRadiusOverThickness * self.wallThickness, elementNode, 'minimumRadius')
		self.inradiusMinusRadiusThickness = self.inradiusMinusThickness - complex(self.minimumRadius, self.minimumRadius)
		self.potentialBubbleArea = 4.0 * self.inradiusMinusThickness.real * self.inradiusMinusThickness.imag
		if self.path is None:
			radiusPlusHalfThickness = self.minimumRadius + self.halfWallThickness
			numberOfPoints = int(math.ceil(self.density * self.potentialBubbleArea / math.pi / radiusPlusHalfThickness / radiusPlusHalfThickness))
			self.path = []
			if self.seed is None:
				self.seed = time.time()
				print('Sponge slice seed used was: %s' % self.seed)
			random.seed(self.seed)
			for pointIndex in xrange(numberOfPoints):
				point = euclidean.getRandomComplex(-self.inradiusMinusRadiusThickness, self.inradiusMinusRadiusThickness)
				self.path.append(Vector3(point.real, point.imag))
Exemple #4
0
def getRandomGrid(derivation, diameter, elementNode, loopsComplex, maximumComplex, minimumComplex):
    "Get rectangular grid."
    gridPath = []
    diameterReciprocal = complex(1.0 / diameter.real, 1.0 / diameter.imag)
    diameterSquared = diameter.real * diameter.real + diameter.imag * diameter.imag
    elements = int(
        math.ceil(derivation.density * euclidean.getAreaLoops(loopsComplex) / diameterSquared / math.sqrt(0.75))
    )
    elements = evaluate.getEvaluatedInt(elements, elementNode, "elements")
    failedPlacementAttempts = 0
    pixelDictionary = {}
    if derivation.seed != None:
        random.seed(derivation.seed)
    successfulPlacementAttempts = 0
    while failedPlacementAttempts < 100:
        point = euclidean.getRandomComplex(minimumComplex, maximumComplex)
        if getIsPointInsideZoneAwayOthers(diameterReciprocal, loopsComplex, point, pixelDictionary):
            gridPath.append(point)
            euclidean.addElementToPixelListFromPoint(point, pixelDictionary, point)
            successfulPlacementAttempts += 1
        else:
            failedPlacementAttempts += 1
        if successfulPlacementAttempts >= elements:
            return gridPath
    return gridPath