Skip to content

Instantly share code, notes, and snippets.

@ad-1
ad-1 / animate.py
Created June 24, 2024 18:47
Elliptical Anomalies
df = pd.DataFrame({
'Position (m)': r,
'Position (X)': rx,
'Position (Y)': ry,
'True Anomaly (rad)': theta,
'True Anomaly (deg)': rad2deg(theta),
'Eccentric Anomaly (rad)': E,
'Eccentric Anomaly (deg)': rad2deg(E),
'Eccentric Anomaly (X)': eccentric_anomaly_x,
'Eccentric Anomaly (Y)': eccentric_anomaly_y,
@ad-1
ad-1 / create_arrow_patches.py
Last active April 13, 2023 20:56
Code accompanying a concise article exploring how to drag a 2D vector around a figure while users receive real-time updates through dynamically updating data.
# define 2D vector coordinates
vector_coord_1 = np.random.rand(2)
vector_coord_2 = np.random.rand(2)
# plotting
fig, ax = plt.subplots()
vector_1 = ax.add_patch(mpatches.FancyArrowPatch((0, 0), vector_coord_1, mutation_scale=15))
vector_2 = ax.add_patch(mpatches.FancyArrowPatch((0, 0), vector_coord_2, mutation_scale=15))
@ad-1
ad-1 / fixed_point_iteration.py
Created November 8, 2022 15:12
Fixed Point Iteration - Numerical Analysis
"""
Method of computing fixed points of iterated functions.
x = g(x0) => fixed points (input = output)
"""
def fixed_point_iteration(p0, tol, n):
"""
fixed point iteration algorithm for root finding
param p0: initial guess for root
@ad-1
ad-1 / bfs.py
Last active April 13, 2023 20:56
Graph Traversal and Pathfinding Algorithm Visualisation in Python: https://medium.com/p/99595c414293
from get_adjacent_nodes import get_adj_list
from progress_state import progress_state
from state import State
class BFS:
def __init__(self, nodes, recursive, start_node, finish_node, root, animate=False):
""" initialise bredth first search solver """
self.subscriber = root
@ad-1
ad-1 / bubble_sort.py
Last active April 13, 2023 20:56
Sorting algorithm visualisation
def bubble_sort(self, unsorted, n):
""" bubble sort algorithm """
# iterate over unsorted array up until second last element
for i in range(0, n - 1):
# swapped conditions monitors for finalised list
swapped = False
# iterate over remaining unsorted items
@ad-1
ad-1 / simple_sphere.py
Created June 6, 2022 18:39
PyVista Simple Sphere
import pyvista
sphere = pyvista.Sphere()
sphere.plot(show_edges=True)
@ad-1
ad-1 / augmented_matrix.py
Last active April 13, 2023 20:56
Find the Inverse of a Matrix using Python
# form the augmented matrix by concatenating A and I
M = np.concatenate((M, I), axis=1)
@ad-1
ad-1 / orthogonal.py
Last active April 13, 2023 20:56
Fundamentals of Matrix Algebra | Part 2
# define array
A = np.array([[1, 0], [0, 1]])
# True if orthogonal
assert (A.T == np.linalg.inv(A)).all()
@ad-1
ad-1 / animate.py
Last active April 13, 2023 20:56
How to animate plots in Python using Matplotlib.
def animate(i):
# update axis view angle
ax.view_init(vertical_rotation_angles[i], horizontal_rotation_angles[i])
# update trajectory for current time step with x, y data
trajectory.set_data(state_history[:i, 0], state_history[:i, 1])\
# update z-dimension data
trajectory.set_3d_properties(state_history[:i, 2])
@ad-1
ad-1 / lorenz_data.py
Last active April 13, 2023 20:56
Lorenz ODE Simulation Data
-7.000000 8.000000 26.000000
-5.583929 7.759362 24.827488
-4.326611 7.501421 23.801976
-3.213183 7.253440 22.902061
-2.228067 7.033525 22.108406
-1.355780 6.853185 21.404540
-0.581457 6.719310 20.777010
0.108848 6.635641 20.215196
0.728002 6.603831 19.710990
1.287734 6.624192 19.258431