Skip to content

Instantly share code, notes, and snippets.

View carlos-adir's full-sized avatar

Carlos Adir carlos-adir

View GitHub Profile
@carlos-adir
carlos-adir / rational_nurbs.ipynb
Last active March 26, 2024 20:31
Describes Circle and Hyperbola with Rational Bezier Curves
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carlos-adir
carlos-adir / generator.py
Created February 25, 2024 21:17
Generate random password
import numpy as np
uppers = "QWERTYUIOPASDFGHJKLZXCVBNM"
lowers = "qwertyuiopasdfghjklzxcvbnm"
digits = list(map(str, range(10)))
specials = "!@#$%&*()+-/"
# specials = "!+-()#"
# specials = ""
chars = set(uppers)
@carlos-adir
carlos-adir / comb.py
Created December 12, 2023 13:17
Light binomial coefficient
def comb(a: int, b: int) -> int:
"""
Implements the binomial coefficient:
( a ) a !
( ) = -------------
( b ) b! * (a-b)!
"""
prod = 1
for i in range(min(b, a-b)):
prod *= a-i
@carlos-adir
carlos-adir / ellipses.py
Last active October 6, 2023 20:10
Maximize objective function in intersection of ellipses
import numpy as np
from matplotlib import pyplot as plt
nelips = 3
ndim = 2
all_axis = []
for i in range(nelips):
matrix = np.random.rand(ndim, ndim)
matrix += np.transpose(matrix)
eigvals, eigvecs = np.linalg.eigh(matrix)
@carlos-adir
carlos-adir / cyclic_curves.py
Last active September 25, 2023 18:13
Cyclic curves
from __future__ import annotations
from typing import *
import numpy as np
from matplotlib import pyplot as plt
class Point2D:
def __init__(self, x: float, y: float):
@carlos-adir
carlos-adir / bezier_curves_app.py
Last active September 25, 2023 13:07
Interactive Bezier/BSplines curves with matplotlib, with add/insert/remove/move control points in python
# import matplotlib
# matplotlib.use('webagg')
import math
from typing import Tuple, Union
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.lines import Line2D
@carlos-adir
carlos-adir / conics.py
Created August 29, 2023 20:19
Basic class to operate conic sections
import numpy as np
from matplotlib import pyplot as plt
from typing import Tuple
class Conic:
def __init__(self, coefs: Tuple[float]):
self.coefs = coefs
@carlos-adir
carlos-adir / inverse_int_frac_matrix.py
Last active July 30, 2023 07:56
Find inverse of matrix using integers and fractions
from typing import Tuple
import numpy as np
from fractions import Fraction
import math
def invert_integer_matrix(
matrix: Tuple[Tuple[int]],
) -> Tuple[Tuple[int], Tuple[Tuple[int]]]:
"""
@carlos-adir
carlos-adir / canon2bezier.py
Created July 21, 2023 19:13
Transforms a polynomial in canonical basis into bezier basis and vice-versa
from typing import Tuple
import sympy as sp
import numpy as np
def Bezier2Canonical(degree: int) -> np.ndarray:
"""
Returns a transformation matrix between the basis
Bezier -> Canonical
"""
matrix = np.zeros((degree+1, degree+1), dtype="object")
@carlos-adir
carlos-adir / ComputeSectionCircleValues.ipynb
Created June 25, 2023 09:30
Compute section properties of a circle by using boundary method
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.