Skip to content

Commit 61a44a4

Browse files
committed
Move points generation into datatype classes
1 parent 72420b8 commit 61a44a4

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

datatypes/great_circle_arc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import numpy as np
12
from .point import Point
3+
from .vector import Vector
24

35
class GreatCircleArc:
46

@@ -7,3 +9,15 @@ def __init__(self, beg : Point, end : Point):
79

810
def __getitem__(self, idx):
911
return self.pts[idx]
12+
13+
def points(self, num : int):
14+
v1 = Vector(self[0])
15+
v2 = Vector(self[1])
16+
v3 = v1.cross_product(v2)
17+
v4 = v3.cross_product(v2).normalized()
18+
dp = -np.arccos(v1.dot_product(v2))
19+
t = np.linspace(0, dp, 1000)
20+
x = np.cos(t) * v2[0] + np.sin(t) * v4[0]
21+
y = np.cos(t) * v2[1] + np.sin(t) * v4[1]
22+
z = np.cos(t) * v2[2] + np.sin(t) * v4[2]
23+
return x, y, z

datatypes/meridian.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import numpy as np
12
from .point import Point
23

34
class Meridian:
45

5-
def __init__(self, lng):
6+
def __init__(self, lng : float):
67
self.lng = lng
8+
9+
def points(self, num : int):
10+
lngv = self.lng
11+
latv = np.linspace(-np.pi/2, np.pi/2, num)
12+
x = np.cos(lngv) * np.cos(latv)
13+
y = np.sin(lngv) * np.cos(latv)
14+
z = np.sin(latv)
15+
return x, y, z

datatypes/parallel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import numpy as np
12
from .point import Point
23

34
class Parallel:
45

56
def __init__(self, lat):
67
self.lat = lat
8+
9+
def points(self, num : int):
10+
lngv = np.linspace(0, 2 * np.pi, num)
11+
latv = self.lat
12+
x = np.cos(lngv) * np.cos(latv)
13+
y = np.sin(lngv) * np.cos(latv)
14+
z = np.sin(latv)
15+
return x, y, z

datatypes/vector.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ def normalized(self):
3232
norm = np.sqrt(self[0] ** 2 + self[1] ** 2 + self[2] ** 2)
3333
coords = self.coords / norm
3434
return Vector(coords)
35+
36+
def points(self, num : int):
37+
x = np.linspace(0, self[0], num)
38+
y = np.linspace(0, self[1], num)
39+
z = np.linspace(0, self[2], num)
40+
return x, y, z

sphereplot.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,18 @@ def __plot_object(self, gobj):
6363
self.__plot_vector(gobj)
6464

6565
def __plot_meridian(self, gobj, **kwargs):
66-
lngv = gobj.lng
67-
latv = np.linspace(-np.pi/2, np.pi/2, 100)
68-
x = np.cos(lngv) * np.cos(latv)
69-
y = np.sin(lngv) * np.cos(latv)
70-
z = np.sin(latv)
66+
x, y, z = gobj.points(100)
7167
self.axes.scatter(x, y, z, **kwargs)
7268

7369
def __plot_parallel(self, gobj):
74-
lngv = np.linspace(0, 2 * np.pi, 100)
75-
latv = gobj.lat
76-
x = np.cos(lngv) * np.cos(latv)
77-
y = np.sin(lngv) * np.cos(latv)
78-
z = np.sin(latv)
70+
x, y, z = gobj.points(200)
7971
self.axes.scatter(x, y, z, s = 0.1, color = "darkgray")
8072

8173
def __plot_arc(self, garc, **kwargs):
82-
v1 = Vector(garc[0])
83-
v2 = Vector(garc[1])
84-
v3 = v1.cross_product(v2)
85-
v4 = v3.cross_product(v2).normalized()
86-
dp = -np.arccos(v1.dot_product(v2))
87-
t = np.linspace(0, dp, 1000)
88-
x = np.cos(t) * v2[0] + np.sin(t) * v4[0]
89-
y = np.cos(t) * v2[1] + np.sin(t) * v4[1]
90-
z = np.cos(t) * v2[2] + np.sin(t) * v4[2]
74+
x, y, z = garc.points(100)
9175
k = { "color" : "red", "s" : 0.1 } | kwargs
9276
self.axes.scatter(x, y, z, **k)
9377

9478
def __plot_vector(self, gvec : Vector, **kwargs):
95-
x = np.linspace(0, gvec[0], 100)
96-
y = np.linspace(0, gvec[1], 100)
97-
z = np.linspace(0, gvec[2], 100)
79+
x, y, z = gvec.points(2)
9880
self.axes.plot3D(x, y, z, **kwargs)

0 commit comments

Comments
 (0)