Skip to main content
Address version dependency
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

AnotherIn Mathematica 12 BoundaryMeshRegion objects can be used as a Graphics primitive. So, another idea is to use a BoundaryMeshRegion as your primitive. For example:

Typeset`MakeBoxes[
    CutoutEllipse[center_, out_, in_],
    form_,
    Graphics
] := With[
    {
    new = Replace[
        RegionDifference[Disk[center, out], Disk[center, in]],
        b_BooleanRegion :> BoundaryDiscretizeRegion[b]
    ]
    },
    Typeset`MakeBoxes[new, form, Graphics]
]

Examples:

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, .9 {1,2}]}]

enter image description here

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, 1.1 {1,2}]}]

enter image description here

You can use this answer to get the above approach to work in earlier versions of Mathematica.

Another idea is to use a BoundaryMeshRegion as your primitive. For example:

Typeset`MakeBoxes[
    CutoutEllipse[center_, out_, in_],
    form_,
    Graphics
] := With[
    {
    new = Replace[
        RegionDifference[Disk[center, out], Disk[center, in]],
        b_BooleanRegion :> BoundaryDiscretizeRegion[b]
    ]
    },
    Typeset`MakeBoxes[new, form, Graphics]
]

Examples:

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, .9 {1,2}]}]

enter image description here

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, 1.1 {1,2}]}]

enter image description here

In Mathematica 12 BoundaryMeshRegion objects can be used as a Graphics primitive. So, another idea is to use a BoundaryMeshRegion as your primitive. For example:

Typeset`MakeBoxes[
    CutoutEllipse[center_, out_, in_],
    form_,
    Graphics
] := With[
    {
    new = Replace[
        RegionDifference[Disk[center, out], Disk[center, in]],
        b_BooleanRegion :> BoundaryDiscretizeRegion[b]
    ]
    },
    Typeset`MakeBoxes[new, form, Graphics]
]

Examples:

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, .9 {1,2}]}]

enter image description here

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, 1.1 {1,2}]}]

enter image description here

You can use this answer to get the above approach to work in earlier versions of Mathematica.

Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

Another idea is to use a BoundaryMeshRegion as your primitive. For example:

Typeset`MakeBoxes[
    CutoutEllipse[center_, out_, in_],
    form_,
    Graphics
] := With[
    {
    new = Replace[
        RegionDifference[Disk[center, out], Disk[center, in]],
        b_BooleanRegion :> BoundaryDiscretizeRegion[b]
    ]
    },
    Typeset`MakeBoxes[new, form, Graphics]
]

Examples:

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, .9 {1,2}]}]

enter image description here

Graphics[{Pink, EdgeForm[Blue], CutoutEllipse[{0,0}, {4,2}, 1.1 {1,2}]}]

enter image description here