Skip to content

Instantly share code, notes, and snippets.

@NickShargan
Last active February 26, 2023 19:51
Show Gist options
  • Save NickShargan/dc72de87fcb3126b6817d6311f8e9e2e to your computer and use it in GitHub Desktop.
Save NickShargan/dc72de87fcb3126b6817d6311f8e9e2e to your computer and use it in GitHub Desktop.
import numpy as np
def get_coord_bazises(point_1, point_2):
""""Function defines coordinate system basizes: Oz as vector parrallel to line point_1, point_2
Ox as random orthogonal vector to Oz, and Oy as vector orthogonal to Oz and Ox.
"""
vec_z = point_2 - point_1
vec_z = vec_z / np.linalg.norm(vec_z)
# non-random value is used to make tests repeatable
random_point = [10, 10, 10]
vec_t = random_point - point_1
vec_x = np.cross(vec_z, vec_t)
# check that vec_t is not parralel with vec_z
axis_idx = 0
while vec_x[0] == 0.0 and vec_x[1] == 0.0 and vec_x[2] == 0.0:
random_point[axis_idx % 3] += 1
axis_idx += 1
vec_t = random_point - point_1
vec_x = np.cross(vec_z, vec_t)
vec_x = vec_x / np.linalg.norm(vec_x)
vec_y = np.cross(vec_z, vec_x)
return vec_x, vec_y, vec_z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment