def ellipsoid(a, b, c, step=0.5, object_color=None): if object_color is None: object_color = gs.Color(0.0, 0.2, 0.5) else: pass u_step = step v_step = step ellipsoid = gs.GraphicalObject() ellipsoid.set_name("ellipsoid") u_top = 2 * math.pi u_down = 0 v_top = math.pi v_down = 0 #coordinates: x = a cos(u) sen(v) y = b sen(u) sen(v) z = c cos(v)) first_edge = [] v = v_down for u in quat.frange(u_down, u_top, u_step): x_value = a * math.cos(u) * math.sin(v) y_value = b * math.sin(u) * math.sin(v) first_edge.append(gs.Point(x_value, y_value, c)) carry_ref = first_edge[0] for ref_point in first_edge: ellipsoid.push_edge(carry_ref, ref_point, object_color) carry_ref = ref_point last_edge = [] last_edge = first_edge for v in quat.frange(v_down, v_top, v_step): carry_edge = [] z_value = c * math.cos(v) for u in quat.frange(u_down, u_top, u_step): x_value = a * math.cos(u) * math.sin(v) y_value = b * math.sin(u) * math.sin(v) carry_edge.append(gs.Point(x_value, y_value, z_value)) ##SE EMPIEZA A GENERAR LOS BORDES carry_ref = carry_edge[0] index = 0 for ref_point in carry_edge: ##Generan Bordes Respecto a XY ellipsoid.push_edge(carry_ref, ref_point, object_color) ##Generan Bordes respecto a Z ellipsoid.push_edge(carry_ref, last_edge[index], object_color) carry_ref = ref_point index += 1 last_edge = carry_edge return ellipsoid
def parabolic_cylinder(a, dom, step=0.5, object_color=None): if object_color is None: object_color = gs.Color(0.0, 0.2, 0.5) else: pass u_step = step v_step = step parabolic_cylinder = gs.GraphicalObject() parabolic_cylinder.set_name("parabolic_cylinder") u_top = dom u_down = -dom v_top = dom v_down = -dom #cilindro parabolico T(u, v) = (u, a u², v) first_edge = [] v = v_down o = v for u in quat.frange(u_down, u_top, u_step): x_value = u y_value = a * u**2 first_edge.append(gs.Point(x_value, y_value, o)) carry_ref = first_edge[0] for ref_point in first_edge: parabolic_cylinder.push_edge(carry_ref, ref_point, object_color) carry_ref = ref_point last_edge = [] last_edge = first_edge for v in quat.frange(v_down, v_top, v_step): carry_edge = [] z_value = v for u in quat.frange(u_down, u_top, u_step): x_value = u y_value = a * u**2 carry_edge.append(gs.Point(x_value, y_value, z_value)) ##SE EMPIEZA A GENERAR LOS BORDES carry_ref = carry_edge[0] index = 0 for ref_point in carry_edge: ##Generan Bordes Respecto a XY parabolic_cylinder.push_edge(carry_ref, ref_point, object_color) ##Generan Bordes respecto a Z parabolic_cylinder.push_edge(carry_ref, last_edge[index], object_color) carry_ref = ref_point index += 1 last_edge = carry_edge return parabolic_cylinder
def hiperboloid_1h(a, b, c, dom, step=0.5, object_color=None): if object_color is None: object_color = gs.Color(0.0, 0.2, 0.5) else: pass u_step = step v_step = step hiperboloid_1h = gs.GraphicalObject() hiperboloid_1h.set_name("hiperboloid") u_top = 2 * math.pi u_down = 0 v_top = dom v_down = -1 * dom #hiperboloide de una hojas x = a cos(u) cosh(v) y = b sen(u) cosh(v) z = c senh(v)) u = 0,2pi , v = R first_edge = [] v = v_down o = c * math.sinh(v) for u in quat.frange(u_down, u_top, u_step): x_value = a * math.cos(u) * math.cosh(v) y_value = b * math.sin(u) * math.cosh(v) first_edge.append(gs.Point(x_value, y_value, o)) carry_ref = first_edge[0] for ref_point in first_edge: hiperboloid_1h.push_edge(carry_ref, ref_point, object_color) carry_ref = ref_point last_edge = [] last_edge = first_edge for v in quat.frange(v_down, v_top, v_step): carry_edge = [] z_value = c * math.sinh(v) for u in quat.frange(u_down, u_top, u_step): x_value = a * math.cos(u) * math.cosh(v) y_value = b * math.sin(u) * math.cosh(v) carry_edge.append(gs.Point(x_value, y_value, z_value)) ##SE EMPIEZA A GENERAR LOS BORDES carry_ref = carry_edge[0] index = 0 for ref_point in carry_edge: ##Generan Bordes Respecto a XY hiperboloid_1h.push_edge(carry_ref, ref_point, object_color) ##Generan Bordes respecto a Z hiperboloid_1h.push_edge(carry_ref, last_edge[index], object_color) carry_ref = ref_point index += 1 last_edge = carry_edge return hiperboloid_1h
def hyperbolic_cylinder(a, b, dom, step=0.5, object_color=None): if object_color is None: object_color = gs.Color(0.0, 0.2, 0.5) else: pass u_step = step v_step = step hyperbolic_cylinder = gs.GraphicalObject() hyperbolic_cylinder.set_name("hyperbolic_cylinder") u_top = 2 * math.pi u_down = 0 v_top = dom v_down = -dom #cilindro hiperbolico (a sec(u), b tg(u), v) first_edge = [] v = v_down o = v for u in quat.frange(u_down, u_top, u_step): x_value = a * (1 / math.cos(u)) y_value = b * math.tan(u) first_edge.append(gs.Point(x_value, y_value, o)) carry_ref = first_edge[0] for ref_point in first_edge: hyperbolic_cylinder.push_edge(carry_ref, ref_point, object_color) carry_ref = ref_point last_edge = [] last_edge = first_edge for v in quat.frange(v_down, v_top, v_step): carry_edge = [] z_value = v for u in quat.frange(u_down, u_top, u_step): x_value = a * (1 / math.cos(u)) y_value = b * math.tan(u) carry_edge.append(gs.Point(x_value, y_value, z_value)) ##SE EMPIEZA A GENERAR LOS BORDES carry_ref = carry_edge[0] index = 0 for ref_point in carry_edge: ##Generan Bordes Respecto a XY hyperbolic_cylinder.push_edge(carry_ref, ref_point, object_color) ##Generan Bordes respecto a Z hyperbolic_cylinder.push_edge(carry_ref, last_edge[index], object_color) carry_ref = ref_point index += 1 last_edge = carry_edge return hyperbolic_cylinder
def hyperbolic_parabolid(a, b, c, dom, step=0.5, object_color=None): if object_color is None: object_color = gs.Color(0.0, 0.2, 0.5) else: pass u_step = step v_step = step hyperbolic_parabolid = gs.GraphicalObject() hyperbolic_parabolid.set_name("hyperbolic_parabolid") u_top = dom u_down = -1 * dom v_top = dom v_down = -1 * dom #paraboloide hiperbolico x = a (u+v) y = b (u− v) z = 4c uv), con D = R² #a u, b v, c(u² − v²) first_edge = [] v = v_down for u in quat.frange(u_down, u_top, u_step): x_value = a * u y_value = b * v z_value = c * (u**2 - v**2) first_edge.append(gs.Point(x_value, y_value, z_value)) carry_ref = first_edge[0] for ref_point in first_edge: hyperbolic_parabolid.push_edge(carry_ref, ref_point, object_color) carry_ref = ref_point last_edge = [] last_edge = first_edge for v in quat.frange(v_down, v_top, v_step): carry_edge = [] for u in quat.frange(u_down, u_top, u_step): x_value = a * u y_value = b * v z_value = c * (u**2 - v**2) carry_edge.append(gs.Point(x_value, y_value, z_value)) ##SE EMPIEZA A GENERAR LOS BORDES carry_ref = carry_edge[0] index = 0 for ref_point in carry_edge: ##Generan Bordes Respecto a XY hyperbolic_parabolid.push_edge(carry_ref, ref_point, object_color) ##Generan Bordes respecto a Z hyperbolic_parabolid.push_edge(carry_ref, last_edge[index], object_color) carry_ref = ref_point index += 1 last_edge = carry_edge return hyperbolic_parabolid
def create_refs_vertex(self): down_carry_list = [] for j in qd.frange(self.ref_vertex[1], self.ref_vertex[1] + self.length * 4, self.length): for k in qd.frange(self.ref_vertex[2], self.ref_vertex[2] + self.length * 4, self.length): for i in qd.frange(self.ref_vertex[0], self.ref_vertex[0] + self.length * 4, self.length): carry = gs.Point(i, j, k) self.list_of_points.append(carry) self.cube.push_point(carry) down_carry_list.append(carry) front_carry_list = [] for k in qd.frange(self.ref_vertex[2], self.ref_vertex[2] + self.length * 4, self.length): for i in qd.frange(self.ref_vertex[0], self.ref_vertex[0] + self.length * 4, self.length): for j in qd.frange(self.ref_vertex[1], self.ref_vertex[1] + self.length * 4, self.length): carry = gs.Point(i, j, k) self.list_of_points.append(carry) self.cube.push_point(carry) front_carry_list.append(carry) right_carry_list = [] for i in qd.frange(self.ref_vertex[0], self.ref_vertex[0] + self.length * 4, self.length): for j in qd.frange(self.ref_vertex[1], self.ref_vertex[1] + self.length * 4, self.length): for k in qd.frange(self.ref_vertex[2], self.ref_vertex[2] + self.length * 4, self.length): carry = gs.Point(i, j, k) self.list_of_points.append(carry) self.cube.push_point(carry) right_carry_list.append(carry) ################################### index = 0 color_counter = 0 color = self.blue suspend_flag = False while index < len(front_carry_list): if index % 16 == 0: if color_counter == 0: color = self.blue elif color_counter == 3: color = self.green else: color = self.black color_counter += 1 suspend_flag = False if (index - 11) % 16 == 0 and index != 0: suspend_flag = True if (index - 3) % 4 == 0 or suspend_flag: pass else: self.list_of_sub_faces.append([front_carry_list[index], front_carry_list[index + 1], front_carry_list[index + 5], front_carry_list[index + 4], color]) index += 1 index = 0 color_counter = 0 color = self.orange suspend_flag = False while index < len(right_carry_list): if index % 16 == 0: if color_counter == 0: color = self.orange elif color_counter == 3: color = self.red else: color = self.black color_counter += 1 suspend_flag = False if (index - 11) % 16 == 0 and index != 0: suspend_flag = True if (index - 3)%4 == 0 or suspend_flag: pass else: self.list_of_sub_faces.append([right_carry_list[index], right_carry_list[index + 1], right_carry_list[index + 5], right_carry_list[index + 4], color]) index += 1 index = 0 color_counter = 0 color = self.yellow suspend_flag = False while index < len(down_carry_list): if index % 16 == 0: if color_counter == 0: color = self.yellow elif color_counter == 3: color = self.white else: color = self.black color_counter += 1 suspend_flag = False if (index - 11) % 16 == 0 and index != 0: suspend_flag = True if (index - 3)%4 == 0 or suspend_flag: pass else: self.list_of_sub_faces.append([down_carry_list[index], down_carry_list[index + 1], down_carry_list[index + 5], down_carry_list[index + 4], color]) index += 1 ################################### id = 0 for m in self.list_of_sub_faces: print(id, "\t", m[0].get_coord(), m[1].get_coord(), m[2].get_coord(), m[3].get_coord()) id += 1
def control(list_of_objects): os.system("clear") print("LISTA DE OBJETOS DIBUJADOS\n\n") index = 0 for graph_object in list_of_objects: print(graph_object.get_color_name(), " \t Indice[", index, "]\n") index += 1 index = input("Opcion >>>:\t") try: index = int(index) if index >= len(list_of_objects): return None else: pass except: return None who_object = list_of_objects[index] option = input(""" [1]Rotar - Sobre si mismo [2]Rotar - Respecto a un Vector [3]Escalar [4]Trasladar """) try: option = int(option) except: return None if option == 1: option = input(""" [1]X [2]Y [3]Z """) try: option = int(option) except: return None who_object.update_center() ref_center = copy.copy(who_object.get_center()) angle = input("Angulo >>>:\t") try: angle = float(angle) except: return None if option == 1: who_object.translate() who_object.rotate(angle, "x", True) who_object.translate(ref_center) elif option == 2: who_object.translate() who_object.rotate(angle, "y", True) who_object.translate(ref_center) elif option == 3: who_object.translate() who_object.rotate(angle, "z", True) who_object.translate(ref_center) else: return None elif option == 2: option = input(""" [1]X [2]Y [3]Z [4]Otro """) try: option = int(option) except: return None angle = input("Angulo >>>:\t") try: angle = float(angle) except: return None if option == 1: who_object.rotate(angle, "x", True) elif option == 2: who_object.rotate(angle, "y", True) elif option == 3: who_object.rotate(angle, "z", True) elif option == 4: vector = eval(input("Vector >>>:\t")) try: vector[0] except: return None who_object.rotate(angle, vector) else: return None elif option == 3: escala = eval(input("Escala >>>:\t")) try: escala = list(escala) except: return None who_object.scale(None, escala) elif option == 4: to_point = eval(input("Punto >>>:\t")) try: to_point == list(to_point) except: return None who_object.translate(gs.Point(to_point[0], to_point[1], to_point[2])) else: return None
print("Angulo respecto a X - Rad: \t", p1.angle_x() , " - Angulo respecto a Z - Seg", to_seg(p1.angle_z()), "Norma:\t", p1.norm()) v1 = edge(Point(0,0,0), Point(5,5,5)) print ("Angulo respecto a X: \t", v1.angle_x(), " - Angulo respecto a Z - Seg", to_seg(v1.angle_z()), "Norma:\t", v1.norm()) """ ref_value = 4.3 blanco = gs.Color(1.0, 1.0, 1.0) rojo = gs.Color(1.0, 0.0, 0.0) verde = gs.Color(0.0, 1.0, 0.0) azul = gs.Color(0.0, 0.0, 1.0) p1 = gs.Point(ref_value, ref_value, ref_value) p2 = gs.Point(0.0, 0.0, 0.0) p3 = gs.Point(0.0, ref_value, 0.0) p4 = gs.Point(0.0, ref_value, ref_value) tetaedro = gs.GraphicalObject() tetaedro.set_name("tetraedro") tetaedro.push_edge(p1, p2, rojo) tetaedro.push_edge(p1, p3, rojo) tetaedro.push_edge(p1, p4, rojo) tetaedro.push_edge(p2, p3, azul) tetaedro.push_edge(p2, p4, azul) tetaedro.push_edge(p3, p4, azul) tetaedro.show_points()