def update(i): # Transforming frame1 cubesat.rotate(angle_step, 0, 0, cor=cubesat.make_cuboid_centroid()) projection_frame = Frame() for face in cubesat.faces: face.project(new_frame=projection_frame, plane='xz') print("[DEBUG] Plotting frame {}".format(i)) # Setting up the axes object ax.clear() ax.set_title("Wireframe visualization. Frame: {}".format(str(i))) plotscale = 1 ax.set_xlim(0, 1.25 * plotscale) ax.set_ylim(0, 1.25 * plotscale) ax.set_zlim(0, plotscale) # ax.set_xlim(-1, 1) # ax.set_ylim(-1, 1) # ax.set_zlim(-1, 1) ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') # Plotting the global XYZ tripod plot_global_tripod(ax, scaling=plotscale / 2) # Plot tripod of frame1: plot_frame(ax, frame1, tripod_scale=plotscale / 8, facefill=False) plot_frame(ax, projection_frame, tripod_scale=plotscale / 8, facefill=False, linecolour="#AA2")
from cp_utilities import d2r #, r2d from cp_plotting import plot_global_tripod, plot_frame # Toggle plotting functionality: if True: # Setting up the plot: fig = plt.figure(figsize=(10, 7)) ax = mp3d.Axes3D(fig) """ TO CHANGE THE DEFAULT CAMERA VIEW, CHANGE THESE: """ ax.view_init(elev=20, azim=-60) steps = 128 angle_step = d2r(360 / steps) frame1 = Frame() projection_frame = Frame() p1 = Vertex(-0.05, -0.05, -0.1, frame1) p2 = Vertex(-0.05, -0.05, 0.1, frame1) p3 = Vertex(0.05, -0.05, 0.1, frame1) p4 = Vertex(0.05, -0.05, -0.1, frame1) p5 = Vertex(-0.05, 0.05, -0.1, frame1) p6 = Vertex(-0.05, 0.05, 0.1, frame1) p7 = Vertex(0.05, 0.05, 0.1, frame1) p8 = Vertex(0.05, 0.05, -0.1, frame1) fA = Face(p4, p3, p2, p1, frame1) fB = Face(p2, p3, p7, p6, frame1) fC = Face(p3, p4, p8, p7, frame1)
from cp_utilities import d2r #, r2d from cp_plotting import plot_global_tripod, plot_frame # Toggle plotting functionality: if True: # Setting up the plot: fig = plt.figure(figsize=(10, 7)) ax = mp3d.Axes3D(fig) """ TO CHANGE THE DEFAULT CAMERA VIEW, CHANGE THESE: """ ax.view_init(elev=20, azim=-60) steps = 40 angle_step = d2r(360 / steps) frame1 = Frame() frame1.translate(0.5, 0.5, 0.5) frame1.rotate(0, 0, d2r(1 * 360 / 12)) p1 = Vertex(-0.05, -0.05, -0.1, frame1) p2 = Vertex(-0.05, -0.05, 0.1, frame1) p3 = Vertex(0.05, -0.05, 0.1, frame1) p4 = Vertex(0.05, -0.05, -0.1, frame1) p5 = Vertex(-0.05, 0.05, -0.1, frame1) p6 = Vertex(-0.05, 0.05, 0.1, frame1) p7 = Vertex(0.05, 0.05, 0.1, frame1) p8 = Vertex(0.05, 0.05, -0.1, frame1) fA = Face(p4, p3, p2, p1, frame1) fB = Face(p2, p3, p7, p6, frame1) fC = Face(p3, p4, p8, p7, frame1)
p4 = Vertex([0.05, -0.05, -0.1]) p5 = Vertex([-0.05, 0.05, -0.1]) p6 = Vertex([-0.05, 0.05, 0.1]) p7 = Vertex([0.05, 0.05, 0.1]) p8 = Vertex([0.05, 0.05, -0.1]) fA = Face(p4, p3, p2, p1) fB = Face(p2, p3, p7, p6) fC = Face(p3, p4, p8, p7) fD = Face(p4, p1, p5, p8) fE = Face(p1, p2, p6, p5) fF = Face(p5, p6, p7, p8) cubesat = Geometry([fA, fB, fC, fD, fE, fF]) frame1 = Frame() frame1.add_geometry(cubesat) frame1.translate(0.5, 0.5, 0.5) frame1.rotate(0, 0, d2r(1 * 360 / 12)) # cubesat.rotate(d2r(-45),0,0,cor=list(cubesat.find_cuboid_centroid())) # f1 = Face(Vertex(0,0,0), Vertex(1,0,0), Vertex(1,1,0), Vertex(0,1,0)) # f2 = Face(Vertex(0,0,0), Vertex(1,0,0), Vertex(1,1,0), Vertex(0,1,0)) # f3 = Face(Vertex(0,0,0), Vertex(1,0,0), Vertex(1,1,0), Vertex(0,1,0)) # f4 = Face(Vertex(0,0,0), Vertex(1,0,0), Vertex(1,1,0), Vertex(0,1,0)) # f5 = Face(Vertex(0,0,0), Vertex(1,0,0), Vertex(1,1,0), Vertex(0,1,0)) # f6 = Face(Vertex(0,0,0), Vertex(1,0,0), Vertex(1,1,0), Vertex(0,1,0)) # f = Face(Vertex([0,0,0]),Vertex([1,0,0]),Vertex([1,1,0]),Vertex([0,1,0]))
p4 = Vertex([0.05, -0.05, -0.1]) p5 = Vertex([-0.05, 0.05, -0.1]) p6 = Vertex([-0.05, 0.05, 0.1]) p7 = Vertex([0.05, 0.05, 0.1]) p8 = Vertex([0.05, 0.05, -0.1]) fA = Face(p4, p3, p2, p1) fB = Face(p2, p3, p7, p6) fC = Face(p3, p4, p8, p7) fD = Face(p4, p1, p5, p8) fE = Face(p1, p2, p6, p5) fF = Face(p5, p6, p7, p8) cubesat = Geometry([fA, fB, fC, fD, fE, fF]) frame1 = Frame() frame1.add_geometry(cubesat) frame1.translate(0.5, 0.5, 0.5) frame1.rotate(0, 0, d2r(1 * 360 / 12)) cubesat.rotate(d2r(-45), 0, 0, cor=list(cubesat.find_cuboid_centroid())) f = Face(Vertex([0, 0, 0]), Vertex([1, 0, 0]), Vertex([1, 1, 0]), Vertex([0, 1, 0])) for face in frame1.illuminated_faces(cubesat, 'xz'): print(frame1.illuminated_strength(face, 'xz')) #%% ==== Plotting ==== # Toggle plotting functionality:
from cp_utilities import d2r #, r2d from cp_plotting import plot_global_tripod, plot_frame # Toggle plotting functionality: if True: # Setting up the plot: fig = plt.figure(figsize=(10, 7)) ax = mp3d.Axes3D(fig) """ TO CHANGE THE DEFAULT CAMERA VIEW, CHANGE THESE: """ ax.view_init(elev=20, azim=-60) steps = 40 angle_step = d2r(360 / steps) frame1 = Frame() vertex1 = Vertex(0.5, 0, 0, parent=frame1) vertex2 = Vertex(0.5, 0.5, 0, parent=frame1) def update(i): # Transforming frame1 frame1.translate(2 / steps, 2 / steps, 2 / steps) # frame1.rotate(0,0,-2*np.pi/(steps)) # Local transformation of vertex1 - rotate around vertex2 vertex1.rotate(2 * np.pi / steps, 0, 0, cor=vertex2) # Setting up the axes object ax.clear()
fB = Face(p2, p3, p7, p6) # |\ B_\ fC = Face(p3, p4, p8, p7) # A | | | F Y fD = Face(p4, p1, p5, p8) # | | C| --------> fE = Face(p1, p2, p6, p5) # \|__| fF = Face(p5, p6, p7, p8) # D # \ # v X # Assembling a Geometry instance named 'cubesat', and add all the faces # we just defined to the geometry. cubesat = Geometry([fA, fB, fC, fD, fE, fF]) # Define a reference frame which will be attached to the centre of gravity # of the CubeSat. If you move/rotate this frame, the 'cubesat' # Geometry will move/rotate along with it (if it is attached of course). frame1 = Frame() # Attaching the cubesat Geometry to 'frame1' frame1.add_geometry(cubesat) # Translate 'frame1' away from the origin. The sole reasons for doing this # is so the geometry will not overlap with the yellow projection of the # illuminated area, and because the plot will generally look nicer. frame1.translate(0.3, 0.3, 0.25) """ == HERE WE START CHANGING THE INITIAL ATTITUDE OF THE SATELLITE == """ # Change the LTAN by 1.5 hours frame1.rotate(0, 0, d2r(1.5/24*360)) """EXAMPLE: Nadir pointing with +Z""" # The way we've set it up, at the start of the simulation, the satellite
import matplotlib.pyplot as plt import matplotlib.animation as animation import mpl_toolkits.mplot3d as mp3d from cp_vertex import Vertex from cp_face import Face from cp_geometry import Geometry from cp_vector import Vector from cp_frame import Frame from cp_utilities import d2r #, r2d from cp_plotting import plot_global_tripod, plot_frame, \ plot_vertex, plot_face #%% ==== Manipulate objects ==== frame1 = Frame() frame1.translate(1, 1, 1) frame2 = Frame() # p1 = Vertex(0,0,0,frame1) # p2 = Vertex(1,0,0) # p3 = Vertex(1,1,0) # p4 = Vertex(0,1,0) # p5 = Vertex(0,1,1) # p6 = Vertex(0,0,1) # f1 = Face(p1, p2, p3, p4, frame1) # f2 = Face(p1, p4, p5, p6, frame1) frame1.readout()
def plot_frame( axes: plt.matplotlib.axes, frame: Frame, # Tripod properties show_tripod=True, # If False, does not plot the tripod tripod_scale=1, # Sets the scale of the tripod plot_perpendiculars=True, # Plot perpendiculars # Vertex plotting properties: vertexfill=True, # If False, vertex will not be plotted vertexcolour="#000", # Specifies the vertex colour vertexsize=10, # Size of the plotted vertex vertexalpha=1, # Opacity of the plotted vertex # Face plotting properties: linefill=True, # If False, does not plot face lines linecolour="#000", # Colour of face lines linewidth=2, # Thickness of face lines linealpha=1, # Opacity of face lines facefill=True, # If False, does not shade the face area facecolour="#555", # Colour of the face area shading facealpha=1, # Opacity of the face area shading # Face perpendicular arrow plotting properties: perpfill=False, # If True, plot perpendiculars perpcolour="#888", # Specifies the perp. arrow colour perpscale=1, # Size of the plotted perp. arrow perpalpha=0.5, # Opacity of the plotted perp. arrow # Illumination: illumination=False, # If True, plots illumination intensity ill_value=0, # Used to plot illumination intensity ill_plane=None, # If illumination is used, a plane # MUST be satisfied. # Vector plotting properties: vectorfill=True, # If False, does not plot vector arrow vectorcolour="#000", # Colour of vector arrow vectoralpha=1, # Opacity of vector arrow vectorscale=1, # Scale the whole vector by a constant vectorratio=0.15 # Vector arrow length ratio ): if frame.geometries: """If frame contains geometries, plot these. Then find out if there are any leftover edges and vertices associated with the frame, plot these too. """ for geometry in frame.geometries: # Plot unique vertices first: for vertex in geometry.vertices(): plot_vertex(axes, vertex, frame.vertex_xyz_global(vertex), vertexfill=vertexfill, vertexcolour=vertexcolour, vertexsize=vertexsize, vertexalpha=vertexalpha) # Then plot faces, without plotting the vertices for face in geometry.faces: if illumination: if not ill_plane: raise AssertionError("If illumination is plotted, an \ illumination plane MUST be \ specified, e.g. \ (ill_plane = 'xy')") else: if face not in frame.illuminated_faces( geometry, plane=ill_plane): ill_value = 0 else: ill_value = frame.illuminated_strength( face, plane=ill_plane) plot_face(axes, face, frame.plotlist(face), linefill=linefill, linecolour=linecolour, linewidth=linewidth, linealpha=linealpha, facefill=facefill, facecolour=facecolour, facealpha=facealpha, vertexfill=False, vertexcolour=vertexcolour, vertexsize=vertexsize, vertexalpha=vertexalpha, illumination=illumination, ill_value=ill_value) if perpfill: # First plot centroids of each plane: plot_geometry_perpendiculars(axes, \ frame.perpendiculars_plotlist(geometry, perpscale), colour = perpcolour, alpha = perpalpha) if show_tripod: plot_frame_tripod(axes, frame, scaling=tripod_scale)
def plot_illumination( axes: plt.matplotlib.axes, frame: Frame, plane='xy', geometry: Geometry = None, # Tripod properties show_tripod=False, # If False, does not plot the tripod tripod_scale=1, # Sets the scale of the tripod plot_perpendiculars=False, # Plot perpendiculars # Vertex plotting properties: vertexfill=False, # If False, vertex will not be plotted vertexcolour="FFC125", # Specifies the vertex colour vertexsize=10, # Size of the plotted vertex vertexalpha=1, # Opacity of the plotted vertex # Face plotting properties: linefill=True, # If False, does not plot face lines linecolour="#FFC125", # Colour of face lines linewidth=2, # Thickness of face lines linealpha=1, # Opacity of face lines facefill=False, # If False, does not shade the face area facecolour="FFC125", # Colour of the face area shading facealpha=1, # Opacity of the face area shading # Face perpendicular arrow plotting properties: perpfill=False, # If True, plot perpendiculars perpcolour="#888", # Specifies the perp. arrow colour perpscale=1, # Size of the plotted perp. arrow perpalpha=0.5, # Opacity of the plotted perp. arrow # Illumination: illumination=False, # If True, plots illumination intensity ill_value=0, # Used to plot illumination intensity # Vector plotting properties: vectorfill=False, # If False, does not plot vector arrow vectorcolour="#000", # Colour of vector arrow vectoralpha=1, # Opacity of vector arrow vectorscale=1, # Scale the whole vector by a constant vectorratio=0.15 # Vector arrow length ratio ): # Gather the faces to be plotted in the geometry. If no geometry was # provided (geometry=None), plot all the illuminated faces in the frame. if not geometry: geometries = frame.geometries else: geometries = list(geometry) illuminated_faces = [] # Find out what faces are illuminated: for geo in geometries: faces = frame.illuminated_faces(geo, plane=plane) illuminated_faces.extend(faces) # Plot each face after projecting them in the global frame: for face in illuminated_faces: # projected_face = frame.project_face(face) plot_face(axes, frame.project_face(face, plane=plane), linefill=linefill, linecolour=linecolour, linewidth=linewidth, linealpha=linealpha, facefill=facefill, facecolour=facecolour, facealpha=facealpha, vertexfill=vertexfill, vertexcolour=vertexcolour, vertexsize=vertexsize, vertexalpha=vertexalpha, illumination=False)