How to draw mathematical lattice diagrams using Inkscape

Asked by diagramdrawer

I want to use Inkscape to draw mathematical lattice diagrams similar to the diagrams at
 https://en.wikipedia.org/wiki/Lattice_%28order%29
 and to the various diagrams at
 https://en.wikipedia.org/wiki/Free_distributive_lattice#Free_distributive_lattices

My basic problems with Inkscape are:
 * I could not find a built-in way to put nodes of various designs at the corners and endpoints of the diagram.
 * I can instead make many copies of a small circle, or small rectangle, or I can make larger circles or rectangles with text in them. But then I don't know how to 'snap' this object neatly to the corners and endpoints.

I could not find a simple explanation of how to draw mathematical and scientific diagrams in the various help files associated with Inkscape. Are you able to direct me?

Question information

Language:
English Edit question
Status:
Answered
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
Andrew P. (japoth) said :
#1

I use AutoCAD R14 for such things, running on Windows 98, then import the DWG file into Adobe Illustrator 9, export as an SVG file, then finish in Inkscape. It's round-about, but AutoCAD, or any CAD program is much better equipped to create precise arrays of shapes and lines and snap to endpoints of lines, centers of circles, etc., than either Inkscape or Illustrator.

Inkscape can read AutoCAD R13 and earlier DXF files, so if you can find a CAD application that can generate R10 - R13 DXF files, this may be an option. There are a few free CAD programs, particularly for Linux, that can do it; although they're not as capable overall as AutoCAD, they should suffice for simple diagrams.

Another option is to write a program in your favorite high-level language (BASIC, Python, etc.) that can generate the XML code for Inkscape. Inkscape's XML files are just text, so the generating program doesn't even have to create a complete Inkscape .svg file, just the code blocks for the entities, which can then be pasted into a prototype .svg file with a text editor. I've done similar things in the past to generate fancy curves in DXF format for importing into AutoCAD, where trying to draw the hundreds of coordinates by hand would have been daunting or impossible. I've also read of individuals writing code in PostScript, which Inkscape can import directly.

Revision history for this message
su_v (suv-lp) said :
#2

> My basic problems with Inkscape are:
> * I could not find a built-in way to put nodes of various
> designs at the corners and endpoints of the diagram.

SVG (and Inkscape) call these markers: they are an attribute of the Stroke style (see 'Object > Fill and Stroke…'). Inkscape has a set of stock markers, and for custom needs, one can easily create custom markers. For details, please read the corresponding manual section:
<http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Attributes-Stroke.html#Attributes-Stroke-Markers>

> * I can instead make many copies of a small circle, or small
> rectangle, or I can make larger circles or rectangles with
> text in them. But then I don't know how to 'snap' this object
> neatly to the corners and endpoints.

Please check the settings on the snap controls bar: it has two groups of snap modes (bounding box corners, Nodes and handles), and for each of them, there are various snap targets. Note that the two modes do not mix (bbox corners do not snap to node targets, and nodes do not snap to bbox targets). Both modes can snap to the general targets grid, guides and page borders (the last group of buttons).

To snap the center of small objects (e.g. circles) to start-, end- and mid-nodes of paths, activate these buttons on the snap controls bar:
 1 - Enable snapping
 7 - Snap nodes or handles
10 - Snap to cusp nodes
13 - Snap from and to centers of objects
Then grab a circle close to its center, drag it near a corner or end-node of a path and watch the snap indicator - drop the object when you see the message "Center to cusp node". Possibly you need to zoom in more closely to have better control about what snaps.

See also the section about snapping in Inkscape's manual:
<http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Snapping.html#Snapping-Objects>

Revision history for this message
diagramdrawer (diagramdrawer) said :
#3

Thank you very much ~suv. You've given me the clues I needed and the necessary access to the manual.

I realise now why I was confused. I was looking for "nodes", which means something else entirely in Inkscape, and I should have been looking for "markers".

I'm on my way, having already tested snapping and created some of my own markers. (The note concerning the bug about when a new marker appears in the list was most useful here.) I will probably have further questions to ask about some of the details.

Thank you Andrew P. for the references. I had a brief look at several most interesting programmes that I never knew existed. For the present, I'll stick with Inkscape if I can.

Revision history for this message
diagramdrawer (diagramdrawer) said :
#4

Actually, I will ask a further question straight away.

I created a circle marker and sorted out the snapping, but when I add it to the ends of line intervals, the line finishes at the centre of the circle, whereas I want the line to finish at the circumference of the circle. Similarly, when the marker is at the join of two line intervals, the two line intervals meet at the centre of the circle instead of stopping at the circumference.

I tried filling the circle with white fill. This worked in that it obliterated the line, but it was unsatisfactory because the boundary became extremely faint.

Later I want to create a second, larger, circle marker and place a letter inside it. Again, this won't look good if the line passes through the circumference and ending on the centre.

Revision history for this message
su_v (suv-lp) said :
#5

Both of these issues are limitations in the SVG file format [1] which defines how markers are rendered [2]:

1) Markers are by default centered on the node.

You can add a transformation to the marker definition, but then you need to create custom start and end markers: for example, the 'EmptyTriangleIn' and 'EmptyTriangleOut' from Inkscape's stock markers are defined with such an offset (as opposed to the filled 'TriangleIn' and 'TriangleOut').

When creating your custom marker, draw them around the SVG origin (top left corner of the page), group the object(s) and convert the group to a marker.
Then you can add a 'translate()' transform for the custom marker with the XML Editor (the marker definitions are stored in the <defs> section) [3]: select the group inside the definition of the custom marker, add a new attribute named 'transform', and set its value to 'translate(± r,0)' where r=radius of the circle in px (+ half of the stroke width used for the marker).
Alternatively (instead of adding a transformation to the group), you can also add refX and/or refY attributes to the marker definition, depending on the required offset of the marker from the nodes.

Here is an example with custom circle markers for start, mid and end nodes:
 (red stroke and solid white fill) -> transform added to group
 (green stroke and solid white fill) -> refX added to the marker definition
<http://imgh.us/custom-start-mid-end-marker-circle-1.svg>
(if the page fails to load (over capacity), try reloading it again - this is the only free image hosting service I'm aware of which accepts and serves SVG files)

2) Markers are placed on top of the path (i.e. the rendering of the stroke does not stop at the boundary of the marker)
Workaround: add a solid fill with the color of the background

[1] Inkscape does aim to fully implement the SVG 1.1 specification (and to not create proprietary [marker] features, so that SVG files created with Inkscape render the same in other SVG viewers). While Inkscape has not achieved 100% of SVG 1.1 support, this is an important goal on the roadmap to version 1.0.
[2] <http://www.w3.org/TR/SVG11/painting.html#Markers>
[3] <http://tavmjong.free.fr/INKSCAPE/MANUAL/html/XML.html>

Revision history for this message
su_v (suv-lp) said :
#6

> Later I want to create a second, larger, circle marker and
> place a letter inside it. Again, this won't look good if the
> line passes through the circumference and ending on the centre.

For such diagrams, consider working with connectors:
<http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Connectors.html>

1) Draw the circle, convert it to path ('Path > Object to Path')
2) Create the letter
3) Select path and letter and center them (using 'Object > Align and Distribute')
4) Group the path and letter ('Object > Group')
5) Duplicate the group as often as you need, and place the copies
6) Connect the groups with the connector tool

Note: the connector implementation in Inkscape is not perfect: while it works fine with rather simple diagrams, there are some annoying regressions in Inkscape 0.48 with incorrect rerouting (often related to preserved transforms on or inside groups, and to (nested) clones).

Can you help with this problem?

Provide an answer of your own, or ask diagramdrawer for more information if necessary.

To post a message you must log in.