<commit_before>from __future__ import division
import numpy as np

from Space.Coordinates import Cartesian
from Space.Coordinates.transforms import unit_vector
from Space.Curve.Parametric import Helix, Arc


def helix_between_two_points(coordinate_system, point1, point2, radius=1, loops=1, right=True):
    distance = np.sqrt(np.dot(point2 - point1, point2 - point1))
    direction = unit_vector(point2 - point1)
    print direction
    origin = coordinate_system.to_parent(point1)
    helix_coordinate_system = Cartesian(basis=np.copy(coordinate_system.basis), origin=np.copy(origin),
                                        name='Helix coordinate system')
    R = np.sqrt(direction[0]**2 + direction[1]**2)
    theta = np.arcsin(R)
    if R == 0:
        phi = 0
    else:
        phi = np.arccos(direction[0] / R)
    print R, np.rad2deg(theta), np.rad2deg(phi)
    helix_coordinate_system.rotate_axis_angle(helix_coordinate_system.basis[2, :], phi)
    helix_coordinate_system.rotate_axis_angle(helix_coordinate_system.basis[1, :], theta)
    h = distance / int(loops)
    path = Helix(name='Right Helix', coordinate_system=helix_coordinate_system,
                 radius=radius, pitch=h, start=0, stop=np.pi * 2 * int(loops), right=right)
    return path


def arc_between_two_points(coordinate_system, point1, point2, r=1, right=True):
    direction = unit_vector(point2 - point1)
    origin = coordinate_system.to_parent(point1)
    arc_coordinate_system = Cartesian(basis=np.copy(coordinate_system.basis), origin=np.copy(origin),
                                      name='Arc coordinate_system')
    R = np.sqrt(direction[0]**2 + direction[1]**2)
    theta = np.arcsin(R)
    if R == 0:
        phi = 0
    else:
        phi = np.arccos(direction[0] / R)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 2], -phi)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 1], -theta)
    local_point2 = arc_coordinate_system.to_local(coordinate_system.to_parent(point2)).ravel()
    origin2 = np.array([np.sqrt((2 * r)**2 - local_point2[2]**2), 0, 0])
    print 'Arc coordinate_system origin offset:', origin2
    distance = np.sqrt(np.dot(local_point2 - origin2, local_point2 - origin2))
    print distance
    direction = unit_vector(local_point2 - origin2)
    print direction
    origin = arc_coordinate_system.to_parent(origin2)
    arc_coordinate_system = Cartesian(basis=np.copy(arc_coordinate_system.basis), origin=np.copy(origin),
                                      name='Arc coordinate_system')
    R = np.sqrt(direction[0]**2 + direction[1]**2)
    theta = np.arcsin(R)
    if R == 0:
        phi = 0
    else:
        phi = np.arccos(direction[0] / R)
    print R, np.rad2deg(theta), np.rad2deg(phi)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 2], -phi)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 1], -theta)
    local_point1 = arc_coordinate_system.to_local(coordinate_system.to_parent(point1)).ravel() - np.array([0, 0, r]).ravel()
    local_point2 = arc_coordinate_system.to_local(coordinate_system.to_parent(point2)).ravel() - np.array([0, 0, r]).ravel()
    start = np.pi - np.arccos(local_point1[2] / r)
    stop = np.pi - np.arccos(local_point2[2] / r)
    print start, stop
    path = Arc(coordinate_system=arc_coordinate_system, r=r, start=start, stop=stop, right=True)
    return path
<commit_msg>Pathfinder now finds helix path between two pints. Initial version.<commit_after>from __future__ import division
import numpy as np

from Space.Coordinates import Cartesian, transforms
from Space.Coordinates.transforms import unit_vector
from Space.Curve.Parametric import Helix, Arc


def helix_between_two_points(coordinate_system, point1, point2, radius=1, loops=1, right=True):
    direction = point2 - point1
    distance = np.sqrt(np.dot(direction, direction))
    print direction
    origin = coordinate_system.to_parent(point1)
    helix_coordinate_system = Cartesian(basis=np.copy(coordinate_system.basis), origin=np.copy(origin),
                                        name='Helix coordinate system')
    r_theta_phi = transforms.cartesian_to_spherical(direction)
    print r_theta_phi
    helix_coordinate_system.rotate_axis_angle([0, 0, 1], r_theta_phi[2])
    helix_coordinate_system.rotate_axis_angle([0, 1, 0], r_theta_phi[1])
    pitch = distance / int(loops)
    name = 'Right Helix' if right else 'Left Helix'
    path = Helix(name=name, coordinate_system=helix_coordinate_system,
                 radius=radius, pitch=pitch, start=0, stop=np.pi * 2 * int(loops), right=right)
    return path


def arc_between_two_points(coordinate_system, point1, point2, r=1, right=True):
    direction = unit_vector(point2 - point1)
    origin = coordinate_system.to_parent(point1)
    arc_coordinate_system = Cartesian(basis=np.copy(coordinate_system.basis), origin=np.copy(origin),
                                      name='Arc coordinate_system')
    R = np.sqrt(direction[0]**2 + direction[1]**2)
    theta = np.arcsin(R)
    if R == 0:
        phi = 0
    else:
        phi = np.arccos(direction[0] / R)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 2], -phi)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 1], -theta)
    local_point2 = arc_coordinate_system.to_local(coordinate_system.to_parent(point2)).ravel()
    origin2 = np.array([np.sqrt((2 * r)**2 - local_point2[2]**2), 0, 0])
    print 'Arc coordinate_system origin offset:', origin2
    distance = np.sqrt(np.dot(local_point2 - origin2, local_point2 - origin2))
    print distance
    direction = unit_vector(local_point2 - origin2)
    print direction
    origin = arc_coordinate_system.to_parent(origin2)
    arc_coordinate_system = Cartesian(basis=np.copy(arc_coordinate_system.basis), origin=np.copy(origin),
                                      name='Arc coordinate_system')
    R = np.sqrt(direction[0]**2 + direction[1]**2)
    theta = np.arcsin(R)
    if R == 0:
        phi = 0
    else:
        phi = np.arccos(direction[0] / R)
    print R, np.rad2deg(theta), np.rad2deg(phi)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 2], -phi)
    arc_coordinate_system.rotate_axis_angle(arc_coordinate_system.basis[:, 1], -theta)
    local_point1 = arc_coordinate_system.to_local(coordinate_system.to_parent(point1)).ravel() - np.array([0, 0, r]).ravel()
    local_point2 = arc_coordinate_system.to_local(coordinate_system.to_parent(point2)).ravel() - np.array([0, 0, r]).ravel()
    start = np.pi - np.arccos(local_point1[2] / r)
    stop = np.pi - np.arccos(local_point2[2] / r)
    print start, stop
    path = Arc(coordinate_system=arc_coordinate_system, r=r, start=start, stop=stop, right=True)
    return path

{'fraction_non_alphanumeric': 0.11894983866236433, 'fraction_numerical': 0.02244059841595776, 'mean_word_length': 3.788623595505618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2106050', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2222, 'n_words': 417}