コード例 #1
0
ファイル: intercircle.py プロジェクト: malx122/Software
def getCircleIntersectionsFromCircleNodes(circleNodes):
	'Get all the circle intersections which exist between all the circle nodes.'
	if len( circleNodes ) < 1:
		return []
	circleIntersections = []
	index = 0
	pixelTable = {}
	for circleNode in circleNodes:
		euclidean.addElementToPixelListFromPoint(circleNode, pixelTable, circleNode.dividedPoint)
	accumulatedCircleNodeTable = {}
	for circleNodeIndex in xrange(len(circleNodes)):
		circleNodeBehind = circleNodes[circleNodeIndex]
		circleNodeIndexMinusOne = circleNodeIndex - 1
		if circleNodeIndexMinusOne >= 0:
			circleNodeAdditional = circleNodes[circleNodeIndexMinusOne]
			euclidean.addElementToPixelListFromPoint(circleNodeAdditional, accumulatedCircleNodeTable, 0.5 * circleNodeAdditional.dividedPoint)
		withinNodes = circleNodeBehind.getWithinNodes(accumulatedCircleNodeTable)
		for circleNodeAhead in withinNodes:
			circleIntersectionForward = CircleIntersection(circleNodeAhead, index, circleNodeBehind)
			if not circleIntersectionForward.isWithinCircles(pixelTable):
				circleIntersections.append(circleIntersectionForward)
				circleNodeBehind.circleIntersections.append(circleIntersectionForward)
				index += 1
			circleIntersectionBackward = CircleIntersection(circleNodeBehind, index, circleNodeAhead)
			if not circleIntersectionBackward.isWithinCircles(pixelTable):
				circleIntersections.append(circleIntersectionBackward)
				circleNodeAhead.circleIntersections.append(circleIntersectionBackward)
				index += 1
	return circleIntersections
コード例 #2
0
ファイル: grid.py プロジェクト: lImbus/giseburt-ReplicatorG
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
コード例 #3
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
コード例 #4
0
ファイル: grid.py プロジェクト: GottfriedSp/ReplicatorG
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
コード例 #5
0
ファイル: grid.py プロジェクト: 1060460048/Cura
def getIsPointInsideZoneAwayOthers(diameterReciprocal, loopsComplex, point, pixelDictionary):
	'Determine if the point is inside the loops zone and and away from the other points.'
	if not euclidean.getIsInFilledRegion(loopsComplex, point):
		return False
	pointOverDiameter = complex(point.real * diameterReciprocal.real, point.imag * diameterReciprocal.imag)
	squareValues = euclidean.getSquareValuesFromPoint(pixelDictionary, pointOverDiameter)
	for squareValue in squareValues:
		if abs(squareValue - pointOverDiameter) < 1.0:
			return False
	euclidean.addElementToPixelListFromPoint(pointOverDiameter, pixelDictionary, pointOverDiameter)
	return True
コード例 #6
0
ファイル: grid.py プロジェクト: lImbus/giseburt-ReplicatorG
def getIsPointInsideZoneAwayOthers(diameterReciprocal, loopsComplex, point, pixelDictionary):
	"Determine if the point is inside the loops zone and and away from the other points."
	if not euclidean.getIsInFilledRegion(loopsComplex, point):
		return False
	pointOverDiameter = complex(point.real * diameterReciprocal.real, point.imag * diameterReciprocal.imag)
	squareValues = euclidean.getSquareValuesFromPoint(pixelDictionary, pointOverDiameter)
	for squareValue in squareValues:
		if abs(squareValue - pointOverDiameter) < 1.0:
			return False
	euclidean.addElementToPixelListFromPoint(pointOverDiameter, pixelDictionary, pointOverDiameter)
	return True