def __str__(self): """ Implement str """ if self.spectrum == None: return Vector3d.__str__(self) + " i: " + str(self.intensity) else: return Vector3d.__str__(self) + " s: " + str(self.spectrum)
def __init__(self, side_str="", device_addr=None, transposition=(0, 1, 2), scaling=(1, 1, 1)): self._accel = Vector3d(transposition, scaling, self._accel_callback) self._gyro = Vector3d(transposition, scaling, self._gyro_callback) # Pre-allocated buffers for reads: allows reads to be done in # interrupt handlers self.buf1 = bytearray(1) self.buf2 = bytearray(2) self.buf3 = bytearray(3) self.buf6 = bytearray(6) # --------------------------------------------------------------------- # # Ensure PSU and device have settled # sleep_ms(200) # # Non-pyb targets may use other than X or Y # if isinstance(side_str, str): # self._mpu_i2c = I2C(side_str) # # Soft or hard I2C instance. See issue #3097 # elif hasattr(side_str, "readfrom"): # self._mpu_i2c = side_str # else: # raise ValueError("Invalid I2C instance") # --------------------------------------------------------------------- self._mpu_i2c = I2C(sda=Pin(21), scl=Pin(22), freq=400000) if device_addr is None: devices = set(self._mpu_i2c.scan()) mpus = devices.intersection(set(self._mpu_addr)) number_of_mpus = len(mpus) if number_of_mpus == 0: raise MPUException("FATAL: No MPUs detected.") elif number_of_mpus == 1: self.mpu_addr = mpus.pop() else: raise ValueError( "FATAL: Two MPUs detected: must specify a device address.") else: if device_addr not in (0, 1): raise ValueError("FATAL: Device address must be 0 or 1.") self.mpu_addr = self._mpu_addr[device_addr] # Test communication by reading chip_id: throws exception on error self.chip_id # Now that we can communicate with chip, set it up. # Wake it up. self.wake() # Enable mag access from main I2C bus. self.passthrough = True # Default to highest sensitivity for accelerometer. self.accel_range = 0 # Default to highest sensitivity for gyroscope. self.gyro_range = 0 # fast filtered response self.accel_filter_range = 0 self.gyro_filter_range = 0
def __init__(self,pos,s_or_i = 1.0): """ Create a 3d source point param pos, Position, the three-D Posistion param spectrum the attched spectrum """ Vector3d.__init__(self,pos) self.spectrum = None # Add null to allow for testing if isinstance(s_or_i,Spectrum): # Add spectrum if given self.spectrum = s_or_i else: self.intensity = float(s_or_i) # else record intensity as a float
def __init__(self,pos = Vector3d(), intensity = 1.0, a = 1.0, b = None, alpha = 0.0): """ Form Psf with parameters param pos the position in 3d param a radius or major axis param b (default None), param alpha angle of ellipse """ Vector3d.__init__(self,pos) self.intensity = 1.0 self.major = a if b == None: self.minor = self.major else: self.minor = b self.alpha = alpha
def exportToRhino(objs): """This function detects the type of outgoing objects and converts them to the appropriate type of Rhinoo object """ if type(objs) in (list, tuple): return [convertToRhino(obj) for obj in objs] else: return convertToRhino(objs) def convertToRhino(obj): return convertAndExport[type(obj)](obj) importAndConvert = { rg.Vector3d: lambda g: Vector3d(g.X, g.Y, g.Z), rg.Point3d: lambda g: Point3d(g.X, g.Y, g.Z), rg.Point: lambda g: importFromRhino(g.Location), rg.Plane: lambda g: Plane3d( importFromRhino(g.Origin), importFromRhino(g.Normal)), rg.Line: lambda g: Line3d( importFromRhino(g.Direction), importFromRhino(g.From)), } convertAndExport = { Vector3d: lambda g: rg.Vector3d(*g.asList()), Point3d: lambda g: rg.Point3d(*g.asList()), Plane3d: lambda g: rg.Plane( convertToRhino(g.point),
# Copyright (c) 2020 Kapitonov Stanislav <*****@*****.**> from vector import Vector2d, Vector3d v1 = Vector3d(3, -1, 2) v2 = Vector3d(-1, 2, 1) v3 = Vector3d(0, -2, 1) v4 = Vector3d(-1, 1, 3) dif = v3 - v4 # Find projection of vector v3 - v4 for vector v2 pr = dif.project(v2) print('Projection of vector v3 - v4 for vector v2: ' + pr) # Find space of triangle with sides v1 and v2 s = v1 * v2 / 2 print('Space of triangle with sides v1 and v2: ' + s) # Mixed production of v1, v2 and dif mp = v1 * v2 * dif print('Mixed production of v1, v2 and dif: ' + mp)
""" c_ob = None c_dis = 999999999999999999999 for (key , ob) in self.object.items(): distance = self.object[key].inter(ray) # all distance is Nome if distance != None: if c_dis > distance: c_dis,c_ob = distance,ob return (c_ob,c_dis) #Test print("fooo") camera = Camera(Vector3d(0,0,0),Vector3d(1,0,0),Vector3d(0,1,0),500,500,0.01) sphere = Sphere(Vector3d(10,0,0),7,1,(79,232,210)) light = Light(Vector3d(-10,0,-200)) ray = Ray(Vector3d(0,0,0),Vector3d(*[1.0, 0.84, -0.6])) print("The intial ray is from {0}".format(ray)) print(f"{camera.pixelToWord(0,0)}") print(f"{camera.pixelToWord(0,99)}") print(f"{camera.pixelToWord(99,0)}") print(f"{camera.pixelToWord(99,99)}") scene = Scene("test",0.5) scene.addObject("s1",sphere) scene.addCamera("c1",camera) scene.addLight("L1" ,light)