5
$\begingroup$

I need to draw a regular polygon on n sides, n <13 for side L, L <11 in cm. with semicircles on its sides, completely black in such a way that I save it as a xxx.png image to print and cut out later. The important thing is that the dimensions on the screen in cm. are identical to the image to be cropped later. Could you help me. I have seen several examples in the forum, like this one, but I can't find a way to modify it. I attach a picture of the idea.(but totally black without squares or borders, on a white background)

Idea

L = 12;
Graphics[Line[{{L, 0}, {L/2, L Sqrt[3]/2}, {-L/2, L Sqrt[3]/2}, {-L, 
0}, {-L/2, -L Sqrt[3]/2}, {L/2, -L Sqrt[3]/2}, {L, 0}}]]
$\endgroup$
5
$\begingroup$

An obvious method would be stitiching together RegularPolygon[] + appropriately positioned Disk[] objects, but that would usually result in unwanted seams. To avoid this, we can instead build a FilledCurve[] object from the result of CirclePoints[], using the NURBS representation of a semicircle:

With[{r = 2, θ = π/2, n = 7}, 
     Graphics[FilledCurve[MapIndexed[With[{d = (EuclideanDistance @@ #1)
                                               Normalize[Cross[Subtract @@ #1]]/2},
                                          BSplineCurve[If[#2 === {1}, Identity, Rest]
                                                       [{#1[[1]], #1[[1]] + d,
                                                         #1[[2]] + d, #1[[2]]}],
                                                       SplineDegree -> 2,
                                                       SplineKnots -> {0, 0, 0, 1/2,
                                                                       1, 1, 1},
                                                       SplineWeights -> {1, 1/2,
                                                                         1/2, 1}]] &,
                                     Partition[N[CirclePoints[{r, θ}, n]], 2, 1, 2]]]]]

regular heptagon bordered by semicircles

$\endgroup$
3
$\begingroup$

Here is the naive approach, also mentioned by J.M. (but he implemented another):

draw[n_, {w_, h_}] := Module[{pts, segments, midPoints, lengths},
  pts = With[{ipts = CirclePoints[n]}, Append[ipts, First[ipts]]];
  segments = Partition[pts, 2, 1];
  midPoints = Mean /@ segments;
  lengths = Norm[First[#] - Last[#]] & /@ segments;
  Graphics[{
    MapThread[Disk, {midPoints, lengths/2}],
    Polygon[pts]
    },
   ImageSize -> (72/2.54) {w, h},
   PlotRangePadding -> 0
   ]
  ]

draw[7, {10, 10}]

Mathematica graphics

ImageSize -> (72/2.54) {w, h} will hopefully mean that if you export this graphics and print it then it will be wxh centimeters large. I removed the plot range padding because otherwise that would count towards the size of the figure. The number 72 comes in because, as documented under ImageSize, the size of the figure is given in printer's points.

Considering the discussion here it seems that you should be careful about printing it directly from Mathematica. The better approach seems to be to export it e.g. to PDF and then print it.

$\endgroup$
3
  • $\begingroup$ Thank you all, very good explanation of the printing, which I did not have much idea. On the other hand since I do not use style sheets, as they implement the rule above, it must be a silly question but I do not see it $\endgroup$ – zeros Aug 23 '20 at 20:14
  • 1
    $\begingroup$ @zeros you mean you do not understand how it applies to you? You can just ignore that post. It has some interesting context but it should not be necessary. All you should need to do is export the image to a file, and then print the file. That is my understanding. $\endgroup$ – C. E. Aug 23 '20 at 20:26
  • $\begingroup$ @C.E.Not what I was really asking is how they put the rule at the top of the mathematica sheet, everything interests me, I learn a lot from you. My knowledge of nathematica is limited. $\endgroup$ – zeros Aug 25 '20 at 4:58
3
$\begingroup$
r = 12;
Graphics[{#, Disk[RegionCentroid @ #, r/2] & /@ MeshPrimitives[#, 1]}] & @ 
   RegularPolygon[r, 6]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Or for any number of sides, n, consider Graphics[{#,Disk[RegionCentroid @ #,r Sin[Pi/n]]&/@MeshPrimitives[#,1]}]&@RegularPolygon[r,n] $\endgroup$ – creidhne Aug 23 '20 at 18:58
  • $\begingroup$ @ creidhne,thank you for your suggestion $\endgroup$ – zeros Aug 24 '20 at 4:27
  • $\begingroup$ @kglr, thanks for your indications $\endgroup$ – zeros Aug 24 '20 at 4:29

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.