Path effect: Turning inside-out

Post questions on how to use or achieve an effect in Inkscape.
DanielTr
Posts: 5
Joined: Thu Jun 25, 2009 6:29 am

Path effect: Turning inside-out

Postby DanielTr » Thu Jun 25, 2009 7:10 am

I am writing a mathematics thesis involving a lot of inkscape graphics.
Currently, I am stuck, as I need a very special type of transformation of a (so-called) planar graph.

As show in the picture below, I have created 4 paths (A). Now, I would like to `push' (B) the outermost 3 paths into the inner path (the blue face). It is like turning your clothing inside-out. That is the best I can describe it. ;)
The result is in (C). But, this is hand-made, and rather ugly. Preferably, the `outside' (around the blue face), is squeezed into the `inside' at the right proportions.

Is there an elegant way to do this in Inkscape?

Image
Attachments
InsideOut.svg
(24.08 KiB) Downloaded 205 times

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Path effect: Turning inside-out

Postby brynn » Fri Jun 26, 2009 11:44 am

I don't think there is, not in a single click, like a function or something.

I'm thinking I would use the Flip Horizontal for the red and green ones, and Flip vertical for the orange one. Then just take the the 2 outside nodes of each path and pull them out to the corners.

DanielTr
Posts: 5
Joined: Thu Jun 25, 2009 6:29 am

Re: Path effect: Turning inside-out

Postby DanielTr » Fri Jun 26, 2009 3:47 pm

Thanks for your comment!

Yes, you are right; there seems no functionality at hand that will make this very easy. I was not expecting on-click-and-you're-done, but maybe with some smart trick make it possible.
I tried for example the perspective tool, in combination with the Flip Horizontal. Then, one creates regions (paths) inside the `blue box', to which the `outer paths' are transformed. Still, this does not deserves any beauty-award.

What I think should be done is the following: execute a node-by-node mapping, where you take some point inside the `blue box' as point of origin (0,0). This origin should be mapped to (+infinity,-infinity), and the `borders' (which we presume to be (+infinity,-infinity)) to (0,0).

Maybe there is already a simple node-by-node transformation plugin, that I can start off from? I should have enough programming experience (C/C# etc).

User avatar
microUgly
Site Admin
Posts: 2985
Joined: Sat Jun 02, 2007 3:13 pm
Contact:

Re: Path effect: Turning inside-out

Postby microUgly » Mon Jun 29, 2009 3:18 pm

It's been requested a few times to be able to link nodes from seperate objects so you can more together--but can't be done yet.

Although, this isn't very complicated to do manually if you enable the appropriate snap-to-node setting and move the nodes for each object individually.

Note that with (C), you can't really turn a shape inside out, so that whilst originally it is filled inside and then folds out so the outer area is filled. Only a confined area can be filled, so you would need to create two shapes (or a single shape with a hole).

DanielTr
Posts: 5
Joined: Thu Jun 25, 2009 6:29 am

Re: Path effect: Turning inside-out

Postby DanielTr » Wed Jul 01, 2009 1:48 am

Yes, I see that there is a problem. On one side, there is the `outside' in (A) that does not actually exist in terms of a `dedicated' path, whilst it should be represented by a path in (C). Vice versa, as you correctly pointed out, the `inside path' should be turned outside, which will need additional nodes to be created.

Thinking about this, I came up with the following procedure. It just iterates over all nodes and re-positions them.

1. Init: choose some point (x',y') within the face (/path) that needs to be turned `inside-out'. This will be the point of origin for the translation
2. Then, iterate over all nodes, and reposition them as follows: (x*,y*) = ( 1/[x-x'], 1/[y-y'] )

Note, however, that this is probably not ideal: the transformation will be done `around' the edge of the unit circle. Thus, there needs some extra scaling to be done. Ideally, one replaces the 1/[x-x'] by u/[x-x'] where u is some value calculated by using the bounding box of the face...
Then, the only thing you need to do yourself (which seems relatively easy to do by hand!) is to add some nodes to the path of the inside face, and pull them to the corners of the background.

I would gladly program this myself, if only I had some clue (inspection of the Inkscape program files folder, searching for current filters didn't help me much...) how I should do this.

Maybe someone has a very simple example that shows how to iterate over all nodes? If one of you could give an example of a filter that shows how to update the coordinates of each individual node of any path, I think I can manage from there... :-)

Slow Dog
Posts: 180
Joined: Wed Sep 24, 2008 7:51 pm

Re: Path effect: Turning inside-out

Postby Slow Dog » Wed Jul 01, 2009 8:09 pm

DanielTr wrote:I would gladly program this myself, if only I had some clue (inspection of the Inkscape program files folder, searching for current filters didn't help me much...) how I should do this.

Maybe someone has a very simple example that shows how to iterate over all nodes? If one of you could give an example of a filter that shows how to update the coordinates of each individual node of any path, I think I can manage from there... :-)


It might be just that you're misled by incorrect terminology. What you need is a "Path Effect" (which can read and manipulate nodes), not a "Filter" (raster effects on shapes and colours).

They're all in <inkscape>/share/extensions, with a python source code for each. While I don't do python myself, a quick look found some loops (in extrude.py) that appeared to do as you suggest. There must be guides on the web somewhere describing inkscape's functions and data structures, of course.

DanielTr
Posts: 5
Joined: Thu Jun 25, 2009 6:29 am

Re: Path effect: Turning inside-out

Postby DanielTr » Fri Jul 03, 2009 5:43 am

Aaaahh, thanks for your advise! I have looked around, and although I am neither familiar with python, surely I should be able to figure it out. If I get it working, I will post the code 8-)

DanielTr
Posts: 5
Joined: Thu Jun 25, 2009 6:29 am

Re: Path effect: Turning inside-out

Postby DanielTr » Tue Jul 14, 2009 7:51 am

Success! I managed to create the path effect myself. Attached (at the bottom of this post) you will find a ZIP file with the two files that need to be placed in the /Share/Extensions/ directory. Then, after Inkscape has been (re)started, "Inside Out" should appear in the "Modify Path" submenu (in the Extensions menu of Inkscape). Tested with versions 0.46 and 0.47pre0-1.

For anyone interested, I have created a small explanation of the steps that need to be taken, plus some tips.

A. The collection of paths that need to be turned inside out. In the dialog window, one can enter the point of origin, but I prefer to set that to (0,0) and move the paths to the left-top corner.
B. When the effect is applied, there might be things sticking out.
C. In fact, when you push the blue face to the background, you'll see that it is not very nice. This strange result is caused by the fact that all controlpoints are equal to the point itself and therefore, the lines remain straight and cross each other.

D. A very simple solution (to the problem under C) is to make sure that for each line segment, the two control points are set at about 1/3 and 2/3 of the segment.
E. Now, when the effect applied again, the control points are shifted further outwards
F. Again, we want push the blue face to the back, such that we can see the other faces

G. To finalize the transformation, we need to `plug a hole' in the blue face, manually. To do so, create a rectangle, and convert it to a path
H. Then, select both the blue face, and the red box, and select "Difference" from the "Path" menu.
I. Now, pull the four nodes outside and you are done!

Image

Image

Image
Attachments
InsideOut.zip
(2.11 KiB) Downloaded 173 times


Return to “Help with using Inkscape”