# How do I use Mathematica as a vector drawing program?

Recently I changed my furniture in my room and I am trying to find the best position of each part. I am sure that Mathematica could help! I read the LocatorPane, selecting multiple Locators for selecting multiple locators.

Then I made some shapes like a triangle (3 Locators), a table (4 Locators) etc. and tried to move them(each shape as a whole) in some direction.

My questions are:

• How can one group/ungroup some of the shapes (for examples table + chairs)

• Rotate a shape to a particular angle

• Ensure that two sides of the same or different shapes are in parallel,vertical or tangent?

• Perhaps Mma isn't the best tool for interior design sketchup.com/products/sketchup-make Aug 12, 2013 at 1:24
• I agree with Belisarius. Mathematica is not the tool for this job. Any of a number of good vector drawing programs would be better. However, some the things you want are available in graphics tools found on the Graphics menu. Aug 12, 2013 at 1:39
• While I agree that Mathematica is not the best the tool for drawing, I don't see why one would downvote this question for that reason. There could be many reasons for using Mathematica for this task, for instance because one needs the coordinates in a Mathematica centered coordinate system for further processing (calculating area, finding the best packing etc.). In the past, I have been using both the drawing tools as well as LocatorPane for quick and dirty jobs in this area and though perhaps clumsy it worked sufficiently well for my needs. Aug 12, 2013 at 5:45
• @SjoerdC.deVries. I down voted because the post doesn't show any code, not because I think Mathematica is an inappropriate tool. Aug 12, 2013 at 13:59
• @m_goldberg It is often good to clarify your downvote in a comment so that the OP knows what to improve instead of letting him guess. Your first comment doesn't provide any clue at all about code. Aug 12, 2013 at 15:24

I think it is fun and maybe even useful for domestic purposes so this is my approach.

The following code allows you to easily manage rotation of objects. So it is reffering to your second question. I have not put this in neat DynamicModule because it is not finished, I consider it a sample piece of code :)

x = {0, 0}; y = {1, 1}; (*starting positions*)
Do[rot@i = 0, {i, 2}]; (*starting rotations*)
acc = 1;
ob[o_, id_] :=  EventHandler[Rotate[#, rot[id]] &@
Style[o, If[acc == id, Red, Blue]],
{"MouseDown" :> (acc = id)},
PassEventsDown -> True, PassEventsUp -> True]
(*ob is wrapper for your chairs etc.*)

Grid[{
{LocatorPane[Dynamic@{x, y},
Graphics[{
Dynamic@ob[Rectangle[x - 1, x + 1], 1],
Dynamic@ob[Rectangle[y - 1, y + 1], 2]
}, PlotRange -> 10, ImageSize -> 500, Axes -> True]
]
,
Column[{
StringForm["Object ", Dynamic@acc],
ExperimentalAngularSlider[Dynamic[rot[acc]]],
InputField[Dynamic[rot[acc]], FieldSize -> 6]
}, Center]
}
}]


• The active object is Red and you can switch it by click, no problem with adding SetterBar or whatever next to the plot.
• Active object is annouced by variable acc which enables color rot and so on.
• You can easily add other parameters which you want to be able to manage.

ExperimentalAngularSlider is just for fun. It's Options do not work correctly but here it is only for it's appearance :)

Maybe it is a mess and there is not much information but I think no one is expecting that answers here will consist of complete interior design tools :)

You can use it $+$ Heike's code about multiple selection $+$ couple tiny improvements $=$ it could be something.

• Good solution for selecting the active object! (+1) Aug 12, 2013 at 13:57
• @Kuba I am sure that you 'll get something! This will be useful not only for domestic purposes(;)) but also geometry, drawing etc. Could you please finish your code and/or insert some geometrical or algebraic aspects in your code like measuring distances, angles, creation of a new shape, putting a shape on front/back, grouping shapes or ensuring parallel/vertical edges.... etc? Aug 12, 2013 at 15:35
• Did you try this on a fresh kernel? I'm getting an error message, due to acc not being initially defined I think. Aug 12, 2013 at 15:54
• @Anon You are right, thanks.
– Kuba
Aug 12, 2013 at 15:57
• @kornaros You should consider to wait with an accept, this question may provoke many great answers. I will, eventualy, improve this, but this month is horrible and I can't promise anything. Also, feel free to use this code to create more complete answer which you can post. :)
– Kuba
Aug 12, 2013 at 16:03

I think it's an interesting question - even if I wouldn't use Mathematica for this purpose. I'm assuming you're not interested so much in the interactive drawing tools (you can group things together, but there's no numerical interactivity like you'd find in a CAD program). Sticking with 2D to start with:

chair = {Gray, Rectangle[{0, 0}, {.5, .5}]};
table = {Gray, Rectangle[{0, 0}, {1, 1}]};
bed = {Gray, Rectangle[{0, 0}, {2, 1}]};
carpet = Inset[
ArrayPlot[
CellularAutomaton[{14, {2, 1}, {1, 1}}, {{{1}}, 0}, {{{30}}}],
ColorFunction -> "LakeColors"]];
room = {EdgeForm[Black], FaceForm[None], Rectangle[{0, 0}, {7, 5}]};
Graphics[
{room,
Translate[carpet,  {0, 0}],
Translate[Rotate[chair, Pi],  {6.25, 4}],
Translate[Rotate[table, Pi/2], {6, 2.5}],
Translate[bed, {0.1, 3.9}]
},
Frame -> True]


If you feel the urge to re-arrange things manually from here, then use the commands on the Graphics menu.

It's possible to add Locators and Sliders to enable some interactivity:

Manipulate[
Graphics[
{room,
Translate[carpet, {0, 0}],
Translate[Rotate[chair, rot1], loc1],
Translate[Rotate[table, rot2], loc2],
Translate[bed, {0.1, 3.9}]
},
Frame -> True],
{{rot1, 0, "Orientation of chair"}, 0, 2 Pi},
{{rot2, 0, "Orientation of table"}, 0, 2 Pi},
{{loc1, {0, 0}}, Locator, Appearance -> None},
{{loc2, {0, 0}}, Locator, Appearance -> None}]
`

you can drag the chair and table around now. It's not looking promising though.

• You get my +1 for your effort of starting to answer this question (and the rug design), but I do note that you haven't answered any of the three bulleted questions. Aug 12, 2013 at 8:32
• @SjoerdC.deVries :) true enough. I was going to add a Manipulate for the rotation and translate, and add a group of 4 chairs and a table - but sometimes you don't want to put too much effort into a 'proof of concept'... Aug 12, 2013 at 8:53
• I also vote +1 for the answer. I like the carpet! I suppose that you can also add some texture for the the bed and table or chair. Of course, I would like to have more geometrical control on the shapes. It will be interesting to see an implementation of the Manipulate for the rotation of any selected shape or group of shapes. Also an implementation of Tooltip that inform me when two edges are in parallel etc. Aug 12, 2013 at 11:45
• @kornaros It might be possible to somehow step through the objects and adjust each one with the same sliders. Amazing things are possible if people are prepared to write them. (Eg Heike's wonderful example here). I wish you luck writing such things! Aug 12, 2013 at 11:54
• This would probably be a useful app! Twice in the last 15 years I've used Mathematica to lay out furniture - but just "by hand". You could group items using {items...} and then add two locators to each group, one to translate and another to rotate the group about the first. Aug 12, 2013 at 13:26