1
$\begingroup$

I am learning to use the drawing tools palette that comes packaged with Mathematica. I'm attempting to create some diagrams for class using Mathematica's drawing tools rather than Adobe.

Is there a way to create smooth curves? I see straight lines and straight lines with arrows but I don't see a way to bend them. There is a tool to create curves free hand using the curser but this is limited as the curves will never look pretty. I believe the way pretty curves are done in other programs is you draw the straight line curve first and then click off the straight line and pull it in any direction to bend the straight line curve to your the desired effect. Is this possible using the drawing tools?

If not, do you have an alternate solution? It would be great to create my diagrams in Mathematica if it has enough functionality.

$\endgroup$
  • $\begingroup$ I don't think there's such a tool in the drawing palette, but you can of course use Mathematica to create pretty mich arbitrary shapes. You might want to look at BezierCurve and in particular the interactive example in the function's documentation. $\endgroup$ – Graumagier Nov 28 '15 at 15:12
2
$\begingroup$

An answer that comes close to what you're looking for is found in Heike's post. It allows you to interactively draw various types of graphics objects. It's also easily extensible to accommodate more shapes, but smooth curves are already implemented in the form of Bezier curves.

To allow you to reuse the graphic created with this code, I added one more button to Heike's answer. It copies the current Graphics to the clipboard, so that you can paste it anywhere in the notebook, or even into other applications.

DynamicModule[{types, fun}, 
 types = {"Circle", "Disk", "Polygon", "Line", "Bezier", "Spline"};
 fun[{}, ___] := {};
 fun[{a_}, ___] := {};
 fun[pts_, type_] := 
  Switch[type, "Circle", Circle[pts[[1]], Norm[pts[[2]] - pts[[1]]]], 
   "Disk", Disk[pts[[1]], Norm[pts[[2]] - pts[[1]]]], 
   "Polygon", {EdgeForm[Black], FaceForm[Opacity[.5]], Polygon[pts]}, 
   "Line", Line[pts], "Bezier", BezierCurve[pts], "Spline", 
   BSplineCurve[pts]];
 Manipulate[ptlst[[object]] = pts;
  typelst[[object]] = type;
  grlst = MapThread[fun, {ptlst, typelst}];
  Graphics[grlst, PlotRange -> {{-3, 3}, {-3, 3}}], {{pts, {}}, 
   Locator, LocatorAutoCreate -> All}, {{ptlst, {{}}}, 
   None}, {{typelst, {"Line"}}, None}, {{object, 1}, None}, {grlst, 
   None}, {{type, "Line", "Object type"}, types}, 
  Row[{Button["New object", 
     If[Length[ptlst[[-1]]] > 0, AppendTo[ptlst, {}]; 
      AppendTo[typelst, type];
      object = Length[typelst];
      pts = {}]], 
    Dynamic@
     PopupView[Graphics[#, ImageSize -> 50] & /@ grlst, 
      Dynamic[object, (object = #; pts = ptlst[[#]]; 
         type = typelst[[#]]) &], Button["Edit object"]], 
    Button["Print shapes", Print[Transpose[{ptlst, typelst}]]], 
    Button["Copy graphic", 
     CopyToClipboard[
      Graphics[grlst, PlotRange -> {{-3, 3}, {-3, 3}}]]]}]]]

Following Heike's instructions, create the desired sketch. Then press Copy graphic. Now you could add a new line saying g =, then paste the sketch into that line, and you have a Graphics object.

$\endgroup$

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.