Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: creating a graphic in a text cell

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128183] Re: creating a graphic in a text cell
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sat, 22 Sep 2012 02:46:05 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20120921081505.6E6DB685F@smc.vnet.net>

On Sep 21, 2012, at 4:15 AM, Alexei Boulbitch <Alexei.Boulbitch at iee.lu> wrote:

> I'm teaching a statics course that naturally requires a lot of
> depictions of ropes, springs, pulleys, etc.  To produce a graphic box
> I use Ctrl-1 and use the tool palette.  This works, a bit painfully, but
> recently I ran into a need to depict angles with short arcs.  I couldn't
> find a way of doing that that the graphic box would accept.
>
> Is there a way to specify an arc, and if so, how?  I'm running Mathematica
> 8.0.4.0 under Mac OS X.6.8.  Thanks.
>
> - Dushan Mitrovich
>
>
> Hi, Dushan,
>
> There is a primitive Circle[] in which you can make a circular arc. Just check Menu/Help/Circle. You may build it iby its evaluation in your notebook, and then you can draw down your sketch around the already existing arc.
>
> I also make a lot of drawings illustrating technical texts done in Mathematica. These drawings are not exactly as yours (i.e. to teach something), but they are rather comparable. Since already long time I refused of using the Drawings palette. Instead I do it programmatically using graphics primitives. The reason is that in the same drawing I often combine some elements obtained by one of plotting operations (like say, Plot[]) with other elements that previously I have produced with the palette. Typically as soon as I end up with drawing, I realized that have missed something in the plot, and need to make it once more. That means that I need to make also the whole palette-based drawing once again.
>
> After having started drawing with primitives I simply need to re-evaluate the whole code.
>
> As the example I just sketched below a simple static problem. You will find there the element entitled arc with the construct you asked about in your post about.
>
> Evaluate the code below.
>
> (* These are definitions of all elements of the sketch *)
>
> base = Graphics[{LightBlue, EdgeForm[{Thin, Black}],
>    Polygon[{{0, 0}, {2, 0}, {2, 2*Tan[\[Pi]/8]}}]}];
>
> brick1 = Graphics[{LightRed, EdgeForm[{Thin, Black}],
>    Translate[
>     Rotate[Polygon[{{0, 0}, {0.5, 0}, {0.5, 0.25}, {0., 0.25}, {0,
>         0}}], 0.392], {0.693, 0.417}]}];
>
> arr1 = Graphics[{Red, Thick,
>    Arrow[{{0.944, 0.514}, {0.944 - 0.4 Sin[\[Pi]/8],
>       0.514 + 0.4 Cos[\[Pi]/8]}}]}];
> arr2 = Graphics[{Blue, Thick,
>    Arrow[{{0.944 + 0.044,
>       0.514 - 0.086}, {0.944 + 0.044 - 0.5 Cos[\[Pi]/8],
>       0.514 - 0.5 Sin[\[Pi]/8] - 0.086}}]}];
> arr3 = Graphics[{Brown, Thick, Arrow[{{0.944, 0.514}, {0.944, 0.1}}]}];
> txtN = Graphics[
>   Text[Style["N", Italic, 18, Red, Bold], {0.874, 0.902}]];
> txtmg = Graphics[
>   Text[Style["mg", Italic, 18, Brown, Bold], {1.062, 0.148}]];
> txtkN = Graphics[
>   Text[Style["F=kN", Italic, 18, Blue, Bold], {0.342 + 0.125,
>     0.46 - 0.11}]];
> arc = Graphics[Circle[{0, 0}, 0.5, {0, \[Pi]/8}]];
> txt3 = Graphics[Text[Style["\[Alpha]", 18], {0.546, 0.12}]];
> line1 = Graphics[{Thick,
>    Line[{{1.172, 0.632}, {1.172 + 0.806*Cos[\[Pi]/8],
>       0.632 + 0.806*Sin[\[Pi]/8]}}]}];
> disk = Graphics[{LightBlue, EdgeForm[{Thin, Black}],
>    Disk[{2, 2*Tan[\[Pi]/8] + 0.1}, 0.1]}];
> line2 = Graphics[{Thick,
>    Line[{{2.1 - 0.015, 2*Tan[\[Pi]/8] + 0.04}, {2.1 - 0.015,
>       Tan[\[Pi]/8] + 0.04}}]}];
> brick2 = Graphics[{LightRed, EdgeForm[{Thin, Black}],
>    Polygon[{{2.01, 0.4542}, {2.01 + 0.15, 0.4542}, {2.01 + 0.15,
>       0.3}, {2.01, 0.3}, {2.01, 0.4542}}]}];
> arr4 = Graphics[{Green, Thick,
>    Arrow[{{1.172, 0.632}, {1.172 + 0.3*Cos[\[Pi]/8],
>       0.632 + 0.3*Sin[\[Pi]/8]}}]}];
> arr5 = Graphics[{Green, Thick,
>    Arrow[{{2.1 - 0.015, Tan[\[Pi]/8] + 0.04}, {2.1 - 0.015,
>       Tan[\[Pi]/8] + 0.3}}]}];
> arr6 = Graphics[{Black, Thick,
>    Arrow[{{2.1 - 0.015, Tan[\[Pi]/8] - 0.04}, {2.1 - 0.015,
>       Tan[\[Pi]/8] - 0.04 - 0.3}}]}];
> txtT1 = Graphics[
>   Text[Style["T", 18, Italic, Bold, Green], {1.395, 0.83}]];
> txtT2 = Graphics[
>   Text[Style["T", 18, Italic, Bold, Green], {2.172, 0.605}]];
> txtMg = Graphics[
>   Text[Style["Mg", 18, Italic, Bold, Black], {2.206, 0.13}]];
>
> (* here the elements are unified making the sketch *)
> Show[{base, brick1, arr1, arr2, arr3, txtN, txtmg, txtkN, arc, txt3,
>  line1, disk, line2, brick2, arr4, arr5, arr6, txtT1, txtT2, txtMg}]
>
> One can also easily parameterize it and make a movie out of a static drawing.
>
> Drawing with primitives goes a bit slower than that with the palette, but still astonishingly fast. It took me about 10 minutes to draw this. There is a simple trick to accelerate the process. Just ask me, if you would find it interesting to learn about it.


That code produces a very nice figure. But, where do all those numeric coordinates come from? I presume this took a lot of experimentation to get things to look just right.

Would it not be wonderful if there were a way in Mathematica to draw something with the Drawing Tools (or some similar facility) that would automatically provide the coordinates of where the cursor is placed and then more or less automatically translate what you've drawn into actual Mathematica code such as you show?

---
Murray Eisenberg                                     
murray at math.umass.edu
Mathematics & Statistics Dept.      
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                  413 545-2859 (W)
710 North Pleasant Street                      fax   413 545-1801
Amherst, MA 01003-9305








  • Prev by Date: Re: List & Plot: do they parse options differently?
  • Next by Date: Re: creating a graphic in a text cell
  • Previous by thread: Re: creating a graphic in a text cell
  • Next by thread: Re: creating a graphic in a text cell