From 3ec71b0a692b9c17300b865082436d212459267c Mon Sep 17 00:00:00 2001 From: koienshi <55773406+koienshi@users.noreply.github.com> Date: Mon, 1 Mar 2021 20:57:06 -0500 Subject: [PATCH 1/2] get angle method --- brainlit/utils/Neuron_trace.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/brainlit/utils/Neuron_trace.py b/brainlit/utils/Neuron_trace.py index f5037963a..6f7849c97 100755 --- a/brainlit/utils/Neuron_trace.py +++ b/brainlit/utils/Neuron_trace.py @@ -856,3 +856,29 @@ def _swc2skeleton(self, swc_file, benchmarking=False, origin=None): skel.vertex_color[:, :] = color return skel + + def get_angle(v1, v2): + """ + Finds angle between two vectors + + Parameters + ---------- + v1 : array-like + List representing a vector. + + v2 : array-like + List representing a second vector. + + Returns + ------- + angle : float + Resulting angle calculated between the two vectors. + """ + # find unit vectors that are in the same direction + unit_v1 = v1 / np.linalg.norm(v1) + unit_v2 = v2 / np.linalg.norm(v2) + + dot_product = np.dot(unit_v1, unit_v2) # dot product = cosine of the angle between 2 vectors + angle = np.arccos(dot_product) # take arccos + + return angle \ No newline at end of file From d56718723a467cf3e4d06ac616b9df2aa18ecdd3 Mon Sep 17 00:00:00 2001 From: koienshi <55773406+koienshi@users.noreply.github.com> Date: Mon, 1 Mar 2021 21:07:47 -0500 Subject: [PATCH 2/2] black --- brainlit/utils/Neuron_trace.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/brainlit/utils/Neuron_trace.py b/brainlit/utils/Neuron_trace.py index 6f7849c97..097d1999b 100755 --- a/brainlit/utils/Neuron_trace.py +++ b/brainlit/utils/Neuron_trace.py @@ -877,8 +877,10 @@ def get_angle(v1, v2): # find unit vectors that are in the same direction unit_v1 = v1 / np.linalg.norm(v1) unit_v2 = v2 / np.linalg.norm(v2) - - dot_product = np.dot(unit_v1, unit_v2) # dot product = cosine of the angle between 2 vectors - angle = np.arccos(dot_product) # take arccos - return angle \ No newline at end of file + dot_product = np.dot( + unit_v1, unit_v2 + ) # dot product = cosine of the angle between 2 vectors + angle = np.arccos(dot_product) # take arccos + + return angle