Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersecting Line with Circle does not work #8

Open
mnesarco opened this issue Jul 13, 2020 · 2 comments
Open

Intersecting Line with Circle does not work #8

mnesarco opened this issue Jul 13, 2020 · 2 comments

Comments

@mnesarco
Copy link

mnesarco commented Jul 13, 2020

Intersecting a Line with a Circle must result in zero, one or two intersection points, but in this example it returns zero points where the Line is actually intersecting the circle at two points:

circle = CircleByNormal(Point(0, 0, 0), Direction(0, 0, 1), 20).circle
line = LineByVector(Point(0, 0, 0), Direction(0, 1, 0)).line
points = IntersectCurveCurve(circle, line).points
print(f"points={points}")

Result:

points=[]

@trelau
Copy link
Owner

trelau commented Jul 19, 2020

Looks like an OCCT bug. When I use a fininte curve (a line is infinite) the intersection works:

circle = CircleByNormal(Point(0, 0, 0), Direction(0, 0, 1), 20).circle
line = LineByVector(Point(0, 0, 0), Direction(0, 1, 0)).line
line = TrimmedCurveByPoints(line, Point(0, -100, 0), Point(0, 100, 0)).curve
points = IntersectCurveCurve(circle, line).points

image

I'll add a unit test for this failing case with a line and hopefully a future OCCT update will fix this case. Until then, are you able to work around it by using a finite curve (either trim the line as shown or interpolate two points using a NURBS curve)?

@mnesarco
Copy link
Author

mnesarco commented Jul 19, 2020

Hi @trelau ,
Yes I have noted that intersections with infinite curves does not work in some cases but i don't know why or when.
I am currently using only NURBS based line segments to do intersections as a workaround.

BTW I am using this code that maybe can be part of AFEM:

class LineSegmentByPoints:
    """
    Create a Line segment between two points.

    :param vector_like p1: Start point.
    :param vector_like p2: End point.
    """

    __slots__ = ('_segment',)

    def __init__(self, p1, p2):
        self._segment = NurbsCurveByInterp([p1, p2]).curve

    @property
    def segment(self):
        return self._segment

... And for Beziers:

class BezierCurve(Curve):
    """
    Bezier curve around ``Geom_BezierCurve``.
    """
    _OCC_TYPE = Geom_BezierCurve

    @classmethod
    def by_data(cls, cp, weights=None):
        """
        Create a Bezier curve by data.

        :param collections.Sequence(point_like) cp: Control points.
        :param collections.Sequence(float) weights: Weights of control points.
        """
        tcol_cp = occ_utils.to_tcolgp_array1_pnt(cp)
        if weights is None:
            weights = [1.] * tcol_cp.Length()
        tcol_weights = occ_utils.to_tcolstd_array1_real(weights)

        geom_crv = Geom_BezierCurve(tcol_cp, tcol_weights)
        return cls(geom_crv)


class BezierCurveByPoints:
    """
    Create a Bezier curve by control points.

    :param collections.Sequence(point_like) qp: Control points.
    :param collections.Sequence(float) weights: Poles weights.
    """

    __slots__ = ('_c',)

    def __init__(self, qp, weights=None):
        self._c = BezierCurve.by_data(qp, weights)

    @property
    def curve(self) -> BezierCurve:
        """
        The Bezier curve.
        """
        return self._c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants