Hong-Phuc Bui
2024-05-12 6609420bf03972212cbfaeb6b53eee66a478e7bf
drop some topic
2 files modified
5 files added
106 ■■■■■ changed files
.gitignore 2 ●●●●● patch | view | raw | blame | history
python-grundlage/cartesian2polar.py 16 ●●●●● patch | view | raw | blame | history
python-grundlage/dice-simulation.py 7 ●●●● patch | view | raw | blame | history
python-grundlage/horner.py 32 ●●●●● patch | view | raw | blame | history
python-grundlage/mecartor-projection.py 31 ●●●●● patch | view | raw | blame | history
python-grundlage/petal.py 8 ●●●● patch | view | raw | blame | history
python-grundlage/polynom.txt 10 ●●●●● patch | view | raw | blame | history
.gitignore
New file
@@ -0,0 +1,2 @@
sandbox*
queens*
python-grundlage/cartesian2polar.py
New file
@@ -0,0 +1,16 @@
#! /usr/bin/env python
import sys
import math
x = float(sys.argv[1])
y = float(sys.argv[2])
z = complex(x, y)
radius = abs(z)
theta = math.atan2(y, x)
theta_degree = math.degrees(theta)
print("Kartesische Koordinate des Punktes:")
print(f"   x = {x}; y = {y}")
print(f"   r = {radius:.3f}; theta = {theta_degree:.3f}°")
python-grundlage/dice-simulation.py
@@ -10,7 +10,10 @@
print(absolute_frequency)
relative_frequency = tuple(
    (f[0], f[1]/experiments) for f in absolute_frequency
    (freq[0], freq[1] / experiments) for freq in absolute_frequency
)
print(relative_frequency)
relative_frequency = tuple(
    (absolute_frequency[idx][0], absolute_frequency[idx][1] / experiments) for idx in range(1, 6 + 1)
)
python-grundlage/horner.py
New file
@@ -0,0 +1,32 @@
#! /usr/bin/env python
from sys import stdin
# read polynome from stdin
print(f"Input Coefficients line by line, last line is x0, Press Ctr+D to finish!")
lines = []
for line in stdin:
    koeffizient = line.strip()
    if koeffizient[0] == "#":
        continue
    if len(koeffizient) > 0:
        lines.append(float(koeffizient))
    else:
        break
a = lines[0:-1]
b = lines[-1]
b = float(b)
p = a[-1]
c = [p]
for ak in a[-2::-1]:
    p = ak + (p * b)
    c.insert(0, p)
p_b = c[0]
c = c[1:]
print(f"p(x) =", a)
print(f"p({b}) = {p_b}")
print(f"c(x) =", c)
python-grundlage/mecartor-projection.py
New file
@@ -0,0 +1,31 @@
#! /usr/bin/env python
"""
Usage:
python mecartor-projection <latitude> <longitude>
Example Bundestags Kooridnaten: 52°31'7.22" N 13°22'13.69" E
./mecartor-projection.py 52.5186729836 13.3704687765
x = 5.55928
y = 18.86398
"""
from math import log, tan, radians, pi
import sys
from typing import Final
# Sternwarte Peterberg WGS84 (49° 34′ N, 7° 0′ E)
MAP_CENTER_LONGITUDE: Final[float] = radians(7)
RADIUS: Final[float] = 50  # cm
latitude = float(sys.argv[1])  # Degree
longitude = float(sys.argv[2])  # Degree
# Hilfe-Variablen
lat = radians(latitude)
lon = radians(longitude)
# Kartesische Koordinaten
x: float = RADIUS * (lon - MAP_CENTER_LONGITUDE)
y: float = RADIUS * log(tan(pi/4) + lat/2)
print(f"x = {x:.5f}")
print(f"y = {y:.5f}")
python-grundlage/petal.py
@@ -2,18 +2,18 @@
import turtle
import math
num_of_petal = 60
num_of_petal = 5
petal_length = 100
# winkel sind in Degree
alpha = 90 / num_of_petal
alpha = 90 / (num_of_petal-1)
beta = 2 * alpha
gamma = 180 - beta
# abgeleitete Länge
side_length = petal_length * math.cos(math.radians(alpha))
start_angle = 0
for petal in range(0, num_of_petal):
    direction = petal * (360 / num_of_petal)
    direction = petal * (360 / num_of_petal) + start_angle
    turtle.home()
    turtle.left(direction + alpha)
    turtle.fd(side_length)
python-grundlage/polynom.txt
New file
@@ -0,0 +1,10 @@
# Koefizient
4
0
2
0
0
-3
6
# x0 =
2