예제 #1
0
def test_intersect_cylinder_line(cylinder, line, array_expected_a,
                                 array_expected_b):

    point_a, point_b = cylinder.intersect_line(line, n_digits=9)

    point_expected_a = Point(array_expected_a)
    point_expected_b = Point(array_expected_b)

    assert point_a.is_close(point_expected_a)
    assert point_b.is_close(point_expected_b)
예제 #2
0
def test_intersect_cylinder_line_with_caps(cylinder, line, array_expected_a,
                                           array_expected_b):

    point_a, point_b = cylinder.intersect_line(line, infinite=False)

    point_expected_a = Point(array_expected_a)
    point_expected_b = Point(array_expected_b)

    assert point_a.is_close(point_expected_a)
    assert point_b.is_close(point_expected_b)
예제 #3
0
def test_is_close(array):

    vector = Vector(array)
    point = Point(array)

    assert point.size == vector.size

    assert point.is_close(vector)
    assert vector.is_close(point)

    assert point.is_close(array)
    assert vector.is_close(array)
예제 #4
0
def test_add_subtract(arrays):

    array_point, array_vector = arrays

    point = Point(array_point)
    vector = Vector(array_vector)

    point_2 = point + array_vector
    assert math.isclose(point.distance_point(point_2), vector.norm())

    point_3 = point_2 - array_vector
    assert point.is_close(point_3)
예제 #5
0
def test_from_points(arrays):

    array_a, array_b = arrays

    point_a = Point(array_a)
    vector_ab = Vector.from_points(array_a, array_b)

    assert (point_a + vector_ab).is_close(array_b)
예제 #6
0
def test_are_collinear(arrays):

    array_a, array_b, array_c = arrays

    assert Points([array_a, array_a, array_a]).are_collinear(tol=ATOL)
    assert Points([array_a, array_a, array_b]).are_collinear(tol=ATOL)

    all_different = not (Point(array_a).is_close(array_b, abs_tol=ATOL)
                         or Point(array_b).is_close(array_c, abs_tol=ATOL))

    if Points([array_a, array_b, array_c]).are_collinear() and all_different:

        line_ab = Line.from_points(array_a, array_b)
        line_bc = Line.from_points(array_b, array_c)

        assert line_ab.contains_point(array_c, abs_tol=ATOL)
        assert line_bc.contains_point(array_a, abs_tol=ATOL)

        assert line_ab.is_coplanar(line_bc)
예제 #7
0
def project_on_vector(L, R, M):
    '''gets left and closest Right and measured points, returns projection on the vector btw. R&L of M'''
    line = Line(point = L[0:2], direction=R[0:2])
    point = Point(M[0:2])

    line_const = line2pts(L, R)

    point_projected = line.project_point(point)
    line_projection = Line.from_points(point, point_projected)

    result = {"Point" : point_projected,
              "Line" : line_projection,
              "Distance": distance_pt2line(line_const["m"], line_const["b"], M[0:2])}
    return result
예제 #8
0
def points(draw, dim):
    """
    Return a strategy which generates Point objects.

    Parameters
    ----------
    dim : int
        Dimension of the object.

    Returns
    -------
    LazyStrategy
        Hypothesis strategy.

    Examples
    --------
    >>> from hypothesis import find
    >>> from tests.property.strategies import points

    >>> find(points(3), lambda x: True)
    Point([0., 0., 0.])

    """
    return Point(draw(arrays_fixed(dim)))
예제 #9
0
def test_add(arrays):

    array_a, array_b = arrays

    # Add and subtract the array to obtain the same point.
    assert (Point(array_a) + array_b - array_b).is_close(array_a)
예제 #10
0
from skspatial.objects import Circle
from skspatial.objects import Cylinder
from skspatial.objects import Line
from skspatial.objects import Plane
from skspatial.objects import Point
from skspatial.objects import Points
from skspatial.objects import Sphere
from skspatial.objects import Triangle
from skspatial.objects import Vector


@pytest.mark.parametrize(
    ("obj_spatial", "repr_expected"),
    [
        (Point([0]), "Point([0])"),
        (Point([0, 0]), "Point([0, 0])"),
        (Point([0.5, 0]), "Point([0.5, 0. ])"),
        (Point([-11, 0]), "Point([-11,   0])"),
        (Vector([-11, 0]), "Vector([-11,   0])"),
        (Vector([-11.0, 0.0]), "Vector([-11.,   0.])"),
        (Vector([0, 0]), "Vector([0, 0])"),
        (Vector([0.5, 0]), "Vector([0.5, 0. ])"),
        (Points([[1.5, 2], [5, 3]]), "Points([[1.5, 2. ],\n        [5. , 3. ]])"),
        (Line([0, 0], [1, 0]), "Line(point=Point([0, 0]), direction=Vector([1, 0]))"),
        (Line([-1, 2, 3], [5, 4, 2]), "Line(point=Point([-1,  2,  3]), direction=Vector([5, 4, 2]))"),
        (Line(np.zeros(2), [1, 0]), "Line(point=Point([0., 0.]), direction=Vector([1, 0]))"),
        (Plane([0, 0], [1, 0]), "Plane(point=Point([0, 0]), normal=Vector([1, 0]))"),
        (Plane([-1, 2, 3], [5, 4, 2]), "Plane(point=Point([-1,  2,  3]), normal=Vector([5, 4, 2]))"),
        (Circle([0, 0], 1), "Circle(point=Point([0, 0]), radius=1)"),
        (Circle([0, 0], 2.5), "Circle(point=Point([0, 0]), radius=2.5)"),
예제 #11
0
"""
Point-Plane Projection
======================

Project a point onto a plane.

"""
from skspatial.objects import Plane
from skspatial.objects import Point
from skspatial.objects import Vector
from skspatial.plotting import plot_3d


plane = Plane(point=[0, 0, 2], normal=[1, 0, 2])
point = Point([5, 9, 3])

point_projected = plane.project_point(point)
vector_projection = Vector.from_points(point, point_projected)


plot_3d(
    plane.plotter(lims_x=(0, 10), lims_y=(0, 15), alpha=0.3),
    point.plotter(s=75, c='k'),
    point_projected.plotter(c='r', s=75, zorder=3),
    vector_projection.plotter(point=point, c='k', linestyle='--'),
)
예제 #12
0
def test_equality(array):

    assert_array_equal(array, Point(array))
    assert_array_equal(array, Vector(array))
    assert_array_equal(array, np.array(array))
예제 #13
0
"""
2D Point-Line Projection
========================

Project a point onto a line.

"""
from skspatial.objects import Point, Line
from skspatial.plotting import plot_2d

line = Line(point=[0, 0], direction=[1, 1])
point = Point([1, 4])

point_projected = line.project_point(point)
line_projection = Line.from_points(point, point_projected)

_, ax = plot_2d(
    line.plotter(t_2=5, c='k'),
    line_projection.plotter(c='k', linestyle='--'),
    point.plotter(s=75, c='k'),
    point_projected.plotter(c='r', s=75, zorder=3),
)

ax.axis('equal')
예제 #14
0
        (Line([0, 0], [1, 1]), Line([0, 0], [0, 1]), True),
        (Line([-6, 7], [5, 90]), Line([1, 4], [-4, 5]), True),
        (Line([0, 0, 1], [1, 1, 0]), Line([0, 0, 0], [0, 1, 0]), False),
        (Line([0, 0, 1], [1, 1, 0]), Line([0, 0, 1], [0, 1, 0]), True),
        (Line([0, 0, 1], [1, 0, 1]), Line([0, 0, 1], [2, 0, 2]), True),
    ],
)
def test_is_coplanar(line_a, line_b, bool_expected):

    assert line_a.is_coplanar(line_b) == bool_expected


@pytest.mark.parametrize(
    ("line_a", "line_b"),
    [
        (Line([0, 0], [1, 1]), Point([0, 0])),
        (Line([0, 0, 0], [1, 1, 0]), Plane([0, 0, 0], [0, 0, 1])),
    ],
)
def test_is_coplanar_failure(line_a, line_b):

    message_expected = "The input must also be a line."

    with pytest.raises(TypeError, match=message_expected):
        line_a.is_coplanar(line_b)


@pytest.mark.parametrize(
    ("point", "point_line", "vector_line", "point_expected", "dist_expected"),
    [
        ([0, 5], [0, 0], [0, 1], [0, 5], 0),
예제 #15
0
        return 0

def poly_model(x_kn, x_end, z_known):
    """ form of the fitting model is z = Ax(x-B)
        where B = x_end
        function
    """
    B = x_end
    A = z_known/(x_kn*(x_kn -B))

    return {"B": B, "A": A}

def predict(model, x):
    "predicts x for a given model"
    B = model["B"]
    A = model["A"]
    return A*x*(x-B)



if __name__ == "__main__":
    #test functions
    print(np.arange(30).reshape(15,2) + 10)
    print(closest(np.array([20, 20]),np.arange(30).reshape(15,2) + 10))

    line = Line(point=[0, 0], direction=[1, 1])
    point = Point([1, 4])

    point_projected = line.project_point(point)
    line_projection = Line.from_points(point, point_projected)
    print(point_projected)
예제 #16
0
def test_distance_points(array_a, array_b, dist_expected):

    point_a = Point(array_a)
    assert math.isclose(point_a.distance_point(array_b), dist_expected)