def computeLocationAsLine(j):
	#STEP 0: Compute jointB's unit vector
	inv = j.jointA.copy()
	locA = j.jointA.copy()
	locB = j.jointB.copy()
	inv.negative()
	locB.add(inv)
	l = locB.findLength(location(0,0,0))
	#STEP 1: Multiply new span length times the unit vector
	locD = location(locA.x + locB.x * j.spanA.l/l, locA.y + locB.y * j.spanA.l/l, locA.z + locB.z * j.spanA.l/l)
	return locD
def solvePointToLine(xe,ye,ze,x1,y1,z1,x2,y2,z2,r,debugPrint=False):
	a = (x1*x1-2*x1*x2+x2*x2) + (y1*y1-2*y1*y2+y2*y2) + (z1*z1-2*z1*z2+z2*z2)
	b = 2.0*(x1*x2-x1*xe-x2*x2+x2*xe + y1*y2-y1*ye-y2*y2+y2*ye + z1*z2-z1*ze-z2*z2+z2*ze) 
	c = x2*x2-2*x2*xe+xe*xe + y2*y2-2*y2*ye+ye*ye + z2*z2-2*z2*ze+ze*ze - r*r
	if debugPrint:
		print 'x1:%f,x2:%f,y1:%f,y2:%f,z1:%f,z2:%f,xe:%f,ye:%f,ze:%f,r:%f,a:%f,b:%f,c:%f'%(x1,x2,y1,y2,z1,z1,xe,ye,ze,r,a,b,c)
	
	#It's possible for A to become nearly zero but not quite, giving totally bad solutions as things are divided by a very small number
	if jgh.isEssentiallyZero(a) or jgh.tolerantSqrt(b*b - 4.0*a*c,handleExceptions=True) == 'NULL':
		if debugPrint:
			print "Endpts: Unable to make ptA or ptB"
		return ['NULL','NULL']
	na = (-b + jgh.tolerantSqrt(b*b - 4.0*a*c))/(2.0*a)	
	nb = (-b - jgh.tolerantSqrt(b*b - 4.0*a*c))/(2.0*a)
	#STEP 2:	
	ptA = location(na*(x1-x2)+x2,na*(y1-y2)+y2,na*(z1-z2)+z2)
	ptB = location(nb*(x1-x2)+x2,nb*(y1-y2)+y2,nb*(z1-z2)+z2)
	return ptA,ptB
def create_next_locations(currentlocation, next_location_names,
                          distance_directory):
    next_locations = []
    for city in next_location_names:
        #print 'adding '+city+'with previous city - '+currentlocation.city
        next_location = location(city, currentlocation, distance_directory)
        next_locations.append(next_location)
    currentlocation.state = 'explored'
    #print next_locations
    return next_locations
Example #4
0
    def explore_child_nodes(self, node):
        destination = None
        for option in node.next_location_names:
            #print 'Exploring option: '+option+' - from parent node: '+ node.city
            option_node = location(option, node, self.distance_directory)
            if super(Depth_First_Finder,
                     self).checkIsDestination(option_node.city):
                return option_node

            elif not super(Depth_First_Finder, self).is_dead_end(option_node):
                return self.explore_child_nodes(option_node)
Example #5
0
	def getDisplayCoordinates(self,structDisp,loc):
		newLoc = loc.copy()
		#Center it -- We don't center it first because the center is computed based on the perspective
		#newLoc.add(location(-self.xCenter,-self.yCenter,-self.zCenter))
		#Rotate it
		newLoc.rotateY(self.yRotate*math.pi*2.0)
		newLoc.rotateX(-self.xRotate*math.pi*2.0)
		#Resize it for display
		newLoc.add(location(-self.xCenter,-self.yCenter,0.0))#This z part doesn't matter since we already rotated
		newLoc.x = self.internal_sizeAndPlaceForDisplay(newLoc.x,structDisp.imageResize,True)
		newLoc.y = self.internal_sizeAndPlaceForDisplay(newLoc.y,structDisp.imageResize,False)
		return newLoc	
Example #6
0
    def searchRoute(self):
        if super(Depth_First_Finder, self).checkIsDestination(self.origin):
            print('origin is destination')
            super(Depth_First_Finder, self).printRoute(None)
        else:
            origin_node = location(self.origin, None, self.distance_directory)
            #search_tree = [origin_node]
            destination = None
            if not super(Depth_First_Finder, self).is_dead_end(origin_node):
                destination = self.explore_child_nodes(origin_node)
                super(Depth_First_Finder, self).printRoute(destination)

            else:
                print('you are in island')

        return self.route
    def explore_child_nodes(self, node, depth, limit):
        destination = None
        for option in node.next_location_names:
            #print 'Exploring option: '+option+' - from parent node: '+ node.city + ' Index - '+str(depth)+'limit - '+str(limit)
            option_node = location(option, node, self.distance_directory)

            if int(depth) >= int(limit):
                return None
            elif super(Iterative_Depth_Finder,
                       self).checkIsDestination(option_node.city):
                return option_node

            elif (not super(Iterative_Depth_Finder,
                            self).is_dead_end(option_node)):
                destination = self.explore_child_nodes(option_node, depth + 1,
                                                       limit)
                if destination != None:
                    return destination
    def searchRoute(self):
        #print 'inside bfs finder'
        if super(Breadth_First_Finder, self).checkIsDestination(self.origin):
            print('origin is destination')
            super(Breadth_First_Finder, self).printRoute(None)
        else:
            origin_node = location(self.origin, None, self.distance_directory)
            search_tree = [origin_node]
            destination = None
            if not super(Breadth_First_Finder, self).is_dead_end(origin_node):
                #print 'have frontiers'
                #print origin_node.next_location_names
                for node in search_tree:
                    #print node.city
                    if super(Breadth_First_Finder,
                             self).checkIsDestination(node.city):
                        destination = node
                        break
                    else:
                        search_tree.extend(
                            create_next_locations(node,
                                                  node.next_location_names,
                                                  self.distance_directory))
                    #print len(search_tree)
                #print 'Destination is:'
                #print destination.city
                """self.route = [destination.city]
                parent_city = destination.prev_city
                

                while parent_city.prev_city != None:
                    self.route.append(parent_city.city)
                    parent_city = parent_city.prev_city
                else:
                   self.route.append(parent_city.city)                    

                self.route = list(reversed(self.route))
                print self.route"""
                super(Breadth_First_Finder, self).printRoute(destination)

            else:
                print('you are in island')

        return self.route
    def searchRoute(self):
        #print 'inside ids finder'
        if super(Iterative_Depth_Finder, self).checkIsDestination(self.origin):
            print('origin is destination')
            super(Iterative_Depth_Finder, self).printRoute(None)
        else:
            origin_node = location(self.origin, None, self.distance_directory)
            destination = None
            #first_iter = True
            if not super(Iterative_Depth_Finder,
                         self).is_dead_end(origin_node):
                depth = 0
                while destination == None:
                    destination = self.explore_child_nodes(
                        origin_node, 0, depth + int(self.depthlimit))
                    depth += int(self.depthlimit)
                super(Iterative_Depth_Finder, self).printRoute(destination)

            else:
                print('you are in island')

        return self.route
def solveForXY(locA,lenA,locB,lenB):
       	Lab = locB.x - locA.x #Right here, we don't know the distance between the old points, we rely on them having been computed correctly.
       	Lal = lenA 
	Lpmax = lenB
	Y = tolerantSqrt(math.pow(Lpmax,2.0) - math.pow((Lal*Lal - Lab*Lab - Lpmax*Lpmax)/(-2.0*Lab),2.0))
       	#By definition of the directions chose, this point is always above the line	
	locC = location(0.0,0.0,0.0)
	locC.y = -Y #Because of the rotation we did, the Y is always in the negative in this space
	if(Lpmax*Lpmax >= (Lab*Lab + Lal*Lal)): #The angle on point 1 is going to be obtuse
		try:
			locC.x = -tolerantSqrt(Lal*Lal - Y*Y)
		except:
			print "ERROR: Lal:%f, Y:%f"%(Lal,Y)
			raise
	else:	#The angle on point 1 is acute
		try:	
			locC.x = tolerantSqrt(Lal*Lal - Y*Y)	
		except:
			print "ERROR: Lal:%f, Y:%f"%(Lal,Y)
			raise
	#print "Lpmax: %f, Lal:%f, Lab:%f, NewX:%f"%(Lpmax,Lal,Lab,locC.x)
	return locC.x, locC.y
def computeLocationAs2D(j):
	#STEP 0: Copy initial points so they never drift with repeated transformations
	#STEP 1: Translate to make point 1 the origin
	#STEP 2: Rotate around Y axis till point 2 lies in Z=0 plane
	#STEP 3: Rotate around Z axis till point 2 lies in Y=0 plane (now must be on the X-axis)
	#STEP 4: Rotate around X axis till point 3 lies in Z=0 plane
	#STEP 4: Solve for X and Y 
	#STEP 5: Build the solution
	#STEP 6: Back out all transformations

	#STEP 0:	
	locA,locB,locC = copyAllJoints(j)	
	#STEP 1: 
	step1Inverse = jgh.moveToOrigin(locA,[locA,locB,locC])
	#STEP 2:
	step2Inverse = jgh.rotateYToXYPlane(locB,[locA,locB,locC])	 
	#STEP 3:
	step3Inverse = jgh.rotateZToXZPlane(locB,[locA,locB,locC])
	#STEP 4:
	if(j.farOrNear == 'n'):
		yIsPositive = False
	else:
		yIsPositive = True
	step4Inverse = jgh.rotateXToXYPlane(locC,[locA,locB,locC],yIsPos=yIsPositive)
	#STEP 5:
	x,y = jgh.solveForXY(locA,j.spanA.l,locB,j.spanB.l)	
	#BUILD SOLUTION	
	locD = location(x,y,0)	
	#STEP 4-inverse:
	jgh.rotateXToXYPlane_reverse(locD,step4Inverse)
	#STEP 3-inverse:
	jgh.rotateZToXZPlane_reverse(locD,step3Inverse)	
	#STEP 2-inverse:
	jgh.rotateYToXYPlane_reverse(locD,step2Inverse)	
	#STEP 1-inverse:
	jgh.moveToOrigin_reverse(locD,step1Inverse)	
	#RETURN: The main function will set this object to have the location of locD
	return locD
def checkForCollisionEdgeCylinder(line,otherLine,minDistance,debugPrint=False):
	#debugPrint = True
	#STEP 1: Copy joints
	#STEP 2: Move so that plane orig is 0,0,0
	#STEP 3: Rotate around Y axis till line is in XY-plane
	#STEP 4: Rotate around Z axis till line is the X-axis
	# -- Span/span collision -- (if the other line penetrates the cylinder around this line, it will be caught here. But it can still come in through the ends...)	
	#STEP 5: Check X1 and Y1 to assure it's square is not zero-zero. If it is, the quad formula we'll use wont work so we'll need to give it just a quick translation	
	#STEP 6: Find the two possible collision points (care for the 1-point case)
	#STEP 7: Check each point to see if it's actually on the other line
	#STEP 8: Check each point to see if it's actually on line
	la,lb,ola,olb = jgh.copyPoints(line[0],line[1],otherLine[0],otherLine[1])
	allPoints = [la,lb,ola,olb]	
	if(debugPrint):
		print "step 1"	
		for pt in allPoints:
			print pt.toString()
	#STEP 2
	step2Inverse = jgh.moveToOrigin(la,allPoints)
	if(debugPrint):
		print "step 2"	
		for pt in allPoints:
			print pt.toString()
	#STEP 3:
	step3Inverse = jgh.rotateYToXYPlane(lb,allPoints)	 
	if(debugPrint):
		print "step 3"	
		for pt in allPoints:
			print pt.toString()
	#STEP 4:
	step4Inverse = jgh.rotateZToXZPlane(lb,allPoints)
	if(debugPrint):
		print "step 4"	
		for pt in allPoints:
			print pt.toString()

	#STEP 5:
	if ola.z*ola.z+ola.y*ola.y == 0.0:
		jgh.movePoints(location(0,1,1),allPoints)
		if debugPrint:
			print "step 5: had to move points"
	#STEP 6:
	z1 = ola.z
	y1 = ola.y
	x1 = ola.x
	z2 = olb.z
	y2 = olb.y
	x2 = olb.x
	ye = la.y #could pick either A or B since they should now be equal
	ze = la.z
	#Move everything onto x=0 since we're not acting like line is a point
	ptA,ptB = solvePointToLine(0,ye,ze,0,y1,z1,0,y2,z2,minDistance,debugPrint=debugPrint)
	if ptA == 'NULL' and ptB == 'NULL':
		if debugPrint:
			print "step 6: there's no point to be found here"
		return False
	else:
		if debugPrint:
			print "step 6: found points: %s\t%s"%(ptA.toString(),ptB.toString())
	#	Fill in the X values we ignored earlier
	if y1 != y2:
		ptA.x = ((ptA.y-y2)/(y1-y2))*(x1-x2)+x2
		ptB.x = ((ptB.y-y2)/(y1-y2))*(x1-x2)+x2
	elif z1 != z2: #if y is parallel, use z
		ptA.x = ((ptA.z-z2)/(z1-z2))*(x1-x2)+x2
		ptB.x = ((ptB.z-z2)/(z1-z2))*(x1-x2)+x2
	else: #Only ever get here if it's a perfect hit on a parallel line, which will also get picked up by the end caps
		if debugPrint:
			print "step 6: no solution for x"
		return False	
	#STEP 7:
	if (ola.findLength(ptA) > ola.findLength(olb) or olb.findLength(ptA) > olb.findLength(ola)):
		ptA = 'NULL'
		if debugPrint:
			print "step 7: eliminating pta"
	if (ola.findLength(ptB) > ola.findLength(olb) or olb.findLength(ptB) > olb.findLength(ola)):
		ptB = 'NULL'
		if debugPrint:
			print "step 7: eliminating ptb"
	#STEP 8:
	if ptA != 'NULL':
		if (ptA.x < 0.0 or ptA.x > lb.x):
			if debugPrint:
				print "step 8: eliminating pta"
			ptA = 'NULL'
	if ptB != 'NULL':
		if (ptB.x < 0.0 or ptB.x > lb.x):
			if debugPrint:
				print "step 8: eliminating ptb"
			ptB = 'NULL'		
	#RETURN 
	if ptA != 'NULL' or ptB != 'NULL':
		if debugPrint:
			print "found an edge point that collides"
		return True
	return False		
Example #13
0
        if answer == "N":
            break

    while True:
        isExist = input("Exist? T/F: ").upper()
        if isExist in ("T", "F"):
            break
    isExist = {"T": True, "F": False}[isExist]

    while True:
        isCompleted = input("Completed? T/F: ").upper()
        if isCompleted in ("T", "F"):
            break
    isCompleted = {"T": True, "F": False}[isCompleted]

    locationObj = location(building, roomNumber)
    courseObj = course(CRN, subj, courseNumber, title, locationObj, credits,
                       attributes, grades, days, isExist, isCompleted)
    courseDict[courseObj.getCRN()] = courseObj
    print(courseDict[courseObj.getCRN()])

    del courseObj
    del locationObj

    while True:
        answer = input("Add more courses? T/F: ").upper()
        if answer in ("T", "F"):
            break
    if not {"T": True, "F": False}[answer]:
        print(str(i) + " course(s) added.")
        break
Example #14
0
def getanswer(msg,query,orig_query):
	if msg == "<train status>":
		ans = train(query)
	elif msg == "<weather status>":
		ans = weather(query)
        elif msg == "<cricinfo module>":
                ans = cric_info(orig_query)
        elif msg == "<festival module>":
                ans = festival(orig_query)
        elif msg == "<tennis module>":
                ans = tennis(orig_query)
        elif msg == "<car module>":
        	ans=car(orig_query)
        elif msg == "<tank module>":
        	ans=tank(orig_query)
        elif msg == "<disease module>":
        	ans=disease(orig_query)       
	elif msg == "<flight module>":
                ans = flight(orig_query)
        elif msg == "<recipe module>":
                ans = recipe(orig_query)
	elif msg=="<discography module>":
		ans=discography(orig_query)
	elif msg=="<electronic module>":
		ans=electronic(orig_query)
        elif msg == "<wiki module>":
                ans = wiki_module(orig_query)

        elif msg == "<bank module>":
                ans = bank_module(orig_query)

	#elif msg == "<restaurant module>":
		#ans = restaurant(orig_query)
		
		
	#elif msg == "<website module>":
	#	ans = get_website(orig_query)

	elif msg == "<stock status>":
		ans = stock(query)
	elif msg == "<mineral status>":
		ans = mineral(query)
	elif msg == "<sports status>":
		ans = sports(query)
	elif msg == "<movie review>":
		ans = movie(query,orig_query)
        elif msg == "<exam status>":
                ans = exam(query)
        elif msg == "<locationcentric module>":
                ans = location(query)
	elif msg == "<highway module>":
                ans = highway(query)
	elif msg == "<differences module>":
                ans = differences(orig_query)
	elif msg == "<currency module>":
		ans = currency(query) 
	elif msg == "<meanings module>":
		ans= meanings(orig_query)  
        elif msg == "<theatre module>":
                ans= theatre(orig_query)
        elif msg == "<minister module>":
                ans= minister(orig_query)

        elif msg == "<std module>":
                ans= std(query)

        elif msg == "<bday module>":
                ans= [{"bday":[]}]

        elif msg == "<highcourt module>":
                ans = highcourt(orig_query)


	#print "here"             
	return ans
def checkForCollisionPlane(lineA,lineB,colLine,minDistance,debugPrint=False):
	if lineA == 'NULL' or lineB == 'NULL' or colLine == 'NULL':
		return False
	#STEP 1: Copy joints
	#STEP 2: Move so that plane orig is 0,0,0
	#STEP 3: Rotate around Y axis till plane pointA is in XY-plane
	#STEP 4: Rotate around Z axis till plane pointA in X-axis
	#STEP 5: Rotate around X axis till plane pointB is in XY-plane
	#STEP 6: Near edge: For each line end, check distance to Z, if less than min distance, check the point there
	#STEP 7: Clear cross: If the line begins and end on opposite sides of Z=0, solve for Z=0 and get the X,Y	
	#STEP 8: Check if the angle from origin to this new point is smaller than the angle to plane pointB
	#STEP 9: Check if the angle from planePointA to this new point is smaller than the angle from plane pointA to plane pointB

	#STEP 1
	plo,pla,plb,la,lb = jgh.copyPoints(lineA[0],lineA[1],lineB[1],colLine[0],colLine[1])
	allPoints = [plo,pla,plb,la,lb]	
	#STEP 2
	step2Inverse = jgh.moveToOrigin(plo,allPoints)
	if(debugPrint):
		print "step 2"	
		for pt in allPoints:
			print pt.toString()
	#STEP 3:
	step3Inverse = jgh.rotateYToXYPlane(pla,allPoints)	 
	if(debugPrint):
		print "step 3"	
		for pt in allPoints:
			print pt.toString()
	#STEP 4:
	step4Inverse = jgh.rotateZToXZPlane(pla,allPoints)
	if(debugPrint):
		print "step 4"	
		for pt in allPoints:
			print pt.toString()
	#STEP 5:
	step5Inverse = jgh.rotateXToXYPlane(plb,allPoints,yIsPos=True)
	if(debugPrint):
		print "step 5"	
		for pt in allPoints:
			print pt.toString()
	
	ptsToCheck = []
	#STEP 6:
	if (math.fabs(la.z)-minDistance) < 0.0: #No need to handle near-miss/hit with a fluff factor since we already have the standoff distance. 
		tmp = la.copy()
		tmp.z = 0.0	
		ptsToCheck.append(tmp)
		if debugPrint:
			print "end point was close to plane"
	if (math.fabs(lb.z)-minDistance) < 0.0: #No need to handle near-miss/hit with a fluff factor since we already have the standoff distance. 
		tmp = lb.copy()
		tmp.z = 0.0	
		ptsToCheck.append(tmp)
		if debugPrint:
			print "end point was close to plane"
	#STEP 7:
	if (la.z < 0.0 and lb.z > 0.0) or (la.z > 0.0 and lb.z < 0.0):
		#N(X1-X2)+X2 = X
		#N(Y1-Y2)+Y2 = Y
		#N(Z1-Z2)+Z2 = 0
		tmpX = lb.x + (-lb.z/(la.z-lb.z))*(la.x-lb.x)
		tmpY = lb.y + (-lb.z/(la.z-lb.z))*(la.y-lb.y)
		tmp = location(tmpX,tmpY,0.0)
		ptsToCheck.append(tmp)
		if debugPrint:
			print "line goes clear through the plane"
	#STEP 8,9:
	for pt in ptsToCheck:
		origAngleMax = math.atan2(plb.y,plb.x)
		origAngleFound = math.atan2(pt.y,pt.x)
		farAngleMax = math.atan2(plb.y,(pla.x-plb.x))	
		farAngleFound = math.atan2(pt.y,(pla.x-pt.x))
		if(origAngleFound > 0.0 and origAngleFound < origAngleMax and farAngleFound > 0.0 and farAngleFound < farAngleMax):
			if debugPrint:
				"line goes through the surface"	
			return True
		if debugPrint:
			print "STEP 8,9: Not a hit. point:%s, origAngleMax:%f, origAngleFound:%f, farAngleMax:%f, farAngleFound:%f"%(pt.toString(),origAngleMax,origAngleFound,farAngleMax,farAngleFound)
	return False
Example #16
0
		if answer == "N":
			break

	while True:
		isExist = input("Exist? T/F: ").upper()
		if isExist in ("T","F"):
			break
	isExist = {"T":True,"F":False}[isExist]

	while True:
		isCompleted = input("Completed? T/F: ").upper()
		if isCompleted in ("T","F"):
			break
	isCompleted = {"T":True,"F":False}[isCompleted]

	locationObj = location(building,roomNumber)
	courseObj = course(CRN, subj, courseNumber, title, locationObj, credits, attributes, grades, days, isExist, isCompleted)
	courseDict[courseObj.getCRN()] = courseObj
	print(courseDict[courseObj.getCRN()])

	del courseObj
	del locationObj

	while True:
		answer = input("Add more courses? T/F: ").upper()
		if answer in ("T","F"):
			break
	if not {"T":True,"F":False}[answer]:
		print(str(i) + " course(s) added.")
		break
	i += 1
def computeLocationAs3D(j,debugPrint=False):
	#debugPrint = True
	#print "NAME IS: %s"%j.name
	#STEP 0: Copy initial points so they never drift with repeated transformations
	#STEP 1: Translate to make point 1 the origin
	#STEP 2: Rotate around Y axis till point 2 lies in Z=0 plane
	#STEP 3: Rotate around Z axis till point 2 lies in Y=0 plane (now must be on the X-axis)
	#STEP 4: Solve for point 4(new point)'s to find the X and Y. The X here will end up being the real X in this space. The Y is simply the radius.
	#STEP 5: The problem now starts over, remaking a new point A and B
	#STEP 6: Translate to make point newA's X=0
	#STEP 7: Rotate around Y axis 90 degrees to make the solution circle lie at Z=0
	#STEP 8: Rotate around Z axis till point newB liest on the Y=0 plane (it now must be on the X-axis)
	#STEP 9: Solve for point 4(new point)'s to find the new X and Y locations. The transformations we've already done will fill out all the other data found along the way.
	#STEP 10: Build the solution
	#STEP 11: Back out all transformations

	#STEP 0:	
	locA,locB,locC = copyAllJoints(j)	
	#STEP 1: 
	step1Inverse = jgh.moveToOrigin(locA,[locA,locB,locC])
	if(debugPrint):
		print "step 1"	
		print locA.toString()
		print locB.toString()
		print locC.toString()
	#STEP 2:
	step2Inverse = jgh.rotateYToXYPlane(locB,[locA,locB,locC])	 
	if(debugPrint):
		print "step 2"	
		print locA.toString()
		print locB.toString()
		print locC.toString()

	#STEP 3:
	step3Inverse = jgh.rotateZToXZPlane(locB,[locA,locB,locC])
	if(debugPrint):
		print "step 3"	
		print locA.toString()
		print locB.toString()
		print locC.toString()

	#STEP 4:
	x,y = jgh.solveForXY(locA,j.spanA.l,locB,j.spanB.l)	
	if(debugPrint):
		print "step 4"
		print "x:%f, y:%f"%(x,y)
	#STEP 5: REMAKE PROBLEM:
	#  remake A
	newSpanA = math.fabs(y)
	newLocA = location(x,0.0,0.0)
	#  remake B: it's projection onto the X=whatever plane
	newSpanB = jgh.tolerantSqrt(math.pow(j.spanC.l,2) - math.pow(locC.x - x,2))
	newLocB = location(x,locC.y, locC.z)
	if(debugPrint):
		print "step 5"	
		print newLocA.toString()
		print newLocB.toString()
		print locC.toString()
		print newSpanA
		print newSpanB

	#STEP 6:
	step6Inverse = jgh.moveToOrigin(newLocA,[newLocA,newLocB])
	if(debugPrint):
		print "step 6"	
		print newLocA.toString()
		print newLocB.toString()
		print locC.toString()

	#STEP 7:
	step7Inverse = jgh.rotateYToXYPlane(location(0.0,0.0,-1.0),[newLocA,newLocB])#newLocB,[newLocA,newLocB])
	if(debugPrint):
		print "step 7"	
		print newLocA.toString()
		print newLocB.toString()
		print locC.toString()
	#STEP 8:
	step8Inverse = jgh.rotateZToXZPlane(newLocB,[newLocA,newLocB])
	if(debugPrint):
		print "step 8"	
		print newLocA.toString()
		print newLocB.toString()
		print locC.toString()
	#STEP 9:
	newX,newY = jgh.solveForXY(newLocA,newSpanA,newLocB,newSpanB)
	if(debugPrint):
		print "X: %f,  Y: %f"%(newX,newY)
	#BUILD SOLUTION	
	locD = location(newX,-newY,0)#Why is this negative? check your right hand rules when building, the solve function goes in the negative Y when we want it positive	
	#STEP 8-inverse:
	jgh.rotateZToXZPlane_reverse(locD,step8Inverse)
	if(debugPrint):
		print "step 8 inverse"	
		print locD.toString()
	#STEP 7-inverse:	
	jgh.rotateYToXYPlane_reverse(locD,step7Inverse)	
	if(debugPrint):
		print "step 7 inverse"
		print locD.toString()
	#STEP 6-inverse:
	jgh.moveToOrigin_reverse(locD,step6Inverse)	
	if(debugPrint):
		print "step 6 inverse"
		print locD.toString()
	#STEP 3-inverse:
	jgh.rotateZToXZPlane_reverse(locD,step3Inverse)	
	if(debugPrint):
		print "step 3 inverse"
		print locD.toString()
	#STEP 2-inverse:
	jgh.rotateYToXYPlane_reverse(locD,step2Inverse)	
	if(debugPrint):
		print "step 2 inverse"
		print locD.toString()
	#STEP 1-inverse:
	jgh.moveToOrigin_reverse(locD,step1Inverse)	
	if(debugPrint):
		print "step 1 inverse"
		print locD.toString()
	#RETURN: The main function will set this object to have the location of locD
	return locD	
def test_joint_collisions():
	p = True
	# -- LINES --
	#No-check cases
	if checkForCollisionSurface(True,False,[location(0,0,0),location(1,1,1)],'NULL',[location(0,0,0),location(1,1,1)],'NULL',1.0):
		print "ERROR on joint collisions test 1"
		p = False	
	
	if checkForCollisionSurface(False,True,[location(0,0,0),location(1,1,1)],'NULL',[location(0,0,0),location(1,1,1)],'NULL',1.0):
		print "ERROR on joint collisions test 2"
		p = False	
	#Single line on top of itself
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(1,1,1)],'NULL',[location(0,0,0),location(1,1,1)],'NULL',1.0):
		print "ERROR on joint collisions test 3"
		p = False	
	#Short line within a large line
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(1,0.0,0.0)],'NULL',[location(0.5,0,0),location(0.6,0,0)],'NULL',0.1):
		print "ERROR on joint collisions test 4"
		p = False	
	#Short line away from the large one
	if checkForCollisionSurface(True,True,[location(0,0,0),location(1,0.0,0.0)],'NULL',[location(0.5,1,1),location(0.6,1,0)],'NULL',0.1):
		print "ERROR on joint collisions test 5"
		p = False	
	#Line coming in from the end
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(1,0.0,0.0)],'NULL',[location(1.5,0.01,0.01),location(0.6,0.01,0.01)],'NULL',0.1):
		print "ERROR on joint collisions test 6"
		p = False	
	#Line coming in at an angle
	if not checkForCollisionSurface(True,True,[location(-2,-2,-2),location(2,2,2)],'NULL',[location(0.6,0.5,0.5),location(2,0,0)],'NULL',0.2):
		print "ERROR on joint collisions test 7"
		p = False	
	#Line coming in at an angle but the radius is too small
	if checkForCollisionSurface(True,True,[location(-2,-2,-2),location(2,2,2)],'NULL',[location(0.6,0.5,0.5),location(2,0,0)],'NULL',0.07):
		print "ERROR on joint collisions test 8"
		p = False	
	# -- Plane vs. line --
	#Simple plane with line through it
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(0,1,0)],[location(0,0,0),location(1,0,0)],[location(0.5,0.5,-1),location(0.5,0.5,1)],'NULL',0.07):
		print "ERROR on joint collisions test 9"
		p = False	
	#Simple plane with line through it but missing
	if checkForCollisionSurface(True,True,[location(0,0,0),location(0,1,0)],[location(0,0,0),location(1,0,0)],[location(1,1,-1),location(1,1,1)],'NULL',0.07):
		print "ERROR on joint collisions test 10"
		p = False	
	#Simple plane with line getting close to it
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(0,1,0)],[location(0,0,0),location(1,0,0)],[location(0.5,0.5,0.1),location(0.5,0.5,1)],'NULL',0.2):
		print "ERROR on joint collisions test 11"
		p = False	
	#Simple plane with line getting close to it but not close enough
	if checkForCollisionSurface(True,True,[location(0,0,0),location(0,1,0)],[location(0,0,0),location(1,0,0)],[location(0.5,0.5,0.3),location(0.5,0.5,1)],'NULL',0.2):
		print "ERROR on joint collisions test 12"
		p = False	
	#Simple plane with angled line from below
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(0,1,0)],[location(0,0,0),location(1,0,0)],[location(1,1,1),location(0,0,-1)],'NULL',0.2):
		print "ERROR on joint collisions test 13"
		p = False	
	#Angled plane with line getting close
	if checkForCollisionSurface(True,True,[location(100,10,0),location(100,20,-40)],[location(100,10,0),location(100,0,40)],[location(0.5,0.5,0.3),location(0.5,0.5,1)],'NULL',0.2):
		print "ERROR on joint collisions test 14"
		p = False	
	#Angled plane with line hitting and edge
	if not checkForCollisionSurface(True,True,[location(100,10,0),location(100,20,-40)],[location(100,10,0),location(100,0,40)],[location(0.5,0.5,0.3),location(100,0,40)],'NULL',0.2):
		print "ERROR on joint collisions test 15"
		p = False	
	#Angled plane with line skimming the center
	if not checkForCollisionSurface(True,True,[location(100,10,0),location(0,20,-40)],[location(100,10,0),location(100,0,40)],[location(110,5.1,20),location(-10,5.0,20)],'NULL',0.2):
		print "ERROR on joint collisions test 16"
		p = False	
	#Angled plane with line skimming the center
	if checkForCollisionSurface(True,True,[location(100,10,0),location(0,20,-40)],[location(100,10,0),location(100,0,40)],[location(110,5.3,20),location(-10,5.4,20)],'NULL',0.2):
		print "ERROR on joint collisions test 17"
		p = False
	# -- Plane on plane
	#Angled plane with angled plane larger than it
	if not checkForCollisionSurface(True,True,[location(100,10,0),location(0,20,-40)],[location(100,10,0),location(100,0,40)],[location(0,0,0),location(0,100,0)],[location(0,0,0),location(1000,0,0)],0.2):
		print "ERROR on joint collisions test 18"
		p = False	
	#Angled plane with angled plane that doesn't intersect
	if checkForCollisionSurface(True,True,[location(100,10,0),location(0,20,-40)],[location(100,10,0),location(100,0,40)],[location(0,20,0),location(0,120,0)],[location(0,20,0),location(1000,20,0)],0.2):
		print "ERROR on joint collisions test 19"
		p = False	
	#Angled plane with angled plane that's in range
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(-100,0,0)],[location(0,0,0),location(0,0,-100)],[location(0,-0.1,0),location(-100,-0.1,0)],[location(0,-0.1,0),location(0,-0.1,-100)],0.2):
		print "ERROR on joint collisions test 20"
		p = False	
	#Angled plane with angled plane that's not in range
	if checkForCollisionSurface(True,True,[location(0,0,0),location(-100,0,0)],[location(0,0,0),location(0,0,-100)],[location(0,-0.1,0),location(-100,-0.1,0)],[location(0,-0.1,0),location(0,-0.1,-100)],0.08):
		print "ERROR on joint collisions test 21"
		p = False	
	
	#Angled plane with angled plane that's barely in range
	if not checkForCollisionSurface(True,True,[location(0,0,0),location(-100,0,0)],[location(0,0,0),location(0,0,-100)],[location(0,-0.1,0),location(-100,-0.1,0)],[location(0,-0.1,0),location(0,-0.1,-100)],0.1001):
		print "ERROR on joint collisions test 22"
		p = False	
	#Angled plane with angled plane that's barely not in range
	if checkForCollisionSurface(True,True,[location(0,0,0),location(-100,0,0)],[location(0,0,0),location(0,0,-100)],[location(0,-0.1,0),location(-100,-0.1,0)],[location(0,-0.1,0),location(0,-0.1,-100)],0.0999):
		print "ERROR on joint collisions test 23"
		p = False
	# -- Now real objects --
	#Object that has no collisions
	s = mfStructure('a',[0,0,0],'b',[1,0,0])
	s.collisionMargin = 0.01
	s.add2DJoint('c','a',1,'b',math.sqrt(2),[0,1,0],'f',cd=True)
	s.addJoint('d','a',1,'c',math.sqrt(2),'b',math.sqrt(2),cd=True)
	s.computeLocations()
	if s.checkForCollisions():			
		print "ERROR on joint collisions test 24"
		p = False
	s.addJoint('e','a',math.sqrt(2),'d',math.sqrt(3),'c',1,cd=True)
	s.computeLocations()
	if s.checkForCollisions():
		print "ERROR on joint collisions test 25"
		p = False
	s.add1DJoint('f','a',10,'d')
	s.add2DJoint('g','f',1,'c',10,'a','f')
	s.add1DJoint('h','c',11,'g')
	s.addJoint('j','h',math.sqrt(11*11+1),'g',math.sqrt(10*10+1),'f',math.sqrt(10*10+1+1),cd=True)
	s.computeLocations()
	if not s.checkForCollisions():
		print "ERROR on joint collisions test 26"	
		p = False
#if not j.internal_checkForCollisionEdge([location(0,0,0),location(1,1,1)],[location(0.0,0.0,0.0),location(1.0,1.0,1.0)],1.0):
	#if not j.internal_checkForCollisionEdge([location(0,0,0),location(1,1,1)],[location(0.0,0.0,0.0),location(1.0,1.0,1.0)],1.0):
	#	print "ERROR on joint collisions test 4"
	#	p = False	
	#Check for various combinations of central collisions
	#Check for combinations of edge collisions
	#j.internal_checkForCollisionSurfaces(True,True,lineA,lineB,otherLineA,otherLineB,minDistance):
		
	#def internal_checkForCollisionPlane(self,lineA,lineB,colLine,minDistance,debugPrint=False):
	#def internal_checkForCollisionEdge(self,line,otherLine,minDistance):
	return p
def test_joint_locationComputation():
	p = True
	#Test case: Rotation
	l1 = location(0,1.0/math.sqrt(2),1.0/math.sqrt(2)) #Y=1, Z=1
	l2 = location(0,1.0/math.sqrt(2),-1.0/math.sqrt(2))
	inv = jgh.rotateXToXYPlane(l1,[l2],yIsPos=True)
	if(l2.z < -1.1 or l2.z > -0.9 or l2.y > 0.1 or l2.y < -0.1 or l2.x > 0.1 or l2.x < -0.1):
		p = False
		print "ERROR on test case 1a: %s"%l2.toString()
	jgh.rotateXToXYPlane_reverse(l2,inv)
	if(l2.z	< -0.8 or l2.z > -0.7 or l2.y > 0.8 or l2.y < 0.7):
		p = False
		print "ERROR on test case 1b: %s"%l2.toString()
	inv = jgh.rotateXToXYPlane(l1,[l2],yIsPos=False)
        if(l2.z < 0.9 or l2.z > 1.1 or l2.y > 0.1 or l2.y < -0.1 or l2.x > 0.1 or l2.x < -0.1):
                p = False
                print "ERROR on test case 1c: %s"%l2.toString()

	#Test case: Rotation
	l1 = location(0,100,-1)
	l2 = location(-1,-100,0)
	inv = jgh.rotateYToXYPlane(l1,[l2])
	if(l2.z > -0.9 or l2.z < -1.1 or l2.x > 0.1 or l2. x < -0.1):
		p = False
		print "ERROR on test case 2: %s"%l2.toString()	
	
	#Test case: Rotation
	l1 = location(-1.0,-1.0,0.0)
	l2 = location(1.0,-1.0,0)
	inv = jgh.rotateZToXZPlane(l1,[l2])
	if(l2.z < -0.1 or l2.z > 0.1 or l2.x < -0.1 or l2.x > 0.1 or l2.y > math.sqrt(2)+0.01 or l2.y < math.sqrt(2)-0.01):
		p = False
		print "ERROR on test case 3: %s"%l2.toString()	

	#Test case: Line
	j = joint()
	j.jointA = location(0,4,0)
	j.jointB = location(1,1,1)
	j.spanA = span( 2.0)
	j.computeLocation()
	if(j.x > 0.61 or j.x < 0.60 or j.y > 2.2 or j.y < 2.1 or j.z > 0.61 or j.z < 0.60):
		p = False
		print "ERROR on test case 4: %s"%j.toString()

	#Test case: 2D joint
	j = joint()
	j.jointA = location(1.0,1.0,0.0)
	j.jointB = location(0.0,1.0,0.0)	
	j.jointC = location(0.0,1.0,0.0)
	j.spanA = span(math.sqrt(2.0))
	j.spanB = span(1.0)
	j.farOrNear = 'f'
	j.computeLocation()
	if(j.x > 0.01 or j.x < -0.01 or j.y > 1.01 or j.y < -0.99 or j.z > 1.01 or j.z < 0.99):
		p = False
		print "ERROR on test case 5: %s"%j.toString()
	
	#Test case: 2D joint
	j = joint()
	j.jointA = location(0.0,1.0,0.0)	
	j.jointB = location(4.0,1.0,0.0)	
	j.jointC = location(0.5,6.0,-2.0)
	j.spanA = span(4.0)
	j.spanB = span(4.0)
	j.farOrNear = 'f'
	j.computeLocation()
	if(j.x > 2.01 or j.x < 1.99 or j.y < -2.22 or j.y > -2.21 or j.z > 1.29 or j.z < 1.285):
		p = False
		print "ERROR on test case 6: %s"%j.toString()

	#Test case: 2D joint
	j = joint()
	j.jointA = location(0.0,1.0,0.0)	
	j.jointB = location(4.0,1.0,0.0)	
	j.jointC = location(0.5,6.0,-2.0)
	j.spanA = span(4.0)
	j.spanB = span(4.0)
	j.farOrNear = 'n'
	j.computeLocation()
	if(j.x > 2.01 or j.x < 1.99 or j.y > 4.22 or j.y < 4.21 or j.z < -1.29 or j.z > -1.285):
		p = False
		print "ERROR on test case 7: %s"%j.toString()

	#Test case: 3D joint
	j = joint()
	j.jointA = location(1.0,0,0)
	j.jointB = location(0.0,1.0,0.0)
	j.jointC = location(0.0,0.0,1.0)
	j.spanA = span(1.0)
	j.spanB = span(math.sqrt(1+1+1))
	j.spanC = span(1.0)
	j.computeLocation()
	if(j.x > 1.01 or j.x < 0.99 or j.y > 0.01 or j.y < -0.01 or j.z > 1.01 or j.z < 0.99):
		p = False
		print "ERROR on test case 8: %s"%j.toString() 

	#Test case: 3D joint
	j = joint()
	j.jointA = location(0.0,2.0,2.0)
	j.jointB = location(-1.0,1.0,0.0)
	j.jointC = location(4.0,0.0,0.0)
	j.spanA = span(4.0)
	j.spanB = span(3.0)
	j.spanC = span(3.0)
	j.computeLocation()
	if(j.x > 1.198 or j.x < 1.19 or j.y > -1.013 or j.y < -1.014 or j.z > -0.34 or j.z < -0.35):
		p = False
		print "ERROR on test case 9: %s"%j.toString() 

	#Test case: 3D joint
	j = joint()
	j.jointA = location(0,0,0)
	j.jointB = location(1,0,0)
	j.jointC = location(.5,-math.sqrt(3)/2.0,0.0)
	j.spanA = span(1.0)
	j.spanB = span(math.sqrt(2.0))
	j.spanC = span(math.sqrt(2.0))
	j.computeLocation()
	if(j.x > 0.01 or j.x < -0.01 or j.y > 0.01 or j.y < -0.01 or j.z > -0.99 or j.z < -1.01):
                p = False
                print "ERROR on test case 10: %s"%j.toString()	
	return p	
Example #20
0
print("customer email: ", customer_1.get_email())
print("\n")

location_1 = Location("darling harbour", "maroubra")
print("pick up location", location_1.get_pick_up)
print("drop off location", location_q.get_drop_off)

print("the second customer")
customer_2 = Customer("C002", "customer 2", "L222222", "*****@*****.**")
print("customer id: ", customer_2.get_customer())
print("customer name: ", customer_2.get_name())
print("customer licence: ", customer_2.get_licence())
print("customer email: ", customer_2.get_email())
print("\n")

location_2 = location("the start location", "the end location")
print("Pick up location:", location_2.get_pick_up())
print("Drop off location:", location_2.get_drop_off())
print("\n")

car_1 = small_car("reg1", "model1", "carid1")
car_2 = medium_car("reg1", "model1", "carid1")
car_3 = large_car("reg1", "model1", "carid1")
car_4 = premium_car("reg1", "model1", "carid1")

system_1 = rental_system()
booking_1 = booking(1, car_1, cuomer_1, "location 1", 1)
booking_1 = booking(2, car_2, cuomer_1, "location 2", 2)
booking_1 = booking(3, car_3, cuomer_1, "location 3", 3)
booking_1 = booking(4, car_4, cuomer_1, "location 4", 4)