3
$\begingroup$

How do you instruct Mathematica to return intersection points between curves as numerical values, when using ParametricRegion to represent at least one of the curves? For example, these are the regions for a line segment and a cubic Bezier curve:

cubicbez[a_, b_, c_, d_, t_] := (1 - t)^3*a + 3*(1 - t)^2*t*b + 3*(1 - t)*t^2*c + t^3*d

bezierRegion[{a_,b_,c_,d_}]:=ParametricRegion[cubicbez[a,b,c,d,t],{{t,0,1}}]

r1=Line[{{2,1},{4,7}}];
r2=bezierRegion[{{0,5},{9,6},{-2,4},{6,3}}];
ri=RegionIntersection[r1,r2];

Show[{Region[r1],Region[r2],Region[ri,BaseStyle->Red]},Frame->True]

Regions r1, r2 and ri

As you can see, Mathematica has no trouble finding the intersection points.

I then ask Mathematica to return the coordinates of the intersection points as follows:

MeshCoordinates[DiscretizeRegion[ri]]

which returns

{{3.20154, 4.60463}, {3.42285, 5.26855}}

when using Mathematica 12.3.0.0. I.e., one of the intersections points (the lower left one) is missing.

What would be the proper way to get the intersection points?

(N.B. I know that you can compute the intersections of a cubic Bezier curve and a line in other ways, e.g. algebraically using Cardano's formula, or using numerical methods, but I'd like to know how to use Mathematica's regions for that purpose.)

$\endgroup$
3
  • 5
    $\begingroup$ MeshCoordinates[DiscretizeRegion[ri, CoordinateBounds[ri]]] gives all three points. $\endgroup$
    – kglr
    Jun 7 at 7:14
  • 1
    $\begingroup$ With version 12.3 one can do: DiscretizeRegion[ri, CoordinateBounds[ri]] // MeshCoordinates or Solve[{x, y} \[Element] r1 && {x, y} \[Element] r2, {x, y}] // N. $\endgroup$
    – rmw
    Jun 7 at 8:39
  • 1
    $\begingroup$ Version 11.2 give me correct result with same code {{2.95674, 3.87023}, {3.20154, 4.60463}, {3.42285, 5.26855}} $\endgroup$
    – Alrubaie
    Jun 7 at 8:50
4
$\begingroup$

Using the two-argument form of DiscretizeRegion we get three points:

MeshCoordinates[DiscretizeRegion[ri, CoordinateBounds[ri]]]
 {{2.95674, 3.87023}, {3.20154, 4.60463}, {3.42285, 5.26855}}

FWIW, we can also use MeshPrimitives to get the three Points:

MeshPrimitives[DiscretizeRegion@ri, 0]
{Point[{2.95674, 3.87023}], Point[{3.20154, 4.60463}], Point[{3.42285, 5.26855}]}
$\endgroup$
1
  • $\begingroup$ The expression MeshPrimitives[DiscretizeRegion@ri, 0] yields only the latter two points for me. Maybe its a bug in Mathematica 12.3.0.0 ... . The option CoordinateBounds[ri], however, works nicely. $\endgroup$
    – FrankM
    Jun 7 at 13:01
3
$\begingroup$

We can also use RegionMember and Solve or Reduce to get the points.

sol = Solve[RegionMember[ri, {x, y}]]
{x, y} /. sol // N

{{2.95674, 3.87023}, {3.20154, 4.60463}, {3.42285, 5.26855}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.