7
$\begingroup$

I can draw a polygon with a curved edge using B-splines or Bézier curves:

Graphics[{Line[{{-1, -1}, {1, 2}, {3, -2}, {1, -4}}],
          BSplineCurve[{{-1, -1}, {1, -3}, {-0.75, -2}, {1, -4}}]}]

Curved polygon

My question is: how can I then color the inside of this polygon with a color of my choosing?

$\endgroup$
1
  • 2
    $\begingroup$ Check FilledCurve $\endgroup$
    – Kuba
    Commented Apr 30, 2020 at 11:59

1 Answer 1

10
$\begingroup$
g1 = Graphics[{Line[{{-1, -1}, {1, 2}, {3, -2}, {1, -4}}], 
    BSplineCurve[{{-1, -1}, {1, -3}, {-0.75, -2}, {1, -4}}]}];

BoundaryDiscretizeGraphics[g1, MeshCellStyle -> {1 -> Red, 2 -> LightYellow}]

enter image description here

Also

g1 /. {Line[x_], BSplineCurve[y_]} :> 
  Module[{ls = Join[x, BSplineFunction[y] /@ Subdivide[50]]},
   {EdgeForm[Red], LightGreen, Polygon[ls[[First@FindCurvePath[ls]]]]}]

enter image description here

and

Graphics[{EdgeForm[Red], LightCyan, 
  FilledCurve[{BSplineCurve[{{-1, -1}, {1, -3}, {-0.75, -2}, {1, -4}}], 
    Line[Reverse @ {{-1, -1}, {1, 2}, {3, -2}, {1, -4}}]}]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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