コード例 #1
0
def select_closest_pt_from_list(Point, pt_list):
    closest_point = None
    distances = [Point.distance_to_point(pt) for pt in pt_list]
    distances.sort()
    min_dis = distances[0]
    for pt in pt_list:
        distance = Point.distance_to_point(pt)
        if distance == min_dis:
            closest_point = pt
    return closest_point, min_dis
コード例 #2
0
ファイル: vextrusion.py プロジェクト: dbt-ethz/compas_vol
    def get_distance(self, point):
        """
        single point distance function

        Parameters
        ----------
        point: :class:`compas.geometry.Point`
            The point in R<sup>3</sup> space to query for it's distance.
        Returns
        -------
        float
            The distance from the query point to the surface of the object.
        """

        if not isinstance(point, Point):
            point = Point(*point)

        point.transform(self.inversetransform)

        tp = Point(point[0], point[1], 0)
        cp = closest_point_on_polyline_xy(tp, self.polyline)
        d = tp.distance_to_point(cp)
        if is_point_in_polygon_xy(tp, self.polyline):
            d = -1.*d
        d = max(d, abs(point.z) - self.height / 2.0)
        return d
コード例 #3
0
 def get_distance(self, point):
     """
     single point distance function
     """
     if not isinstance(point, Point):
         point = Point(*point)
     p = closest_point_on_segment(point, self.segment)
     return point.distance_to_point(p) - self.radius
コード例 #4
0
ファイル: vextrusion.py プロジェクト: wenqian157/compas_vol
    def get_distance(self, point):
        if not isinstance(point, Point):
            point = Point(*point)

        m = matrix_from_frame(self.frame)
        mi = matrix_inverse(m)
        point.transform(mi)

        tp = Point(point[0], point[1], 0)
        cp = closest_point_on_polyline_xy(tp, self.polyline)
        d = tp.distance_to_point(cp)
        if is_point_in_polygon_xy(tp, self.polyline):
            d = -1. * d
        d = max(d, abs(point.z) - self.height / 2.0)
        return d
コード例 #5
0
    def get_distance(self, point):
        """
        single point distance function
        """
        if not isinstance(point, Point):
            point = Point(*point)

        distances = [(point.distance_to_point(p), p) for p in self.points]
        sortpoints = sorted(distances, key=lambda x: x[0])
        closest = sortpoints[0][1]

        vc = Vector(*closest)
        d1 = vc.dot(vc)

        secondc = sortpoints[1][1]
        vs = Vector(*secondc)
        v1 = Vector(*point) - (vc + vs) / 2
        v2 = vs - vc
        v2.unitize()
        d2 = v1.dot(v2)

        return abs(min(d1, d2)) - self.thickness / 2
コード例 #6
0
    from compas.geometry import Plane
    from compas.geometry import Line
    from compas.geometry import Polygon

    from compas.geometry import projection_matrix

    point = Point(0.0, 0.0, 0.0)
    normal = Vector(0.0, 0.0, 1.0)
    plane = Plane.from_point_and_normal(point, normal)
    line = Line([0.0, 0.0, 0.0], [1.0, 0.0, 0.0])
    triangle = Polygon([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]])
    polygon = Polygon([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0],
                       [0.0, 1.0, 0.0]])

    p = Point(1.0, 1.0, 1.0)

    print(repr(p))

    print(p.distance_to_point(point))
    print(p.distance_to_line(line))
    print(p.distance_to_plane(plane))
    print(p.in_triangle(triangle))

    # print(p.in_polygon(polygon))
    # print(p.in_polyhedron())

    # p.transform()
    # p.translate()
    # p.project_to_line()
    # p.project_to_plane()
コード例 #7
0
ファイル: vsphere.py プロジェクト: wenqian157/compas_vol
 def get_distance(self, point):
     if not isinstance(point, Point):
         point = Point(*point)
     d = point.distance_to_point(self.sphere.center)
     return d - self.sphere.radius