5
$\begingroup$

I want to create geometries. How to create shapes like this in Mathematica? enter image description here

$\endgroup$
6
$\begingroup$

Generally, graphics primitives like Polygon, Triangle, Disk and MeshRegion-related functions such as RegionDifference and RegionUnion may help you.

As a starting point for you, here is example D:

R = BoundaryDiscretizeRegion[
 RegionDifference[
  Rectangle[{0, 0}, {10, 2}],
  BoundaryDiscretizeRegion@RegionUnion[
    Triangle[{{2, 1}, {4, 1}, {3, 0}}],
    Disk[{7.5, 0.5}, 1/Sqrt[2]]
    ]
  ]
 ]

I suggest to look up the used symbols in the documentation. Moreover, each documentation page has links to further related symbols. See also Graphics for setting up scenes (including axes, coloring, filling style etc.)

$\endgroup$
7
$\begingroup$

Like Henrik says, it is possible to use the region functionality in Mathematica to define those regions using unions and complements. Another way to define regions is by specifying their boundaries. To this end, Mathematica has a function called FilledCurve:

Graphics[{
  FaceForm[LightBlue],
  EdgeForm[{Thick, Red}],
  FilledCurve@Line[{
     {0, 0},
     {2, 0},
     {3, 1},
     {4, 0},
     {7, 0},
     {7.5, 1},
     {8, 0},
     {10, 0},
     {10, 2},
     {0, 2}
     }]
  },
 Axes -> True,
 Ticks -> {Range[10], Range[2]},
 PlotRangePadding -> {{0, 1}, {0, 1}}
 ]

Mathematica graphics

To get the curved shapes, you may use graphics primitives such as BezierCurve and BSplineCurve.

Even if you choose to work with unions and complements you may want to use FilledCurve to create regions that you can work with. For example, there is no primitive that will allow you create those curved regions directly, but you can easily create them by combining e.g. BezierCurve and FilledCurve.

(Being able to use segments like BezierCurve is also one of the reasons why FilledCurve is preferred over Polygon; the simple example in this post could also be created using Polygon but it only works so long as the boundary consists of straight lines.)

This approach also handles geometries with holes in them, but I refer to the documentation for the details on that.

$\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.