Skip to content

Commit d6aeff9

Browse files
committed
Put data types into separate python modules in the datatypes subdirectory
1 parent 3f8b30f commit d6aeff9

File tree

7 files changed

+69
-58
lines changed

7 files changed

+69
-58
lines changed

datatypes/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .point import Point
2+
from .vector import Vector
3+
from .parallel import Parallel
4+
from .meridian import Meridian
5+
from .great_circle_arc import GreatCircleArc

datatypes/great_circle_arc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .point import Point
2+
3+
class GreatCircleArc:
4+
5+
def __init__(self, beg : Point, end : Point):
6+
self.pts = [beg, end]
7+
8+
def __getitem__(self, idx):
9+
return self.pts[idx]

datatypes/meridian.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .point import Point
2+
3+
class Meridian:
4+
5+
def __init__(self, lng):
6+
self.lng = lng

datatypes/parallel.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .point import Point
2+
3+
class Parallel:
4+
5+
def __init__(self, lat):
6+
self.lat = lat

datatypes/point.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class Point:
3+
4+
def __init__(self, lng, lat):
5+
self.coords = [lng, lat]
6+
7+
def __getitem__(self, idx):
8+
return self.coords[idx]

datatypes/vector.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import numpy as np
2+
from .point import Point
3+
4+
class Vector:
5+
6+
def __init__(self, data, color = None):
7+
if isinstance(data, Point):
8+
self.coords = [
9+
np.cos(data[0]) * np.cos(data[1]),
10+
np.sin(data[0]) * np.cos(data[1]),
11+
np.sin(data[1])
12+
]
13+
elif isinstance(data, list):
14+
self.coords = np.array(data)
15+
elif isinstance(data, np.ndarray):
16+
self.coords = data.copy()
17+
self.color = "black" if color is None else color
18+
19+
def __getitem__(self, idx):
20+
return self.coords[idx]
21+
22+
def cross_product(self, v):
23+
x = self[1] * v[2] - self[2] * v[1]
24+
y = self[2] * v[0] - self[0] * v[2]
25+
z = self[0] * v[1] - self[1] * v[0]
26+
return Vector([x, y, z])
27+
28+
def dot_product(self, v):
29+
return self[0] * v[0] + self[1] * v[1] + self[2] * v[2];
30+
31+
def normalized(self):
32+
norm = np.sqrt(self[0] ** 2 + self[1] ** 2 + self[2] ** 2)
33+
coords = self.coords / norm
34+
return Vector(coords)

sphereplot.py

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,6 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
3-
4-
class Point:
5-
6-
def __init__(self, lng, lat):
7-
self.coords = [lng, lat]
8-
9-
def __getitem__(self, idx):
10-
return self.coords[idx]
11-
12-
class Vector:
13-
14-
def __init__(self, data, color = None):
15-
if isinstance(data, Point):
16-
self.coords = [
17-
np.cos(data[0]) * np.cos(data[1]),
18-
np.sin(data[0]) * np.cos(data[1]),
19-
np.sin(data[1])
20-
]
21-
elif isinstance(data, list):
22-
self.coords = np.array(data)
23-
elif isinstance(data, np.ndarray):
24-
self.coords = data.copy()
25-
self.color = "black" if color is None else color
26-
27-
def __getitem__(self, idx):
28-
return self.coords[idx]
29-
30-
def cross_product(self, v):
31-
x = self[1] * v[2] - self[2] * v[1]
32-
y = self[2] * v[0] - self[0] * v[2]
33-
z = self[0] * v[1] - self[1] * v[0]
34-
return Vector([x, y, z])
35-
36-
def dot_product(self, v):
37-
return self[0] * v[0] + self[1] * v[1] + self[2] * v[2];
38-
39-
def normalized(self):
40-
norm = np.sqrt(self[0] ** 2 + self[1] ** 2 + self[2] ** 2)
41-
coords = self.coords / norm
42-
return Vector(coords)
43-
44-
class GreatCircleArc:
45-
46-
def __init__(self, beg : Point, end : Point):
47-
self.pts = [beg, end]
48-
49-
def __getitem__(self, idx):
50-
return self.pts[idx]
51-
52-
class Meridian:
53-
54-
def __init__(self, lng):
55-
self.lng = lng
56-
57-
class Parallel:
58-
59-
def __init__(self, lat):
60-
self.lat = lat
3+
from datatypes import *
614

625
class Sphere:
636

0 commit comments

Comments
 (0)