Beispiel #1
0
    def point_to_cref(self, pnt, direction=None):
        """
        Project a point to reference curve.

        :param afem.geometry.entities.Point pnt: The point. Position will be
            updated.
        :param vector_like direction: Projection direction.

        :return: *True* if projected, *False* if not.
        :rtype: bool
        """
        proj = ProjectPointToCurve(pnt, self._cref, direction, update=True)
        if not proj.success:
            return False
        return True
Beispiel #2
0
    def invert_cref(self, pnt):
        """
        Invert the point on the reference curve.

        :param point_like pnt: The point.

        :return: The parameter on the reference curve. Returns *None* if no
            projection is found.
        :rtype: float or None

        :raise AttributeError: If part does not have a reference curve.
        """
        if not self.has_cref:
            msg = 'Part does not have a reference curve.'
            raise AttributeError(msg)

        proj = ProjectPointToCurve(pnt, self._cref)
        if proj.success:
            return proj.nearest_param
        return None
Beispiel #3
0
    def point_to_cref(self, pnt, direction=None):
        """
        Project a point to reference curve.

        :param afem.geometry.entities.Point pnt: The point. Position will be
            updated.
        :param vector_like direction: Projection direction.

        :return: *True* if projected, *False* if not.
        :rtype: bool

        :raise AttributeError: If part does not have a reference curve.
        """
        if not self.has_cref:
            msg = 'Part does not have a reference curve.'
            raise AttributeError(msg)

        proj = ProjectPointToCurve(pnt, self._cref, direction, update=True)
        if not proj.success:
            return False
        return True
Beispiel #4
0
def _param_on_adp_crv(adp_crv, shape, other_shape):
    """
    Determine the parameter on the adaptor curve by intersecting the shape.

    :param afem.adaptor.entities.AdaptorCurve adp_crv: The curve.
    :param afem.topology.entities.Shape shape: The shape that defines the
        curve. This should be the same shape that created the adaptor curve.
    :param afem.topology.entities.Shape other_shape: The other shape that
        intersects the adaptor curve and will be used to find the parameter.

    :return: The parameter on the curve or *None* if not found.
    :rtype: float or None
    """
    shape = IntersectShapes(shape, other_shape).shape
    verts = shape.vertices
    prms = [adp_crv.u1]
    for v in verts:
        pnt = v.point
        proj = ProjectPointToCurve(pnt, adp_crv)
        if proj.npts < 1:
            continue
        umin = proj.nearest_param
        prms.append(umin)
    return min(prms)
Beispiel #5
0
    def extract_curve(self, u1, v1, u2, v2, basis_shape=None):
        """
        Extract a trimmed curve within the reference surface between the
        parameters.

        :param float u1: First u-parameter.
        :param float v1: First v-parameter.
        :param float u2: Second u-parameter.
        :param float v2: Second v-parameter.
        :param basis_shape: The shape that will be used to intersect with
            the reference shape. If not provided a plane will be
            created using the *extract_plane()* method. The parameters
            should create points that are on or very near the intersection
            between these two shapes. If they are not they will be projected to
            the intersection which could yield unanticipated results.
        :type basis_shape: afem.geometry.entities.Surface or
            afem.topology.entities.Shape

        :return: The curve.
        :rtype: afem.geometry.entities.TrimmedCurve

        :raise RuntimeError: If method fails.
        """
        p1 = self.eval(u1, v1)
        p2 = self.eval(u2, v2)

        if basis_shape is None:
            basis_shape = self.extract_plane(u1, v1, u2, v2)
        basis_shape = Shape.to_shape(basis_shape)

        bop = IntersectShapes(basis_shape, self.sref_shape, approximate=True)
        shape = bop.shape

        edges = shape.edges
        builder = WiresByConnectedEdges(edges)
        if builder.nwires == 0:
            msg = 'Failed to extract any curves.'
            raise RuntimeError(msg)

        if builder.nwires == 1:
            wire = builder.wires[0]
        else:
            dist = DistancePointToShapes(p1, builder.wires)
            wire = dist.nearest_shape
        crv = wire.curve

        proj = ProjectPointToCurve(p1, crv)
        if not proj.success:
            msg = 'Failed to project point to reference curve.'
            raise RuntimeError(msg)
        u1c = proj.nearest_param

        proj = ProjectPointToCurve(p2, crv)
        if not proj.success:
            msg = 'Failed to project point to reference curve.'
            raise RuntimeError(msg)
        u2c = proj.nearest_param

        if u1c > u2c:
            crv.reverse()
            u1c, u2c = crv.reversed_u(u1c), crv.reversed_u(u2c)

        return TrimmedCurve.by_parameters(crv, u1c, u2c)