MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / calculate_unit_vector

Function calculate_unit_vector

src/ext/makerbot_driver/Gcode/Utils.py:211–231  ·  view source on GitHub ↗

Calculate the unit vector of a given 5D vector @param list vector: A 5D vector @return list: The 5D equivalent of the vector

(vector)

Source from the content-addressed store, hash-verified

209
210
211def calculate_unit_vector(vector):
212 """ Calculate the unit vector of a given 5D vector
213
214 @param list vector: A 5D vector
215 @return list: The 5D equivalent of the vector
216 """
217 if len(vector) != 5:
218 raise makerbot_driver.errors.PointLengthError(
219 "Expected list of length 5, got length %i" % (len(vector)))
220
221 magnitude = calculate_vector_magnitude(vector)
222
223 # Check if this is a null vector
224 if magnitude == 0:
225 return [0, 0, 0, 0, 0]
226
227 unitVector = []
228 for val in vector:
229 unitVector.append(val / magnitude)
230
231 return unitVector
232
233
234def get_safe_feedrate(displacement_vector, max_feedrates, target_feedrate):

Callers

nothing calls this directly

Calls 2

appendMethod · 0.80

Tested by

no test coverage detected