Beispiel #1
0
def removeIntersection( loop ):
	"Get loop without the first intersection."
	withoutIntersection = []
	for pointIndex in xrange( len( loop ) ):
		behindComplex = loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ]
		behindEndComplex = loop[ ( pointIndex + len( loop ) - 2 ) % len( loop ) ]
		behindMidpointComplex = 0.5 * ( behindComplex + behindEndComplex )
		aheadComplex = loop[ pointIndex ]
		aheadEndComplex = loop[ ( pointIndex + 1 ) % len( loop ) ]
		aheadMidpointComplex = 0.5 * ( aheadComplex + aheadEndComplex )
		normalizedSegment = behindComplex - behindMidpointComplex
		normalizedSegmentLength = abs( normalizedSegment )
		if normalizedSegmentLength > 0.0:
			normalizedSegment /= normalizedSegmentLength
			segmentYMirror = complex( normalizedSegment.real, - normalizedSegment.imag )
			behindRotated = segmentYMirror * behindComplex
			behindMidpointRotated = segmentYMirror * behindMidpointComplex
			aheadRotated = segmentYMirror * aheadComplex
			aheadMidpointRotated = segmentYMirror * aheadMidpointComplex
			y = behindRotated.imag
			isYAboveFirst = y > aheadRotated.imag
			isYAboveSecond = y > aheadMidpointRotated.imag
			if isYAboveFirst != isYAboveSecond:
				xIntersection = euclidean.getXIntersection( aheadRotated, aheadMidpointRotated, y )
				if xIntersection > min( behindMidpointRotated.real, behindRotated.real ) and xIntersection < max( behindMidpointRotated.real, behindRotated.real ):
					intersectionPoint = normalizedSegment * complex( xIntersection, y )
					loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ] = intersectionPoint
					del loop[ pointIndex ]
					return
Beispiel #2
0
def removeIntersection( loop ):
	"Get loop without the first intersection."
	withoutIntersection = []
	for pointIndex in xrange( len( loop ) ):
		behindComplex = loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ]
		behindEndComplex = loop[ ( pointIndex + len( loop ) - 2 ) % len( loop ) ]
		behindMidpointComplex = 0.5 * ( behindComplex + behindEndComplex )
		aheadComplex = loop[ pointIndex ]
		aheadEndComplex = loop[ ( pointIndex + 1 ) % len( loop ) ]
		aheadMidpointComplex = 0.5 * ( aheadComplex + aheadEndComplex )
		normalizedSegment = behindComplex - behindMidpointComplex
		normalizedSegmentLength = abs( normalizedSegment )
		if normalizedSegmentLength > 0.0:
			normalizedSegment /= normalizedSegmentLength
			segmentYMirror = complex( normalizedSegment.real, - normalizedSegment.imag )
			behindRotated = segmentYMirror * behindComplex
			behindMidpointRotated = segmentYMirror * behindMidpointComplex
			aheadRotated = segmentYMirror * aheadComplex
			aheadMidpointRotated = segmentYMirror * aheadMidpointComplex
			y = behindRotated.imag
			isYAboveFirst = y > aheadRotated.imag
			isYAboveSecond = y > aheadMidpointRotated.imag
			if isYAboveFirst != isYAboveSecond:
				xIntersection = euclidean.getXIntersection( aheadRotated, aheadMidpointRotated, y )
				if xIntersection > min( behindMidpointRotated.real, behindRotated.real ) and xIntersection < max( behindMidpointRotated.real, behindRotated.real ):
					intersectionPoint = normalizedSegment * complex( xIntersection, y )
					loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ] = intersectionPoint
					del loop[ pointIndex ]
					return
Beispiel #3
0
def addLineXSegmentIntersection( lineLoopsIntersections, segmentFirstX, segmentSecondX, vector3First, vector3Second, y ):
	"Add intersections of the line with the x segment."
	isYAboveFirst = y > vector3First.imag
	isYAboveSecond = y > vector3Second.imag
	if isYAboveFirst == isYAboveSecond:
		return
	xIntersection = euclidean.getXIntersection( vector3First, vector3Second, y )
	if xIntersection <= min( segmentFirstX, segmentSecondX ):
		return
	if xIntersection >= max( segmentFirstX, segmentSecondX ):
		return
	lineLoopsIntersections.append( xIntersection )