topologicpy 0.4.8__py3-none-any.whl → 0.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- topologicpy/Aperture.py +46 -0
- topologicpy/Cell.py +1780 -0
- topologicpy/CellComplex.py +791 -0
- topologicpy/Cluster.py +591 -0
- topologicpy/Color.py +157 -0
- topologicpy/Context.py +56 -0
- topologicpy/DGL.py +2661 -0
- topologicpy/Dictionary.py +470 -0
- topologicpy/Edge.py +855 -0
- topologicpy/EnergyModel.py +1052 -0
- topologicpy/Face.py +1810 -0
- topologicpy/Graph.py +3526 -0
- topologicpy/Graph_Export.py +858 -0
- topologicpy/Grid.py +338 -0
- topologicpy/Helper.py +182 -0
- topologicpy/Honeybee.py +424 -0
- topologicpy/Matrix.py +255 -0
- topologicpy/Neo4jGraph.py +311 -0
- topologicpy/Plotly.py +1396 -0
- topologicpy/Polyskel.py +524 -0
- topologicpy/Process.py +1368 -0
- topologicpy/SQL.py +48 -0
- topologicpy/Shell.py +1418 -0
- topologicpy/Speckle.py +433 -0
- topologicpy/Topology.py +5854 -0
- topologicpy/UnitTest.py +29 -0
- topologicpy/Vector.py +555 -0
- topologicpy/Vertex.py +714 -0
- topologicpy/Wire.py +2346 -0
- topologicpy/__init__.py +20 -0
- topologicpy/bin/linux/topologic/__init__.py +2 -0
- topologicpy/bin/linux/topologic/topologic.cpython-310-x86_64-linux-gnu.so +0 -0
- topologicpy/bin/linux/topologic/topologic.cpython-311-x86_64-linux-gnu.so +0 -0
- topologicpy/bin/linux/topologic/topologic.cpython-38-x86_64-linux-gnu.so +0 -0
- topologicpy/bin/linux/topologic/topologic.cpython-39-x86_64-linux-gnu.so +0 -0
- topologicpy/bin/linux/topologic.libs/libTKBO-6bdf205d.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKBRep-2960a069.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKBool-c44b74bd.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKFillet-9a670ba0.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKG2d-8f31849e.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKG3d-4c6bce57.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKMath-72572fa8.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKMesh-2a060427.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKOffset-6cab68ff.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKPrim-eb1262b3.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
- topologicpy/bin/linux/topologic.libs/libgcc_s-32c1665e.so.1 +0 -0
- topologicpy/bin/linux/topologic.libs/libstdc++-672d7b41.so.6.0.30 +0 -0
- topologicpy/bin/windows/topologic/TKBO-f6b191de.dll +0 -0
- topologicpy/bin/windows/topologic/TKBRep-e56a600e.dll +0 -0
- topologicpy/bin/windows/topologic/TKBool-7b8d47ae.dll +0 -0
- topologicpy/bin/windows/topologic/TKFillet-0ddbf0a8.dll +0 -0
- topologicpy/bin/windows/topologic/TKG2d-2e2dee3d.dll +0 -0
- topologicpy/bin/windows/topologic/TKG3d-6674513d.dll +0 -0
- topologicpy/bin/windows/topologic/TKGeomAlgo-d240e370.dll +0 -0
- topologicpy/bin/windows/topologic/TKGeomBase-df87aba5.dll +0 -0
- topologicpy/bin/windows/topologic/TKMath-45bd625a.dll +0 -0
- topologicpy/bin/windows/topologic/TKMesh-d6e826b1.dll +0 -0
- topologicpy/bin/windows/topologic/TKOffset-79b9cc94.dll +0 -0
- topologicpy/bin/windows/topologic/TKPrim-aa430a86.dll +0 -0
- topologicpy/bin/windows/topologic/TKShHealing-bb48be89.dll +0 -0
- topologicpy/bin/windows/topologic/TKTopAlgo-7d0d1e22.dll +0 -0
- topologicpy/bin/windows/topologic/TKernel-08c8cfbb.dll +0 -0
- topologicpy/bin/windows/topologic/__init__.py +2 -0
- topologicpy/bin/windows/topologic/topologic.cp310-win_amd64.pyd +0 -0
- topologicpy/bin/windows/topologic/topologic.cp311-win_amd64.pyd +0 -0
- topologicpy/bin/windows/topologic/topologic.cp38-win_amd64.pyd +0 -0
- topologicpy/bin/windows/topologic/topologic.cp39-win_amd64.pyd +0 -0
- {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/METADATA +1 -1
- topologicpy-0.4.9.dist-info/RECORD +77 -0
- topologicpy-0.4.9.dist-info/top_level.txt +1 -0
- topologicpy-0.4.8.dist-info/RECORD +0 -5
- topologicpy-0.4.8.dist-info/top_level.txt +0 -1
- {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/LICENSE +0 -0
- {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/WHEEL +0 -0
topologicpy/UnitTest.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Vertex Unit testing
|
|
2
|
+
import topologicpy
|
|
3
|
+
import topologic
|
|
4
|
+
from topologicpy.Vertex import Vertex
|
|
5
|
+
from topologicpy.CellComplex import CellComplex
|
|
6
|
+
|
|
7
|
+
v = Vertex.ByCoordinates(10, 20, 30)
|
|
8
|
+
assert isinstance(v, topologic.Vertex), "Vertex.ByCoordinates. Should be topologic.Vertex"
|
|
9
|
+
|
|
10
|
+
v = Vertex.ByCoordinates(10.123, 20.456, 30.789)
|
|
11
|
+
x = Vertex.Coordinates(v, outputType="x", mantissa=3)
|
|
12
|
+
assert x == [10.123], "Vertex.Coordinates. Should be 10.123"
|
|
13
|
+
y = Vertex.Coordinates(v, outputType="y", mantissa=3)
|
|
14
|
+
assert y == [20.456], "Vertex.Coordinates. Should be 20.456"
|
|
15
|
+
z = Vertex.Coordinates(v, outputType="z", mantissa=3)
|
|
16
|
+
assert z == [30.789], "Vertex.Coordinates. Should be 30.789"
|
|
17
|
+
xyz = Vertex.Coordinates(v, outputType="xyz", mantissa=3)
|
|
18
|
+
assert xyz == [10.123, 20.456, 30.789], "Vertex.Coordinates. Should be 30.789"
|
|
19
|
+
|
|
20
|
+
v1 = Vertex.ByCoordinates(10, 20, 30)
|
|
21
|
+
v2 = Vertex.ByCoordinates(20, 30, 40)
|
|
22
|
+
d = Vertex.Distance(v1, v2, mantissa=3)
|
|
23
|
+
assert d == 17.321, "Vertex.Distance. Should be 17.321"
|
|
24
|
+
|
|
25
|
+
origin = Vertex.ByCoordinates(0,0,0)
|
|
26
|
+
cc = CellComplex.Prism(origin=origin, width=10, length=10, height=10, uSides=2, vSides=2, wSides=2,
|
|
27
|
+
direction=[0,0,1], originLocation="Center")
|
|
28
|
+
assert isinstance(cc, topologic.CellComplex), "Vertex.EnclosingCell. Should be topologic.CellComplex"
|
|
29
|
+
EnclosingCell(vertex, topology, exclusive=True, tolerance=0.0001)
|
topologicpy/Vector.py
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import numpy.linalg as la
|
|
3
|
+
from numpy import pi, arctan2, rad2deg
|
|
4
|
+
import math
|
|
5
|
+
|
|
6
|
+
class Vector(list):
|
|
7
|
+
@staticmethod
|
|
8
|
+
def Angle(vectorA, vectorB, mantissa=4):
|
|
9
|
+
"""
|
|
10
|
+
Returns the angle in degrees between the two input vectors
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
vectorA : list
|
|
15
|
+
The first vector.
|
|
16
|
+
vectorB : list
|
|
17
|
+
The second vector.
|
|
18
|
+
mantissa : int, optional
|
|
19
|
+
The length of the desired mantissa. The default is 4.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
float
|
|
24
|
+
The angle in degrees between the two input vectors.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
n_v1=la.norm(vectorA)
|
|
28
|
+
n_v2=la.norm(vectorB)
|
|
29
|
+
if (abs(np.log10(n_v1/n_v2)) > 10):
|
|
30
|
+
vectorA = vectorA/n_v1
|
|
31
|
+
vectorB = vectorB/n_v2
|
|
32
|
+
cosang = np.dot(vectorA, vectorB)
|
|
33
|
+
sinang = la.norm(np.cross(vectorA, vectorB))
|
|
34
|
+
return round(math.degrees(np.arctan2(sinang, cosang)), mantissa)
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def AzimuthAltitude(vector, mantissa=4):
|
|
38
|
+
"""
|
|
39
|
+
Returns a dictionary of azimuth and altitude angles in degrees for the input vector. North is assumed to be the positive Y axis [0,1,0]. Up is assumed to be the positive Z axis [0,0,1].
|
|
40
|
+
Azimuth is calculated in a counter-clockwise fashion from North where 0 is North, 90 is East, 180 is South, and 270 is West. Altitude is calculated in a counter-clockwise fashing where -90 is straight down (negative Z axis), 0 is in the XY plane, and 90 is straight up (positive Z axis).
|
|
41
|
+
If the altitude is -90 or 90, the azimuth is assumed to be 0.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
vectorA : list
|
|
46
|
+
The input vector.
|
|
47
|
+
mantissa : int, optional
|
|
48
|
+
The length of the desired mantissa. The default is 4.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
dict
|
|
53
|
+
The dictionary containing the azimuth and altitude angles in degrees. The keys in the dictionary are 'azimuth' and 'altitude'.
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
x, y, z = vector
|
|
57
|
+
if x == 0 and y == 0:
|
|
58
|
+
if z > 0:
|
|
59
|
+
return {"azimuth":0, "altitude":90}
|
|
60
|
+
elif z < 0:
|
|
61
|
+
return {"azimuth":0, "altitude":-90}
|
|
62
|
+
else:
|
|
63
|
+
# undefined
|
|
64
|
+
return None
|
|
65
|
+
else:
|
|
66
|
+
azimuth = math.degrees(math.atan2(y, x))
|
|
67
|
+
if azimuth > 90:
|
|
68
|
+
azimuth -= 360
|
|
69
|
+
azimuth = round(90-azimuth, mantissa)
|
|
70
|
+
xy_distance = math.sqrt(x**2 + y**2)
|
|
71
|
+
altitude = math.degrees(math.atan2(z, xy_distance))
|
|
72
|
+
altitude = round(altitude, mantissa)
|
|
73
|
+
return {"azimuth":azimuth, "altitude":altitude}
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def ByAzimuthAltitude(azimuth, altitude, north=0, reverse=False):
|
|
77
|
+
"""
|
|
78
|
+
Returns the vector specified by the input azimuth and altitude angles.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
azimuth : float
|
|
83
|
+
The input azimuth angle in degrees. The angle is computed in an anti-clockwise fashion. 0 is considered North, 90 East, 180 is South, 270 is West
|
|
84
|
+
altitude : float
|
|
85
|
+
The input altitude angle in degrees from the XY plane. Positive is above the XY plane. Negative is below the XY plane
|
|
86
|
+
north : float , optional
|
|
87
|
+
The angle of the north direction in degrees measured from positive Y-axis. The angle is added in anti-clockwise fashion. 0 is considered along the positive Y-axis,
|
|
88
|
+
90 is along the positive X-axis, 180 is along the negative Y-axis, and 270 along the negative Y-axis.
|
|
89
|
+
reverse : bool , optional
|
|
90
|
+
If set to True the direction of the vector is computed from the end point towards the origin. Otherwise, it is computed from the origin towards the end point.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
list
|
|
95
|
+
The resulting vector.
|
|
96
|
+
|
|
97
|
+
"""
|
|
98
|
+
from topologicpy.Vertex import Vertex
|
|
99
|
+
from topologicpy.Edge import Edge
|
|
100
|
+
from topologicpy.Topology import Topology
|
|
101
|
+
e = Edge.ByVertices([Vertex.Origin(), Vertex.ByCoordinates(0,1,0)])
|
|
102
|
+
e = Topology.Rotate(e, Vertex.Origin(), 1, 0, 0, altitude)
|
|
103
|
+
e = Topology.Rotate(e, Vertex.Origin(), 0, 0, 1, -azimuth-north)
|
|
104
|
+
if reverse:
|
|
105
|
+
return Vector.Reverse(Edge.Direction(e))
|
|
106
|
+
return Edge.Direction(e)
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def ByCoordinates(x, y, z):
|
|
110
|
+
"""
|
|
111
|
+
Creates a vector by the specified x, y, z inputs.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
x : float
|
|
116
|
+
The X coordinate.
|
|
117
|
+
y : float
|
|
118
|
+
The Y coordinate.
|
|
119
|
+
z : float
|
|
120
|
+
The Z coodinate.
|
|
121
|
+
|
|
122
|
+
Returns
|
|
123
|
+
-------
|
|
124
|
+
list
|
|
125
|
+
The created vector.
|
|
126
|
+
|
|
127
|
+
"""
|
|
128
|
+
return [x,y,z]
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
def ByVertices(vertices, normalize=True):
|
|
132
|
+
"""
|
|
133
|
+
Creates a vector by the specified input list of vertices.
|
|
134
|
+
|
|
135
|
+
Parameters
|
|
136
|
+
----------
|
|
137
|
+
vertices : list
|
|
138
|
+
The the input list of topologic vertices. The first element in the list is considered the start vertex. The last element in the list is considered the end vertex.
|
|
139
|
+
normalize : bool , optional
|
|
140
|
+
If set to True, the resulting vector is normalized (i.e. its length is set to 1)
|
|
141
|
+
|
|
142
|
+
Returns
|
|
143
|
+
-------
|
|
144
|
+
list
|
|
145
|
+
The created vector.
|
|
146
|
+
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
from topologicpy.Vertex import Vertex
|
|
150
|
+
import topologic
|
|
151
|
+
if not isinstance(vertices, list):
|
|
152
|
+
return None
|
|
153
|
+
if not isinstance(normalize, bool):
|
|
154
|
+
return None
|
|
155
|
+
vertices = [v for v in vertices if isinstance(v, topologic.Vertex)]
|
|
156
|
+
if len(vertices) < 2:
|
|
157
|
+
return None
|
|
158
|
+
v1 = vertices[0]
|
|
159
|
+
v2 = vertices[-1]
|
|
160
|
+
vector = [Vertex.X(v2)-Vertex.X(v1), Vertex.Y(v2)-Vertex.Y(v1), Vertex.Z(v2)-Vertex.Z(v1)]
|
|
161
|
+
if normalize:
|
|
162
|
+
vector = Vector.Normalize(vector)
|
|
163
|
+
return vector
|
|
164
|
+
|
|
165
|
+
@staticmethod
|
|
166
|
+
def CompassAngle(vectorA, vectorB, mantissa=4, tolerance=0.0001):
|
|
167
|
+
"""
|
|
168
|
+
Returns the horizontal compass angle in degrees between the two input vectors. The angle is measured in counter-clockwise fashion. Only the first two elements in the input vectors are considered.
|
|
169
|
+
|
|
170
|
+
Parameters
|
|
171
|
+
----------
|
|
172
|
+
vectorA : list
|
|
173
|
+
The first vector.
|
|
174
|
+
vectorB : list
|
|
175
|
+
The second vector.
|
|
176
|
+
mantissa : int, optional
|
|
177
|
+
The length of the desired mantissa. The default is 4.
|
|
178
|
+
tolerance : float , optional
|
|
179
|
+
The desired tolerance. The default is 0.0001.
|
|
180
|
+
|
|
181
|
+
Returns
|
|
182
|
+
-------
|
|
183
|
+
float
|
|
184
|
+
The horizontal compass angle in degrees between the two input vectors.
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
if abs(vectorA[0]) < tolerance and abs(vectorA[1]) < tolerance:
|
|
188
|
+
return None
|
|
189
|
+
if abs(vectorB[0]) < tolerance and abs(vectorB[1]) < tolerance:
|
|
190
|
+
return None
|
|
191
|
+
p1 = (vectorA[0], vectorA[1])
|
|
192
|
+
p2 = (vectorB[0], vectorB[1])
|
|
193
|
+
ang1 = arctan2(*p1[::-1])
|
|
194
|
+
ang2 = arctan2(*p2[::-1])
|
|
195
|
+
return round(rad2deg((ang1 - ang2) % (2 * pi)), mantissa)
|
|
196
|
+
|
|
197
|
+
@staticmethod
|
|
198
|
+
def Coordinates(vector, outputType="xyz", mantissa=4):
|
|
199
|
+
"""
|
|
200
|
+
Returns the coordinates of the input vector.
|
|
201
|
+
|
|
202
|
+
Parameters
|
|
203
|
+
----------
|
|
204
|
+
vector : list
|
|
205
|
+
The input vector.
|
|
206
|
+
outputType : string, optional
|
|
207
|
+
The desired output type. Could be any permutation or substring of "xyz" or the string "matrix". The default is "xyz". The input is case insensitive and the coordinates will be returned in the specified order.
|
|
208
|
+
mantissa : int , optional
|
|
209
|
+
The desired length of the mantissa. The default is 4.
|
|
210
|
+
|
|
211
|
+
Returns
|
|
212
|
+
-------
|
|
213
|
+
list
|
|
214
|
+
The coordinates of the input vertex.
|
|
215
|
+
|
|
216
|
+
"""
|
|
217
|
+
if not isinstance(vector, list):
|
|
218
|
+
return None
|
|
219
|
+
x = round(vector[0], mantissa)
|
|
220
|
+
y = round(vector[1], mantissa)
|
|
221
|
+
z = round(vector[2], mantissa)
|
|
222
|
+
matrix = [[1,0,0,x],
|
|
223
|
+
[0,1,0,y],
|
|
224
|
+
[0,0,1,z],
|
|
225
|
+
[0,0,0,1]]
|
|
226
|
+
output = []
|
|
227
|
+
outputType = outputType.lower()
|
|
228
|
+
if outputType == "matrix":
|
|
229
|
+
return matrix
|
|
230
|
+
else:
|
|
231
|
+
outputType = list(outputType)
|
|
232
|
+
for axis in outputType:
|
|
233
|
+
if axis == "x":
|
|
234
|
+
output.append(x)
|
|
235
|
+
elif axis == "y":
|
|
236
|
+
output.append(y)
|
|
237
|
+
elif axis == "z":
|
|
238
|
+
output.append(z)
|
|
239
|
+
return output
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def Cross(vectorA, vectorB, mantissa=4, tolerance=0.0001):
|
|
243
|
+
"""
|
|
244
|
+
Returns the cross product of the two input vectors. The resulting vector is perpendicular to the plane defined by the two input vectors.
|
|
245
|
+
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
vectorA : list
|
|
249
|
+
The first vector.
|
|
250
|
+
vectorB : list
|
|
251
|
+
The second vector.
|
|
252
|
+
mantissa : int, optional
|
|
253
|
+
The length of the desired mantissa. The default is 4.
|
|
254
|
+
tolerance : float, optional
|
|
255
|
+
the desired tolerance. The default is 0.0001.
|
|
256
|
+
|
|
257
|
+
Returns
|
|
258
|
+
-------
|
|
259
|
+
list
|
|
260
|
+
The vector representing the cross product of the two input vectors.
|
|
261
|
+
|
|
262
|
+
"""
|
|
263
|
+
if not isinstance(vectorA, list) or not isinstance(vectorB, list):
|
|
264
|
+
return None
|
|
265
|
+
if Vector.Magnitude(vector=vectorA, mantissa=mantissa) < tolerance or Vector.Magnitude(vector=vectorB, mantissa=mantissa) < tolerance:
|
|
266
|
+
return None
|
|
267
|
+
vecA = np.array(vectorA)
|
|
268
|
+
vecB = np.array(vectorB)
|
|
269
|
+
vecC = list(np.cross(vecA, vecB))
|
|
270
|
+
if Vector.Magnitude(vecC) < tolerance:
|
|
271
|
+
return None
|
|
272
|
+
return [round(vecC[0], mantissa), round(vecC[1], mantissa), round(vecC[2], mantissa)]
|
|
273
|
+
|
|
274
|
+
@staticmethod
|
|
275
|
+
def Down():
|
|
276
|
+
"""
|
|
277
|
+
Returns the vector representing the *down* direction. In Topologic, the negative ZAxis direction is considered *down* ([0,0,-1]).
|
|
278
|
+
|
|
279
|
+
Returns
|
|
280
|
+
-------
|
|
281
|
+
list
|
|
282
|
+
The vector representing the *down* direction.
|
|
283
|
+
"""
|
|
284
|
+
return [0,0,-1]
|
|
285
|
+
|
|
286
|
+
@staticmethod
|
|
287
|
+
def East():
|
|
288
|
+
"""
|
|
289
|
+
Returns the vector representing the *east* direction. In Topologic, the positive XAxis direction is considered *east* ([1,0,0]).
|
|
290
|
+
|
|
291
|
+
Returns
|
|
292
|
+
-------
|
|
293
|
+
list
|
|
294
|
+
The vector representing the *east* direction.
|
|
295
|
+
"""
|
|
296
|
+
return [1,0,0]
|
|
297
|
+
|
|
298
|
+
@staticmethod
|
|
299
|
+
def IsCollinear(vectorA, vectorB, tolerance=0.1):
|
|
300
|
+
"""
|
|
301
|
+
Returns True if the input vectors are collinear. Returns False otherwise.
|
|
302
|
+
|
|
303
|
+
Parameters
|
|
304
|
+
----------
|
|
305
|
+
vectorA : list
|
|
306
|
+
The first input vector.
|
|
307
|
+
vectorB : list
|
|
308
|
+
The second input vector.
|
|
309
|
+
|
|
310
|
+
Returns
|
|
311
|
+
-------
|
|
312
|
+
bool
|
|
313
|
+
Returns True if the input vectors are collinear. Returns False otherwise.
|
|
314
|
+
"""
|
|
315
|
+
|
|
316
|
+
return Vector.Angle(vectorA, vectorB) < tolerance
|
|
317
|
+
|
|
318
|
+
@staticmethod
|
|
319
|
+
def Magnitude(vector, mantissa=4):
|
|
320
|
+
"""
|
|
321
|
+
Returns the magnitude of the input vector.
|
|
322
|
+
|
|
323
|
+
Parameters
|
|
324
|
+
----------
|
|
325
|
+
vector : list
|
|
326
|
+
The input vector.
|
|
327
|
+
mantissa : int
|
|
328
|
+
The length of the desired mantissa. The default is 4.
|
|
329
|
+
|
|
330
|
+
Returns
|
|
331
|
+
-------
|
|
332
|
+
float
|
|
333
|
+
The magnitude of the input vector.
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
return round(np.linalg.norm(np.array(vector)), mantissa)
|
|
337
|
+
|
|
338
|
+
@staticmethod
|
|
339
|
+
def Multiply(vector, magnitude, tolerance=0.0001):
|
|
340
|
+
"""
|
|
341
|
+
Multiplies the input vector by the input magnitude.
|
|
342
|
+
|
|
343
|
+
Parameters
|
|
344
|
+
----------
|
|
345
|
+
vector : list
|
|
346
|
+
The input vector.
|
|
347
|
+
magnitude : float
|
|
348
|
+
The input magnitude.
|
|
349
|
+
tolerance : float, optional
|
|
350
|
+
the desired tolerance. The default is 0.0001.
|
|
351
|
+
|
|
352
|
+
Returns
|
|
353
|
+
-------
|
|
354
|
+
list
|
|
355
|
+
The created vector that multiplies the input vector by the input magnitude.
|
|
356
|
+
|
|
357
|
+
"""
|
|
358
|
+
oldMag = 0
|
|
359
|
+
for value in vector:
|
|
360
|
+
oldMag += value ** 2
|
|
361
|
+
oldMag = oldMag ** 0.5
|
|
362
|
+
if oldMag < tolerance:
|
|
363
|
+
return [0,0,0]
|
|
364
|
+
newVector = []
|
|
365
|
+
for i in range(len(vector)):
|
|
366
|
+
newVector.append(vector[i] * magnitude / oldMag)
|
|
367
|
+
return newVector
|
|
368
|
+
|
|
369
|
+
@staticmethod
|
|
370
|
+
def Normalize(vector):
|
|
371
|
+
"""
|
|
372
|
+
Returns a normalized vector of the input vector. A normalized vector has the same direction as the input vector, but its magnitude is 1.
|
|
373
|
+
|
|
374
|
+
Parameters
|
|
375
|
+
----------
|
|
376
|
+
vector : list
|
|
377
|
+
The input vector.
|
|
378
|
+
|
|
379
|
+
Returns
|
|
380
|
+
-------
|
|
381
|
+
list
|
|
382
|
+
The normalized vector.
|
|
383
|
+
"""
|
|
384
|
+
|
|
385
|
+
return list(vector / np.linalg.norm(vector))
|
|
386
|
+
|
|
387
|
+
@staticmethod
|
|
388
|
+
def North():
|
|
389
|
+
"""
|
|
390
|
+
Returns the vector representing the *north* direction. In Topologic, the positive YAxis direction is considered *north* ([0,1,0]).
|
|
391
|
+
|
|
392
|
+
Returns
|
|
393
|
+
-------
|
|
394
|
+
list
|
|
395
|
+
The vector representing the *north* direction.
|
|
396
|
+
"""
|
|
397
|
+
return [0,1,0]
|
|
398
|
+
|
|
399
|
+
@staticmethod
|
|
400
|
+
def NorthEast():
|
|
401
|
+
"""
|
|
402
|
+
Returns the vector representing the *northeast* direction. In Topologic, the positive YAxis direction is considered *north* and the positive XAxis direction is considered *east*. Therefore *northeast* is ([1,1,0]).
|
|
403
|
+
|
|
404
|
+
Returns
|
|
405
|
+
-------
|
|
406
|
+
list
|
|
407
|
+
The vector representing the *northeast* direction.
|
|
408
|
+
"""
|
|
409
|
+
return [1,1,0]
|
|
410
|
+
|
|
411
|
+
@staticmethod
|
|
412
|
+
def NorthWest():
|
|
413
|
+
"""
|
|
414
|
+
Returns the vector representing the *northwest* direction. In Topologic, the positive YAxis direction is considered *north* and the negative XAxis direction is considered *west*. Therefore *northwest* is ([-1,1,0]).
|
|
415
|
+
|
|
416
|
+
Returns
|
|
417
|
+
-------
|
|
418
|
+
list
|
|
419
|
+
The vector representing the *northwest* direction.
|
|
420
|
+
"""
|
|
421
|
+
return [-1,1,0]
|
|
422
|
+
|
|
423
|
+
@staticmethod
|
|
424
|
+
def Reverse(vector):
|
|
425
|
+
"""
|
|
426
|
+
Returns a reverse vector of the input vector. A reverse vector multiplies all components by -1.
|
|
427
|
+
|
|
428
|
+
Parameters
|
|
429
|
+
----------
|
|
430
|
+
vector : list
|
|
431
|
+
The input vector.
|
|
432
|
+
|
|
433
|
+
Returns
|
|
434
|
+
-------
|
|
435
|
+
list
|
|
436
|
+
The normalized vector.
|
|
437
|
+
"""
|
|
438
|
+
if not isinstance(vector, list):
|
|
439
|
+
return None
|
|
440
|
+
return [x*-1 for x in vector]
|
|
441
|
+
|
|
442
|
+
@staticmethod
|
|
443
|
+
def SetMagnitude(vector: list, magnitude: float) -> list:
|
|
444
|
+
"""
|
|
445
|
+
Sets the magnitude of the input vector to the input magnitude.
|
|
446
|
+
|
|
447
|
+
Parameters
|
|
448
|
+
----------
|
|
449
|
+
vector : list
|
|
450
|
+
The input vector.
|
|
451
|
+
magnitude : float
|
|
452
|
+
The desired magnitude.
|
|
453
|
+
|
|
454
|
+
Returns
|
|
455
|
+
-------
|
|
456
|
+
list
|
|
457
|
+
The created vector.
|
|
458
|
+
"""
|
|
459
|
+
return (Vector.Multiply(vector=Vector.Normalize(vector), magnitude=magnitude))
|
|
460
|
+
|
|
461
|
+
@staticmethod
|
|
462
|
+
def South():
|
|
463
|
+
"""
|
|
464
|
+
Returns the vector representing the *south* direction. In Topologic, the negative YAxis direction is considered *south* ([0,-1,0]).
|
|
465
|
+
|
|
466
|
+
Returns
|
|
467
|
+
-------
|
|
468
|
+
list
|
|
469
|
+
The vector representing the *south* direction.
|
|
470
|
+
"""
|
|
471
|
+
return [0,-1,0]
|
|
472
|
+
|
|
473
|
+
@staticmethod
|
|
474
|
+
def SouthEast():
|
|
475
|
+
"""
|
|
476
|
+
Returns the vector representing the *southeast* direction. In Topologic, the negative YAxis direction is considered *south* and the positive XAxis direction is considered *east*. Therefore *southeast* is ([1,-1,0]).
|
|
477
|
+
|
|
478
|
+
Returns
|
|
479
|
+
-------
|
|
480
|
+
list
|
|
481
|
+
The vector representing the *southeast* direction.
|
|
482
|
+
"""
|
|
483
|
+
return [1,-1,0]
|
|
484
|
+
|
|
485
|
+
@staticmethod
|
|
486
|
+
def SouthWest():
|
|
487
|
+
"""
|
|
488
|
+
Returns the vector representing the *southwest* direction. In Topologic, the negative YAxis direction is considered *south* and the negative XAxis direction is considered *west*. Therefore *southwest* is ([-1,-1,0]).
|
|
489
|
+
|
|
490
|
+
Returns
|
|
491
|
+
-------
|
|
492
|
+
list
|
|
493
|
+
The vector representing the *southwest* direction.
|
|
494
|
+
"""
|
|
495
|
+
return [-1,-1,0]
|
|
496
|
+
|
|
497
|
+
@staticmethod
|
|
498
|
+
def Up():
|
|
499
|
+
"""
|
|
500
|
+
Returns the vector representing the up direction. In Topologic, the positive ZAxis direction is considered "up" ([0,0,1]).
|
|
501
|
+
|
|
502
|
+
Returns
|
|
503
|
+
-------
|
|
504
|
+
list
|
|
505
|
+
The vector representing the "up" direction.
|
|
506
|
+
"""
|
|
507
|
+
return [0,0,1]
|
|
508
|
+
|
|
509
|
+
@staticmethod
|
|
510
|
+
def West():
|
|
511
|
+
"""
|
|
512
|
+
Returns the vector representing the *west* direction. In Topologic, the negative XAxis direction is considered *west* ([-1,0,0]).
|
|
513
|
+
|
|
514
|
+
Returns
|
|
515
|
+
-------
|
|
516
|
+
list
|
|
517
|
+
The vector representing the *west* direction.
|
|
518
|
+
"""
|
|
519
|
+
return [-1,0,0]
|
|
520
|
+
|
|
521
|
+
@staticmethod
|
|
522
|
+
def XAxis():
|
|
523
|
+
"""
|
|
524
|
+
Returns the vector representing the XAxis ([1,0,0])
|
|
525
|
+
|
|
526
|
+
Returns
|
|
527
|
+
-------
|
|
528
|
+
list
|
|
529
|
+
The vector representing the XAxis.
|
|
530
|
+
"""
|
|
531
|
+
return [1,0,0]
|
|
532
|
+
|
|
533
|
+
@staticmethod
|
|
534
|
+
def YAxis():
|
|
535
|
+
"""
|
|
536
|
+
Returns the vector representing the YAxis ([0,1,0])
|
|
537
|
+
|
|
538
|
+
Returns
|
|
539
|
+
-------
|
|
540
|
+
list
|
|
541
|
+
The vector representing the YAxis.
|
|
542
|
+
"""
|
|
543
|
+
return [0,1,0]
|
|
544
|
+
|
|
545
|
+
@staticmethod
|
|
546
|
+
def ZAxis():
|
|
547
|
+
"""
|
|
548
|
+
Returns the vector representing the ZAxis ([0,0,1])
|
|
549
|
+
|
|
550
|
+
Returns
|
|
551
|
+
-------
|
|
552
|
+
list
|
|
553
|
+
The vector representing the ZAxis.
|
|
554
|
+
"""
|
|
555
|
+
return [0,0,1]
|