forked from puffertron/physics-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculations.py
42 lines (28 loc) · 1.14 KB
/
calculations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from math import cos, sin, sqrt, pi
from ursina import Vec2
"""
using variables from parameter file
"""
# distance calculation
def distance(dx: float, dy: float, dz: float) -> float:
return sqrt(dx ** 2 + dy ** 2 + dz ** 2)
# angle calculation
def angle(wavelength: float, ray_dist: float) -> float:
# the wavelength (λ) travels along the ray distance
# Ray distance
# |---------------------------------------|
# |-----λ-----|-----λ-----|-----λ-----|---|
# ^
# (ray_distance % λ)
# Measure of how close the wave is to ending on an n * λ, in terms of phase angle
return (ray_dist % wavelength) / wavelength * (2 * pi)
# Calculation for wave amplitude
def amplitude(vis_separation: float, ray_dist: float) -> float:
return (1 + vis_separation / ray_dist) / ray_dist
# Calculating pixel color values
def cartesian(vis_separation: float, ray_dist: float, wavelength: float) -> Vec2:
amp = amplitude(vis_separation, ray_dist)
ang = angle(wavelength, ray_dist)
x = amp * cos(ang)
y = amp * sin(ang)
return Vec2(x, y)