def __init__(self, coords=[],shifting=[], outer_box = [], sc = True): """bbox(coords:[float list, float list], shifting:float list, outer_box:[float list, float list], sc:bool). Creates a box given the coordinates of the lower-left and upper_right vertices. The box is shifted to the position shifting wrt the origin of coordinates system. If sc = False, the shift is wrt the centre of the box. """ mesh_obj.__init__(self) if coords == [] and shifting != []: # only shifting is given tmp0_list = [] tmp1_list = [] for i in range(len(shifting)): tmp0_list.append(0.0) tmp1_list.append(1.0) coords = [tmp0_list, tmp1_list] elif coords != [] and shifting == []: # only coords is given for i in range(len(coords[0])): shifting.append(0.0) elif coords == [] and shifting == []: # default: 2D tmp0_list = [] tmp1_list = [] for i in range(2): tmp0_list.append(0.0) tmp1_list.append(1.0) shifting.append(0.0) coords = [tmp0_list, tmp1_list] else: pass print "box" print coords, shifting if sc: # system coordinates self.obj.append(ocaml.body_shifted_sc(ocaml.body_box(coords[0],coords[1]),shifting)) else: # body coordinates self.obj.append(ocaml.body_shifted_bc(ocaml.body_box(coords[0],coords[1]),shifting)) min_coords = [] # create bounding box max_coords = [] for i in range(len(shifting)): if outer_box == []: min_coords.append(min(coords[0][i]+shifting[i],coords[1][i]+shifting[i])) max_coords.append(max(coords[0][i]+shifting[i],coords[1][i]+shifting[i])) else: min_coords.append(min(coords[0][i]+shifting[i],coords[1][i]+shifting[i], outer_box[0][i], outer_box[1][i])) max_coords.append(max(coords[0][i]+shifting[i],coords[1][i]+shifting[i],outer_box[0][i], outer_box[1][i])) self.bbox = [min_coords, max_coords] # update bounding box print "bbox" print self.bbox print "box.\n"
def shift(self, shift, sc=True ): """shift( shift:float list - shifting vector to add to the current position sc:bool - reference system for shifting (body or system coordinates) ). Function to shift the object of the amount shift along the axes. If sc = False the shift is made wrt the body coordinates, wrt the system coordinates otherwise. """ if sc: self.obj = ocaml.body_shifted_sc(self.obj,shift) else: self.obj = ocaml.body_shifted_bc(self.obj,shift)
def __init__(self,length=[],shifting=[], outer_box = [], sc = True): """ellipsoid(length: float list, shifting: float list, outer_box:[float list, float list], sc:bool). Creates an ellipsoid given the length of the main axes. The ellipsoid is shifted to the position shifting wrt the origin of coordinates system. If sc = False, the shift is wrt the centre of the ellipsoid """ mesh_obj.__init__(self) if length == [] and shifting != []: # only shifting is given for i in range(len(shifting)): length.append(1.0) elif length != [] and shifting == []: # only length is given for i in range(len(length)): shifting.append(0.0) elif length == [] and shifting == []: # default: 2D for i in range(2): length.append(1.0) shifting.append(0.0) else: pass print "ellips" print length , shifting if sc: # system coordinates self.obj.append(ocaml.body_shifted_sc(ocaml.body_ellipsoid(length),shifting)) else: # body coordinates self.obj.append(ocaml.body_shifted_bc(ocaml.body_ellipsoid(length),shifting)) min_coords = [] # create bounding box max_coords = [] for i in range(len(shifting)): if outer_box == []: min_coords.append(-length[i]+shifting[i]) max_coords.append(length[i]+shifting[i]) else: min_coords.append(min(-length[i]+shifting[i], outer_box[0][i], outer_box[1][i])) max_coords.append(max(length[i]+shifting[i],outer_box[0][i], outer_box[1][i])) self.bbox = [min_coords, max_coords] # update bounding box print "bbox" print self.bbox print "ellips.\n"
def shift(self, shifting = [], bc=True): """shift( shifting:float list, bc:bool ). Function to shift the object of the amount shifting along the axes wrt the centre of the body. If bc=False the shift is wrt the origin of coordinates system. """ if shifting == []: # default shift for i in range(len(self.bbox[0])): shifting.append(0.0) new_obj = [] # create new object if bc: for obj in self.obj: new_obj.append( ocaml.body_shifted_bc(obj,shifting)) else: for obj in self.obj: new_obj.append( ocaml.body_shifted_sc(obj,shifting)) self.obj = new_obj # update current object
def __init__(self,coords1=[],rad1=1.0,coords2=[],rad2=0.0,shifting=[], outer_box = [], sc = True): """conical( coords1:float list, rad1:float, coords2: float list, rad2: float, shifting: float list, outer_box:[float list, float list], sc:bool). Creates a conical frustum given the centre of the bottom circumference, its radius, the upper circumference and its radius. The frustum is shifted to the position shifting wrt the origin of coordinates system. If sc = False, the shift is wrt the centre of the ellipsoid """ mesh_obj.__init__(self) if coords1 == [] and shifting != []: # only shifting is given for i in range(len(shifting)): coords1.append(0.0) coords2.append(0.0) coords2[-1] = 1.0 elif coords1 != [] and shifting == []: # only coords is given for i in range(len(coords[0])): shifting.append(0.0) elif coords1 == [] and shifting != []: # default: 2D for i in range(2): coords1.append(0.0) coords2.append(0.0) shifting.append(0.0) coords2[-1] = 1.0 else: pass print "cone" print coords1, coords2, shifting if sc: # system coordinates self.obj.append(ocaml.body_shifted_sc(ocaml.body_frustum(coords1,rad1,coords2,rad2),shifting)) else: # body coordinates self.obj.append(ocaml.body_shifted_bc(ocaml.body_frustum(coords1,rad1,coords2,rad2),shifting)) min_coords = [] # create bounding box max_coords = [] import Numeric c1 = Numeric.array(coords1) c2 = Numeric.array(coords2) max_dim = max(rad1, rad2, Numeric.sqrt(Numeric.add.reduce((c1-c2)*(c1-c2)))) for i in range(len(shifting)): if outer_box == []: min_coords.append(shifting[i]-max_dim/2.) max_coords.append(shifting[i]+max_dim/2.) else: min_coords.append(min(length[i]+shifting[i], outer_box[0][i], outer_box[1][i])) max_coords.append(max(shifting[i]+max_dim/2.,outer_box[0][i], outer_box[1][i])) self.bbox = [min_coords, max_coords] # update bounding box print "bbox" print self.bbox print "cone.\n"