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 / polinomios.py
Created October 8, 2024 20:29
This file contains a class called Polinomio such allows evaluating, adding and multiplying polynomials
"""
This file contains a class Polynomial that allows evaluating and
making operations with polynomials, like adding, multiplying, etc
"""
from __future__ import annotations
import math
from typing import Tuple, Union
Parameter = Union[int, float]
@carlos-adir
carlos-adir / trignomios.py
Last active October 8, 2024 20:44
This file contains a class Trignomio that allows evaluating and making operations with trignomios, like adding, multiplying, etc A trignomio is similar to a polynomial, but uses trigonometric functions
"""
This file contains a class Trignomio that allows evaluating and
making operations with trignomios, like adding, multiplying, etc
A trignomio is similar to a polynomial, but uses trignometic functions
Example
-------
>>> trig = Trignomio([1, 2, 3])
>>> print(trig)
@carlos-adir
carlos-adir / sympy_nurbs.py
Last active July 22, 2024 18:25
Analitic BSpline basis
import sympy as sp
import numpy as np
from matplotlib import pyplot as plt
class Knotvector:
@classmethod
def uniform(cls, degree, npts):
ninter = npts - degree
@carlos-adir
carlos-adir / rational_nurbs.ipynb
Last active March 26, 2024 20:31
Describes Circle and Hyperbola with Rational Bezier Curves
Loading
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