Rounded Rectangle

Author

Eric W. Weisstein
August 3, 2016

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Laminae/RoundedRectangle.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/RoundedRectangle.html.

©2016 Wolfram Research, Inc. except for portions noted otherwise

Definitions

lamina="RoundedRectangle";

var=LaminaData[lamina,"Variables"]

par=LaminaData[lamina,"Parameters"]

assum=LaminaData[lamina,"VariableConstraints"]@@var

ineq=(LaminaData[lamina,"Inequalities"]@@var)@@par

area=LaminaData[lamina,"Area"]@@var

implreg=LaminaData[lamina,"ImplicitRegion"]@@var

reg=LaminaData[lamina,"Region"]@@var

reg=Function[{\[FormalA],\[FormalB],\[FormalR]},RegionUnion[Disk[-(1/2) {\[FormalA],\[FormalB]},\[FormalR]],Disk[(1/2) {-\[FormalA],\[FormalB]},\[FormalR]],Disk[(1/2) {\[FormalA],-\[FormalB]},\[FormalR]],Disk[(({\[FormalA],\[FormalB]})/2),\[FormalR]],Rectangle[-{(\[FormalA]/2)+\[FormalR],(\[FormalB]/2)},{(\[FormalA]/2)+\[FormalR],(\[FormalB]/2)}],Rectangle[-{(\[FormalA]/2),(\[FormalB]/2)+\[FormalR]},{(\[FormalA]/2),(\[FormalB]/2)+\[FormalR]}]]]@@var

paramreg=LaminaData[lamina,"ParametricRegion"]

Graphic

RoundedRectangle2[x1_,x2_,r_]:={
(* middle *)
Rectangle[x1+{r,r},x2-{r,r}],
(* bottom flap *)
Rectangle[x1+{r,0},{x2[[1]]-r,x1[[2]]+r}],
(* top flap *)
Rectangle[{x1[[1]]+r,x2[[2]]-r},x2-{r,0}],
(* left flap *)
Rectangle[x1+{0,r},{x1[[1]]+r,x2[[2]]-r}],
(* yellow flap *)
Rectangle[{x2[[1]]-r,x1[[2]]+r},x2-{0,r}],
(* lower left disk quadrant *)
Disk[x1+{r,r},r,{Pi,3Pi/2}],
(* lower right disk quadrant *)
Disk[{x2[[1]]-r,x1[[2]]+r},r,{3Pi/2,2Pi}],
(* upper right disk quadrant *)
Disk[x2-{r,r},r,{0,Pi/2}],
(* upper left disk quadrant *)
Disk[{x1[[1]]+r,x2[[2]]-r},r,{Pi/2,Pi}]
}

Graphics[RoundedRectangle2[{0,0},{3,1},.1]]

bug(439137): Cracks and jaggies when rendering rounded rectangle components

Graphics[{EdgeForm[Black],RoundedRectangle2[{0,0},{3,1},.1]}]

Region

reg=LaminaData["RoundedRectangle","Region"][3,1,.1]

Region[reg]

Equations

Inequality

RoundedRectangle[a_,b_,r_]:=Or@@Flatten[Outer[(x-a#1/2)^2+(y-b#2/2)^2<=r^2&,{-1,1},{-1,1}]]||(-a/2-r<=x<=a/2+r&&-b/2<=y<=b/2)||(-b/2-r<=y<=b/2+r&&-a/2<=x<=a/2)

RoundedRectangle[a,b,r]

ineq=FullSimplify[%,a>0&&b>0&&r>0]

ineq=((((a/2)+x))^2)+((((b/2)+y))^2)<(r^2)||((((a/2)+x))^2)+(((-(b/2)+y))^2)<(r^2)||(((-(a/2)+x))^2)+((((b/2)+y))^2)<(r^2)||(((-(a/2)+x))^2)+(((-(b/2)+y))^2)<(r^2)||(a+2 (r+x)>0&&a+2 r>2 x&&b+2 y>0&&b>2 y)||(b+2 (r+y)>0&&b+2 r>2 y&&a+2 x>0&&a>2 x);

Plots

Diagram

LaminaData["RoundedRectangle","Diagram"]

DiscretizeRegion

Block[{a=1,b=.8,r=.2},Show[DiscretizeRegion[reg],ImageSize->Small]]

Block[{a=1,b=.8,r=.2},Show[DiscretizeRegion[implreg],ImageSize->Small]]

InequalityGraphics

<<Graphics`InequalityGraphics`

With[{a=2,b=1,r=1/10,eps=.1},InequalityPlot[RoundedRectangle[a,b,r],{x},{y},PlotRange->All,Axes->False,Epilog->{
Line[{{#(a/2+r),-b/2},{#(a/2+r),b/2}}]&/@{-1,1},
{Dashing[{.01}],
Outer[Circle[{a#1,b#2}/2,r]&,{-1,1},{-1,1}],
Line[{{-a,b},{-a,-b},{a,-b},{a,b},{-a,b}}/2],
Text[Sequence@@#,TextStyle->{FontFamily->"Times",FontSlant->"Italic"}]&/@{{"a",{0,b/2-eps}},{"b",{a/2-eps,0}}}
}
}]
]

With[{a=2,b=1},Table[InequalityPlot[RoundedRectangle[a,b,r],{x},{y},Axes->False,PlotRange->{{-3,3},{-2,2}},Epilog->{Line[{{#(a/2+r),-b/2},{#(a/2+r),b/2}}]&/@{-1,1}}],{r,0,1,1/10}]]

RegionPlot

With[{a=2,b=1,r=1/10},RegionPlot[((((a/2)+x))^2)+((((b/2)+y))^2)<(r^2)||((((a/2)+x))^2)+(((-(b/2)+y))^2)<(r^2)||(((-(a/2)+x))^2)+((((b/2)+y))^2)<(r^2)||(((-(a/2)+x))^2)+(((-(b/2)+y))^2)<(r^2)||(a+2 (r+x)>0&&a+2 r>2 x&&b+2 y>0&&b>2 y)||(b+2 (r+y)>0&&b+2 r>2 y&&a+2 x>0&&a>2 x),{x,-a/2-r,a/2+r},{y,-b/2-r,b/2+r},AspectRatio->Automatic]]

Properties

Area

Area

$Version

Assuming[assum,FullSimplify@Area[reg]]//Timing

Integrate V5

(i=Integrate[Boole[RoundedRectangle[a,b,r]],{x,-∞,∞},{y,-∞,∞},Assumptions->a>0&&b>0&&r>0])//Timing

Returns after 3.9 CPU days!

Integrate V6.1

(i=Integrate[Boole[RoundedRectangle[a,b,r]],{x,-∞,∞},{y,-∞,∞},Assumptions->a>0&&b>0&&r>0])//Timing

Integrate V8

Integrate[Boole[ineq],{x,-a/2-r,a/2+r},{y,-b/2-r,b/2+r},Assumptions->a>0&&b>0&&r>0]//Timing

Integrate V11

$Version

Integrate[Boole[ineq],{\[FormalX],-\[FormalA]/2-\[FormalR],\[FormalA]/2+\[FormalR]},{\[FormalY],-\[FormalB]/2-\[FormalR],\[FormalB]/2+\[FormalR]},Assumptions->assum]//Timing

RegionMeasure

$Version

Assuming[assum,RegionMeasure[reg]]//Timing

Area Special Casses

a==b

(i=Integrate[Boole[RoundedRectangle[a,a,r]],{x,-∞,∞},{y,-∞,∞},Assumptions->a>0&&r>0])//Timing

Stadium

a b+2 a r+2 b r+π (r^2)/.a->0

a b+2 a r+2 b r+π (r^2)/.b->0

Centroid

Integrate

(1/(a b+2 a r+2 b r+π (r^2)))Integrate[{x,y}Boole[ineq],{x,-a/2-r,a/2+r},{y,-b/2-r,b/2+r},Assumptions->a>0&&b>0&&r>0]//Simplify//Timing

RegionCentroid

InertiaTensor

Integrate[AreaInertiaTensor[{x,y}]Boole[ineq],{x,-a/2-r,a/2+r},{y,-b/2-r,b/2+r},Assumptions->a>0&&b>0&&r>0]//Simplify//Timing

FullSimplify[Last[%]]

Perimeter

RadiiOfGyration

FullSimplify[Sqrt[(1/(a b+2 a r+2 b r+π (r^2)))Tr[{{(1/12) (a (((b+2 r))^3)+r (2 (b^3)+3 (b^2) π r+16 b (r^2)+3 π (r^3))),0},{0,(1/12) ((a^3) b+2 (a^2) (a+3 b) r+3 a (4 b+a π) (r^2)+8 (2 a+b) (r^3)+3 π (r^4))}},List]],r>0&&b>0&&a>0]

GeneralizedDiameter

ineq0[x_,y_]:=((((a/2)+x))^2)+((((b/2)+y))^2)<(r^2)||((((a/2)+x))^2)+(((-(b/2)+y))^2)<(r^2)||(((-(a/2)+x))^2)+((((b/2)+y))^2)<(r^2)||(((-(a/2)+x))^2)+(((-(b/2)+y))^2)<(r^2)||(a+2 (r+x)>0&&a+2 r>2 x&&b+2 y>0&&b>2 y)||(b+2 (r+y)>0&&b+2 r>2 y&&a+2 x>0&&a>2 x)

ineqs=FullSimplify[And@@ineq0@@@{{x1,y1},{x2,y2}},a>0&&r>0&&b>0]

Maximize[{(x1-x2)^2+(y1-y2)^2,ineqs},{x1,x2,y1,y2},Reals]//Timing

...ran overnight...

Extremities of opposite straight edges

x0={a/2+r,b};
x1={-a/2,-b/2-r};
x2={-a/2-r,-b/2};

FullSimplify[Max@@(#.#&/@{x1-x0,x2-x0}),a>0&&b>0&&r>0&&a>b&&2r<b&&2r<a]

Maximize diagonally opposite quarter round pieces

x1=.
x2=.

MaxValue[{(x1-x2)^2+(y1-y2)^2,(x1-a/2)^2+(y1-b/2)^2==r^2&&(x2+a/2)^2+(y2+b/2)^2==r^2},{x1,x2,y1,y2}]

Solve[(x1-a/2)^2+(y1-b/2)^2==r^2,y1]

Solve[(x2+a/2)^2+(y2+b/2)^2==r^2,y2]

MaxValue[(x1-x2)^2+((1/2) (b+(Sqrt[-(a^2)+4 (r^2)+4 a x1-4 (x1^2)]))-(1/2) (-b-(Sqrt[-(a^2)+4 (r^2)-4 a x2-4 (x2^2)])))^2,{x1,x2}]

GeneralizedDiameter with a==b

Maximize[{(x1-x2)^2+(y1-y2)^2,ineqs/.b->a},{x1,x2,y1,y2},Reals]//Timing

...ran overnight...

GeneralizedDiameter normalized by r

Maximize[{(x1-x2)^2+(y1-y2)^2,ineqs/.r->1},{x1,x2,y1,y2},Reals]//Timing

Special Cases

FilledRectangle

With[{a=2,b=1,r=0},InequalityPlot[ineqs[a,b,r],{x},{y},PlotRange->All,Axes->False,Epilog->{Line[{{#(a/2+r),-b/2},{#(a/2+r),b/2}}]&/@{-1,1}},ImageSize->200]
]

{a b+2 r(a+b)+π r^2,2(a+b+π r)}/.r->0

Disk

With[{a=0,b=0,r=1},InequalityPlot[ineqs[a,b,r],{x},{y},PlotRange->All,Axes->False,Epilog->{Line[{{#(a/2+r),-b/2},{#(a/2+r),b/2}}]&/@{-1,1}},ImageSize->200]
]

With[{a=0,b=0},{a b+2 r(a+b)+π r^2,2(a+b+π r)}]

FilledRoundedSquare

With[{a=1,b=1,r=1},InequalityPlot[ineqs[a,b,r],{x},{y},PlotRange->All,Axes->False,Epilog->{Line[{{#(a/2+r),-b/2},{#(a/2+r),b/2}}]&/@{-1,1}},ImageSize->200]
]

With[{b=a,r=a},{a b+2 r(a+b)+π r^2,2(a+b+π r)}]//Simplify