Skip to content

Instantly share code, notes, and snippets.

View uwezi's full-sized avatar

Uwe Zimmermann uwezi

View GitHub Profile
@uwezi
uwezi / 20240529_triangle.py
Created May 29, 2024 22:54
[triangle centers] calculate different center points for a triangle. #geometry #python
def H(z,a,b,l):
'''
from https://codegolf.stackexchange.com/questions/11767/the-centers-of-a-triangle
1 - Incenter
2 - Centroid
3 - Circumcenter
4 - Orthocenter
5 - Equation of Euler Line
(if the Euler Line is vertical, output the `x` value of the line
@uwezi
uwezi / 20240525_system.py
Last active May 25, 2024 20:00
[system response] Plotting system response function in Manim. #manim #scipy #systemresponse #plot #linegraph
from scipy import signal
class stepResponse(Scene):
def construct(self):
T = np.linspace(0,10,1000)
sys = signal.TransferFunction([1,3,3], [1,2,1])
t, y1 = sys.impulse(T=T)
t, y2 = sys.step(T=T)
ax = Axes(
x_range=[-1,12,1],
x_length=[13],
@uwezi
uwezi / 20240524_glyphmap.py
Created May 24, 2024 11:27
[transform glyph map] Helper made by dudewaldo4 to animate LaTeX. #manim #latex #tex #mathtext #transform
from manim import *
# by dudewaldo4
# https://discord.com/channels/581738731934056449/976376734935048223/1161709114154569819
# https://www.youtube.com/watch?v=Bg999qefIic
#
def ir(a,b): # inclusive range, useful for TransformByGlyphMap
return list(range(a,b+1))
@uwezi
uwezi / 20240524_arc3d.py
Last active May 24, 2024 08:10
[arc in 3D] placing an arc/angle between lines in 3D. #manim #3D #angle #arc
from manim import *
# https://discord.com/channels/581738731934056449/1096718885606150154/1096718885606150154
class arc3d(VMobject):
def __init__(self, A=None, B=None, center=None, radius=1, segments=40, **kwargs):
super().__init__(**kwargs)
start = center + (A-center)*radius/np.linalg.norm(A-center)
end = center + (B-center)*radius/np.linalg.norm(B-center)
self.set_points([start])
for i in np.linspace(0,1,segments,endpoint=True):
@uwezi
uwezi / 20240523_decimalfont.py
Last active May 23, 2024 14:42
[font for DecimalNumber] render DecimalNumber objects in different fonts. #manim #decimalnumber #integer #font
from manim.mobject.text.numbers import string_to_mob_map as cache
# https://discord.com/channels/581738731934056449/1243063440206073907/1243210818837811230
class numText(Text):
def __init__(self, text: str, **kwargs) -> None:
print('hello')
super().__init__(text, font="Roboto", **kwargs)
class Test(Scene):
def construct(self):
@uwezi
uwezi / 20240406_inoutcircle.py
Last active April 6, 2024 21:35
[inner and outer circle] Showing the inner and outer circle of a triangle. #manim #geometry #triangle #circle
class inoutcircleTriangle(Scene):
def construct(self):
triangle = VMobject()
incirc = VMobject()
outcirc = VMobject()
for i in range(5):
A = np.array([np.random.uniform(-5,5),np.random.uniform(-3,3),0])
B = np.array([np.random.uniform(-5,5),np.random.uniform(-3,3),0])
C = np.array([np.random.uniform(-5,5),np.random.uniform(-3,3),0])
a = np.linalg.norm(B-C)
@uwezi
uwezi / 20240318_findpy.py
Created March 18, 2024 09:43
[find python executable] Find the python which is used by Manim. #manim #python #sys
from manim import *
import sys
class findpython(Scene):
def construct(self):
text = Text(sys.executable).scale_to_fit_width(14)
self.add(text)
@uwezi
uwezi / 20240309_opencv.py
Last active April 30, 2024 11:27
[video inclusion in Manim] Include video objects picture-in-picture. #manim #animate #video #opencv #videomobject
import cv2
from PIL import Image, ImageOps
from dataclasses import dataclass
@dataclass
class VideoStatus:
time: float = 0
videoObject: cv2.VideoCapture = None
def __deepcopy__(self, memo):
return self
@uwezi
uwezi / 20240308_pathfinder.py
Last active March 7, 2024 23:23
[more nearest neighbors] Animating the algorithm to find your way through a cloud of points. #manim #isolated_point #distance #nearest
from manim import *
class PathFinder(MovingCameraScene):
def construct(self):
# thanks ChatGPT
def closest_neighbor(given_point, points):
# Convert points to numpy array for efficient calculations
points_array = np.array(points)
# Calculate Euclidean distance between given_point and all points
@uwezi
uwezi / 20240307_nearest.py
Created March 7, 2024 20:14
[nearest neighbors] find the path through a list of points using nearest neighbors. #manim #chatgpt #sorting
# https://discord.com/channels/581738731934056449/1214983872413044786/1214983872413044786
from manim import *
class PathAutoSorted(MovingCameraScene):
def construct(self):
# thanks ChatGPT
def closest_neighbor(given_point, points):
# Convert points to numpy array for efficient calculations
points_array = np.array(points)