def subtractVector(): components1 = [] components2 = [] try: for component in vector1: components1.append(float(component.get())) for component in vector2: components2.append(float(component.get())) except ValueError: pass v1 = Vector.from_list(components1) v2 = Vector.from_list(components2) solution = v1.sum(v2.multiply(-1)) answer.set(solution)
def crossProduct(): components1 = [] components2 = [] try: for component in vector1: components1.append(float(component.get())) for component in vector2: components2.append(float(component.get())) except ValueError: pass v1 = Vector.from_list(components1) v2 = Vector.from_list(components2) solution = v1.cross(v2) answer.set(solution)
def dotProduct(): components1 = [] components2 = [] try: for component in vector1: components1.append(float(component.get())) for component in vector2: components2.append(float(component.get())) except ValueError: pass v1 = Vector.from_list(components1) v2 = Vector.from_list(components2) sum = v1.dot(v2) answer.set(sum)
def test_vector_status_report(): ship = Ship(port_panel=ShipPanel(side=PORT, thrusters=[Thruster(max_force=15)]), reactors=[Reactor(max_output=100)]) report_vector = Vector.from_list(ship.status_report["vector"].values()) assert report_vector == ship.current_vector, \ "Thruster vector is innacurately reported"
def can_detect(self, body): target_distance = get_distance(body.position, self.position) # Exit early if totally out of range if target_distance > self.range: return False # TODO(Austin) - Fix this on the actual library # TODO(Austin) - Figure out what the hell the above comment means... # I think it has something to do with the wonky way I'm initializing # this vector x = Vector.from_list((self.position - body.position).to_list()) dist_along_axis = x.dot(self.unit_vector) if 0 <= dist_along_axis <= min(target_distance, self.range): cone_radius = self.get_sensor_radius_at_point( self.unit_vector.multiply(dist_along_axis)) orth_distance = ( x - self.unit_vector.multiply(dist_along_axis)).magnitude() return orth_distance < cone_radius return False
def apply_acceleration_to_vector(self, vector, acceleration): return Vector.from_list([x * self.current_acceleration for x in vector])