Generalized alignment (pairwise)

Flesh out your ideas for new or improved Inkscape features before submitting a request.
mathog
Posts: 82
Joined: Tue Feb 08, 2011 6:05 am

Generalized alignment (pairwise)

Postby mathog » Sat Jan 07, 2012 6:17 am

Most drawing programs, inkscape included, only provide "special alignment". That is, projection of objects onto a line. It would be nice if Inkscape also provided "generalized alignment" as indicated in the attached diagram. Generalized alignment is the pairwise linear mapping of one object onto another via rotation, translation, and scaling. The math to accomplish this is trivial, making the interface user friendly much less so. Inkscape currently has "transform", which does this, but requires the user to punch in a bunch of numbers. The method suggested here does the same thing in a more GUI friendly manner. Basically the idea is to let the user identify a vector for each object, as it is easy to visualize the 2D motion to move one arrow onto another. Generalized alignment would provide a way to snap together objects at precise angles, to get a perfect fit at the junctions.

Please refer to the attached drawing. It illustrates the "standard vectors", which are defined with respect to a unit reference vector. The first 3 examples across the top show reference vectors corresponding to the X axis, an arbitary vector, and the Y axis. The fourth example (top right) show how special user defined vectors might look. The examples below that show how generalized alignment would work for some cases, named vector on one object mapping onto a named vector on another object.

Leaving aside the user defined vectors for the moment, the way I imagine this might work is that one would first select two objects in Inkscape. (It might make sense in some instances to use this on >2 objects, in which case the last one would be fixed and all the others would move.) Open the "general pairwise alignment" window. There will be two images like the one shown in the upper left hand corner of the illustration and two regions labeled something like "source" and "target" or "from" and "to". Additionally there would be a "scale" checkbox.

The reference vector selector would have check boxes for x,y, and custom, with an angle value for the latter. (The existing alignment/distribution only works on x or y.)

In the window:

1. check or uncheck scale (irrelevant for unit vector to unit vector)
2. for each object set the reference vector
3. for each object select one of the named vectors: 1->9, length, width, major, minor by clicking on it, or click on the "user defined" vector.

When all 3 steps have been completed the first (set of) object(s) would be mapped as indicated onto the target. Note that except for user defined vectors no additional metadata need be associated with the objects. The vectors can be calculated on the fly from the object and the reference vector specified.

User defined vectors are a bit more challenging. These would be defined with respect to one or more nodes on a path
as shown in the upper right hand corner. Presumably this would be added to the "edit nodes" menu as something like:

"special vector from node(s)"

1. define normal
2. define tangent
3. define connect
4. define arbitrary (puts up a vector like a "handle" that the user can rotate)
5. reverse (flip the vector already defined by 1->4)
6. clear

The first 3 act on a single selected node, 4 requires two nodes, 5 requires that the vector already exist, and 6 deletes one if it does exist, or does nothing if it doesn't. Storing this vector is where it gets complicated, it is a sort of metadata. It needs to be associated with the object but shouldn't be visible in any rendering of the image. However it does need to be visible at least in "edit nodes". The closest thing to this currently in Inkscape is the Extension "draw handles" under "visualize paths".

Some of these vectors have length, others are unit vectors. The length may be ignored (if the scale box is not checked), otherwise the "from" object is scaled so that its vector is the same size as the vector in the "to" object.

Note, the concept of the vectors 1->9 appears in various other graphics environments, for instance in text placement in CGM.

Definitions of the non unit standard vectors:

Length: vector parallel to the reference vector with length equal to the projection of the object onto the unit reference vector.
Width: rotate the reference vector 90 degrees counterclockwise, and then as for Length.
Major: The vector corresponding to the longest path that may be drawn across the object. If the object is symmetric
and has multiple longest paths then pick the one that has the largest dot product with the reference vector.
Minor: Rotate the Major vector 90 degrees counterclockwise, convert to unit vector, project object onto it as for length/width.

These vectors are independent of the chosen reference vector: Major, minor, all user defined vectors.
Attachments
generailzed _alignment.svg
(94.98 KiB) Downloaded 364 times

mathog
Posts: 82
Joined: Tue Feb 08, 2011 6:05 am

Re: Generalized alignment (pairwise)

Postby mathog » Sat Jan 07, 2012 6:31 am

I forgot one other thing, a checkbox "define transform". This would let the general alignment interface be used to define a transform, and then that could be used with the existing "transform" tool to move a bunch of other objects. If define transform is checked, nothing happens immediately.

Consider the case where a complex object composed of many sub objects has to be transformed to mate up with another part of the drawing. To do so, select one sub object that can be placed precisely, use the general alignment interface to define the transform, and then select the whole assembly and apply the transform.

mathog
Posts: 82
Joined: Tue Feb 08, 2011 6:05 am

Re: Generalized alignment (pairwise)

Postby mathog » Sat Jan 07, 2012 7:08 am

Sorry about the typo in the attachment's filename.

mathog
Posts: 82
Joined: Tue Feb 08, 2011 6:05 am

Re: Generalized alignment (pairwise)

Postby mathog » Sun Jan 08, 2012 3:21 am

There are a few complications that also need to be dealt with.

The position of the standard arrows will need to be defined with respect to the borders, if these are present. Towards that end, each of the two panels would also need a radio button with the options: inner, center, outer. If there is no border it won't matter which is checked. See the attachment for examples. Zoom in to see the unit vector used for the alignment in each case. Basically this is needed in order to precisely overlap borders as desired, especially when the borders have different stroke widths. Without this one must carefully line things up by eye, which tends to be slow and error prone. Most likely only a couple of the 9 combinations for mismatched borders would actually be used, as the others result in the border of one object impinging on the interior of the other.

Additionally, for scale, rather than just on or off, it might as well be:

1. none
2. automatic (based on arrow sizes)
3. manual (enter a scale factor into the space provided)
Attachments
border_treatment.svg
(62.85 KiB) Downloaded 226 times


Return to “Inkscape Ideas”