       Re: Drawing a bounded smooth region with Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg76400] Re: Drawing a bounded smooth region with Mathematica
• From: dimitris <dimmechan at yahoo.com>
• Date: Mon, 21 May 2007 06:04:59 -0400 (EDT)
• References: <f2em3g\$2oo\$1@smc.vnet.net><f2mdui\$lot\$1@smc.vnet.net>

```
/  dimitris       :
> The following code appeared in a recent post.
> But as Murray watched, it was not very easy to follow.
>
> So...
>
> Let make another attempt with the hope that everything
>
> ---------------------------------------------------------------------------=
> ----------
> Drawing a bounded smooth region with Mathematica
> ---------------------------------------------------------------------------=
> ----------
>
> In:=
> Clear["Global`*"]
>
> In:=
> << "Graphics`Arrow`"
>
> We want to take a circle and add an arbitrary modulation to the radius
> to obtain an irregular shape. However, we need a smooth join at o=0
> and o=2Pi. So we need a partition function. I am going to make a
> function that is a over most of the domain 0 to 2 , but smoothly
> transistions to zero at the end points and has zero slope at the end
> points. The following was just used to calculate arguments for the
> function.
>
> In:=
> a*o + b /. o -> 2*Pi
> Out=
> b + 2*a*Pi
>
> In:=
> a*o + b /. o -> 2*Pi - d
> Out=
> b + a*(-d + 2*Pi)
>
> In:=
> Solve[{b + 2*a*Pi == -(Pi/2), b + a*(-d + 2*Pi) == Pi/2}, {a, b}]
> Out=
> {{a -> -(Pi/d), b -> -((d*Pi - 4*Pi^2)/(2*d))}}
>
> In:=
> 1/2 + (1/2)*Sin[(-o)*(Pi/d) - (d*Pi - 4*Pi^2)/(2*d)]
> FullSimplify[%]
>
> Out=
> 1/2 - (1/2)*Sin[(o*Pi)/d + (d*Pi - 4*Pi^2)/(2*d)]
> Out=
> Sin[((o - 2*Pi)*Pi)/(2*d)]^2
>
> So this gives us a partition function. d gives the width of the
> transistion region at each end of the o domain.
>
> In:=
> partitionfunction[d_][o_] := Piecewise[{{Sin[(Pi*o)/(2*d)]^2,
> Inequality[0, LessEqual, o, Less, d]},
>     {1, Inequality[d, LessEqual, o, Less, 2*Pi - d]}, {Sin[(Pi*(2*Pi -
> o))/(2*d)]^2, 2*Pi - d <= o <= 2*Pi}}]
>
> Let's use a piece of a Bessel function to modulate the radius.
>
> In:=
> Plot[BesselJ[5, x], {x, 5, 18}, Frame -> True];
>
> In:=
> Solve[{(a*o + b /. o -> 0) == 5, (a*o + b /. o -> 2*Pi) == 18}]
> Out=
> {{a -> 13/(2*Pi), b -> 5}}
>
> In:=
> radius[d_][o_] := 1 + 1.5*partitionfunction[d][o]*BesselJ[5, (13/
> (2*Pi))*o + 5]
>
> In:=
> Plot[radius[o], {o, 0, 2*Pi}, Frame -> True, PlotRange -> All, Axes
> -> False];
>
> Now we can parametrize the curve.
>
> In:=
>
> For d=1 and o=45=B0 we can calculate the tangent line and normal line.
>
> In:=
> tangent[t_] = N[curve[45*Degree] + t*Derivative[curve]
> [45*Degree]]
> Out=
> {1.057382730502271 - 0.7335911589691905*t, 1.057382730502271 +
> 1=2E3811743020353515*t}
>
> In:=
> normal[t_] = N[curve[45*Degree] + t*Reverse[Derivative[curve]
> [45*Degree]]*{1, -1}]
> Out=
> {1.057382730502271 + 1.3811743020353515*t, 1.057382730502271 +
> 0=2E7335911589691905*t}
>
> In:=
> n = {1.127382730502271, 1.037382730502271};
>
> Finnally
>
> In:=
> Block[{\$DisplayFunction = Identity}, g = ParametricPlot[curve[o1],
> {o1, 0, 2*Pi}, Axes -> False, PlotPoints -> 50,
>      PlotStyle -> Thickness[0.007]]; g1 = g /. Line[x_] ->
> {GrayLevel[0.8], Polygon[x]};
>    g2 = ParametricPlot[tangent[t], {t, -0.2, 0.2}, PlotStyle ->
> Thickness[0.006], PlotPoints -> 50];
>    g3 = Graphics[{Thickness[0.007], Arrow[normal, normal[0.3],
>    cir = Graphics[{Circle[normal, 0.1, {3.3*(Pi/2), 2.15*Pi}]}]; po
> = Graphics[{PointSize[0.01], Point[n]}];
>    tex1 = Graphics[Text["V", {0.0532359, -0.0138103}]]; tex2 =
> Graphics[Text["S", {0.470751, -1.08655}]];
>    tex3 = Graphics[Text[StyleForm["n", FontSize -> 17, FontFamily ->
> "Times", FontColor -> Black,
> FontWeight -> "Bold"], {1.7, 1.2}]]; ]
>
> Show[g, g1, g2, g3, tex1, tex2, tex3, cir, po, AspectRatio ->
> Automatic,
>    TextStyle -> {FontSize -> 17, FontFamily -> "Times", FontWeight ->
> "Bold"}];
>
> ---------------------------------------------------------------------------=
> -------------------------------------------------------------------------
>
> If everything works ok during the Copy/Paste process then it will
> appear a really nice
> drawing.
>
> Who sent that Mathematica cannot be used as a drawing environement?
> Show them this drawing in order to change their mind!
> I did to my supervisor! With a little success I must admit! But this
> is
> another issue!
>
> Using David Park's well known package previous drawing appears much
> nicer in the
> sense of aesthetic issues! I have seen it with my own eyes!
>
> All acknowledgents regarding the process of modulation of the region
> must
> be given to the one and only Mr. David Park! I spent much time to
> figure out what
> is going! Simply amazing (the idea and David as well!).
>
> I don't know about you, but speaking on behalf of myself and with all
> of my respect to the other forumists,
> I sadly missed his presence and contribution to the forum.
>
> Dimtris

I use Mathematica 5.2.

I guess some compatibility issues affect the quality of the graphics
object in version 6
as Murray noticed!

I guess only a very clever man (...) could write incorrect (!!!) his
own name!
(see a little above!)

Dimitris

(Double Checked!)

```

• Prev by Date: Re: Mathematica 6 review [first impressions]
• Next by Date: Re: Pisot Numbers
• Previous by thread: Re: Drawing a bounded smooth region with Mathematica
• Next by thread: Minimize[] Problem