def findLongestDimension(pointList): '''calls direction, returns length in that direction''' direction = findLongestDirection(pointList) #direction is a unit vector, so can do scalar projection, i.e. #dot product of each point with direction gives the length in that direction #and is negative if in the opposite direction, so just find max-min and return firstPoint = pointList[0] try: if 1 == len(direction): direction = direction[0] #numpy/numeric return differently except TypeError: pass min = geometry_basic.dot(firstPoint, direction) max = min #same for now for point in pointList[1:]: #already done first point newScalar = geometry_basic.dot(point, direction) try: if newScalar < min: min = newScalar if newScalar > max: max = newScalar except TypeError: newScalar = newScalar.real min = min.real max = max.real if newScalar < min: min = newScalar if newScalar > max: max = newScalar return max-min
def findDimensions(pointList): '''finds the dimension in the 3 principal directions, longest first''' dimensions = [] directions = sortDirections(pointList) for direction in directions: firstPoint = pointList[0] try: if 1 == len(direction): direction = direction[0] #stupid numpy except TypeError: pass min = geometry_basic.dot(firstPoint, direction) max = min #same for now for point in pointList[1:]: #already done first point newScalar = geometry_basic.dot(point, direction) try: if newScalar < min: min = newScalar if newScalar > max: max = newScalar except TypeError: newScalar = newScalar.real min = min.real max = max.real if newScalar < min: min = newScalar if newScalar > max: max = newScalar dimensions.append(max - min) return dimensions
def findProjectAndSplit(pointListList, altSplit=False): '''finds the eigs, projects the points, splits into 2 sub lists. returns indices from orig pointListList split into 2 groups. altsplit true means biggest gap splitting altsplit false means bisective splitting (based on average) maybe want a 3rd option to split on median (equal subgroups)''' maxVecRet = findLongestProjectedDirection(pointListList) flattenedList = flatten(pointListList) projectedPts = [] for pointList in flattenedList: projectedPt = geometry_basic.dot(maxVecRet, pointList) try: projectedPt = projectedPt.real #in case it is complex except AttributeError: pass #this is okay, not a complex number projectedPts.append(projectedPt) if not altSplit: #use bisective splitting, i.e. split based on mean avgPoint = geometry_basic.getAverage1(projectedPts) indicesSplit = findBisectiveSplit(projectedPts, avgPoint) else: indicesSplit = findBiggestGapSplit(projectedPts) return indicesSplit