Polygon rotation snap

Post questions on how to use or achieve an effect in Inkscape.
il_mix
Posts: 5
Joined: Wed Feb 27, 2013 2:16 am

Polygon rotation snap

Postby il_mix » Wed Feb 27, 2013 2:24 am

I think it's an easy problem to solve...
When I draw a polygon, specifically an 8 angles one, I would like to rotate it so the base is horizontal (like the polygon in the polygon/star icon :tool_star: ). Pressing Ctrl while drawing, the rotation snaps to multiple of 15°, but it never look "horizontal". Same thing when rotating after draw.
How to do that?

Thaks a lot!

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

Re: Polygon rotation snap

Postby brynn » Wed Feb 27, 2013 6:59 pm

Image
Welcome to InkscapeForum!

Aaahh, yes, that's one thing I've found very difficult to do with Inkscape. I don't know why the Star tool doesn't draw the star/polygon horizontally, like the Rectangle tool does. I find it very frustrating that it spins around while I draw it. I don't know if that would be "fixable" or if it would require a whole new feature. If I were to guess, I would say that it spins around like that, because it's necessary for some of the Star tools awesome features. (I've been tempted to request such a feature.....

The only way I've found to approximate a perfectly horizontal placement, is to drag down a horizontal guide. First draw the polygon. Drag it towards the guide, so that one of the corners (that you want aligned to the guide) is close to the guide. Then switch to the Selection tool and put in "rotate mode". Then you can use the guide line to visually estimate when the side is parallel to the guide. I know it's not a perfect solution -- not by far!

I don't know, maybe one of our geometry experts (ah-hm, druban, Ragstian, Pilosopong Tasyo, others that don't come to mind immediately) can think of a way to use guides more productively than that, along with snapping?

OH! Actually I might have just thought of something myself. Let me do some testing, and I'll post again :D

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Polygon rotation snap

Postby druban » Wed Feb 27, 2013 7:20 pm

Inkscape Preferences> Rotation snaps every > 22.5 degrees.

vertices of an octagon are 45 degrees apart. first vertex is drawn at 0. etc ec.

EDIT: I am not sure at what version 22.5 became an option in the dropdown for snap angles, so you might need to wait/upgrade! It's available in dev. versions.
Last edited by druban on Fri Mar 01, 2013 8:24 am, edited 1 time in total.
Your mind is what you think it is.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Polygon rotation snap

Postby Lazur » Wed Feb 27, 2013 7:38 pm

There are two ways come to my mind:
1. Draw an octogon with holding down Ctrl and aligning the controlpoint on the vertical axis, then rotate it through the transformation panel.
Shift+Ctrl+m calls that panel, and you should rotate it with 22,5°.
2. Draw a hexadecagon or an octogram with holding down Ctrl and aligning the controlpoint on the vertical axis, then convert it to path with pressing Ctrl++.
Then delete every unnecessary second nodes, and make all segments straight lines.

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

Re: Polygon rotation snap

Postby brynn » Wed Feb 27, 2013 7:53 pm

Aaahh, very good point, druban and Lazur URH!

As far as making any star's points, or polygon's sides lie on a horizontal line, I'm still stumped. I found a way to do it, that theoretically should work. I'm stuck on a snapping issue, so maybe dvlierop will stop by.

First drag out 1 horizontal guide and 1 vertical guide. Drag the star/polygon over near the guide intersection. Go back and engage the Star tool again. If it's a polygon, grab the handle, and if it's a star, grab the outer handle. Drag it towards the intersection of guides, and it should snap right to it. Next, with Selection tool, click twice to reveal the rotation handle (small + in the center of the object). Grab that and drag it also towards the guide intersection until it snaps.

Next, the only way this can be done, is to do Path menu > Object to Path to the star/polygon. I don't know how it could possibly be done with snapping, unless it's changed to a path. If you grab the rotation handle that's closest to the other corner (that you want to be horizontal to the handle corner, and snapped to the guide) (and you have your snap settings in Inks Prefs to "Only snap the node closest to the pointer") that corner node should snap to the guide, as you rotate. I don't know why it doesn't Image

il_mix
Posts: 5
Joined: Wed Feb 27, 2013 2:16 am

Re: Polygon rotation snap

Postby il_mix » Wed Feb 27, 2013 9:58 pm

Well, it looks like a "not-so-easy-to-solve" problem.
I think that the solution suggested by druban is the fastest and more "clean". Ok, you must change the rotation snaps angle for (almost) every polygon you will draw, and do a little fanta-blasting-trygonometric math every time.
By the way, I think I'll use this solution.

brynn, if you'll write down a petition for the new feature, I'm in!

Thanks to everyone
MIX

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Polygon rotation snap

Postby ragstian » Thu Feb 28, 2013 12:50 pm

Hi brynn.

I thought "I'am doing this all the time - no problem" - but I had to check.
(Living in Texas - have to draw the "Lone Star" every now and then! ;) )

When drawing the pentagon (or star) click on the canvas, pull the mouse pointer straight down, release - press the V key to flip the star horizontally.
(I have my rotation snap set to 22.5°)

Easy? (or do I misunderstand the problem?)

RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

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

Re: Polygon rotation snap

Postby brynn » Thu Feb 28, 2013 6:08 pm

Hi Ragnar,
I guess that would work with a grid and snapping enabled. But on an open canvas (or grid without snapping) the star or polygon literally spins around as I draw it. I can't keep good enough control of the mouse to drag it precisely vertically. But even with having to use the grid and snapping, it's better than nothing!

Thanks :D

PS -- But I'm still curious why the node won't snap to the guide while rotating the star.

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Polygon rotation snap

Postby ragstian » Thu Feb 28, 2013 11:41 pm

:D Hi brynn

What snap settings are you using? The node snaps fine on my system.
Don't use the "select and transform object" -F1 - to rotate but rather the star tool itself *.
( Using Inkscape 0.48+devel r12137. (Always using the latest and greatest!))
I am also curious about your mouse settings, (sensitivity, resolution etc), might be time for some hardware upgrades? :D :D :?: :D :D

RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Polygon rotation snap

Postby ~suv » Fri Mar 01, 2013 3:46 am

brynn wrote:PS -- But I'm still curious why the node won't snap to the guide while rotating the star.

Because this snap feature does not (and never did) exist in current stable Inkscape (0.48) [1] - only guides can snap while rotating them (to other guides, to grid lines, to nodes, etc).

And yes, it will be a new snap feature [1] in the next major release (0.49) (*)

---
[1] Edit: this refers to snapping while rotating with the select tool (F1) (thx ragstian for mentioning that detail)

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

Re: Polygon rotation snap

Postby brynn » Fri Mar 01, 2013 8:36 am

Ah-ha! Well then it makes sense why it doesn't work, lol. But I'm sure I've seen things snap during a rotation. I can't think of any specific examples, but it seems like I've seen it before....

Well anyway, thanks for the info :D

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Polygon rotation snap

Postby druban » Fri Mar 01, 2013 6:06 pm

Off topic:
brynn wrote:But I'm sure I've seen things snap during a rotation.

Usually it's when you rotate it one time more than you should... :lol:
Your mind is what you think it is.

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

Re: Polygon rotation snap

Postby brynn » Sat Mar 02, 2013 2:55 pm

:mrgreen:

logiclrd
Posts: 1
Joined: Sat Oct 25, 2014 11:13 am

Re: Polygon rotation snap

Postby logiclrd » Sat Oct 25, 2014 11:37 am

I have found a way to get a very precise rotation using the following steps. They assume that you want to get two adjacent vertices in the polygon to have exactly the same 'x' or exactly the same 'y'. You'll need to convert your polygon to a path in order to do this, but the end result should be as close to exactly what you want as you're going to get without special code to do this type of snapping for you. :-)

1. Get the polygon's centre exactly on one of the two adjacent vertices

The centre is stored in the XML using attributes "inkscape:transform-center-x" and "inkscape:transform-center-y". These are relative to the centre of gravity of the polygon. In order to set them, then, you need to find out the coordinates of the vertex relative to the centre of gravity. The easiest way I found to achieve that is to put the polygon's centre of gravity at the origin (0, 0), which I did this way (there might be an easier way?):

  1. Select the freehand lines tool (F6).
  2. Click anywhere in the canvas, and then hold down Ctrl while clicking below the line to make a perfectly vertical line.
  3. Switch to the selection tool (F1) and select the line as an object.
  4. In the toolbar, manually enter an X coordinate of 0, snapping the line to Y axis.
  5. Select your polygon, then shift-click the line.
  6. In the Align and Distribute panel, make sure that "Relative to" is set to "Last Selected", then click on "Center on vertical axis" in the first row.
  7. Select the guide line and delete it. Next, we'll create a similar guide line for the horizontal axis.
    [*} Click once, and then use Ctrl while clicking to the right of the line to create a perfectly horizontal line.
  8. Select it with the selection tool, and set its Y coordinate in the toolbar to 0, snapping it to the X axis.
  9. Select your polygon, then shift-click the line.
  10. In the Align and Distribute panel, with "Relative to" still set to "Last Selected", click on "Center on horizontal axis" in the second row.

Now the polygon's centre is at exactly (0, 0). This means that the absolute coordinates of its vertices are also relative to its centre of mass. So, now we move the centre to *exactly* coincide with one of the two vertices you want to flatten out.

  1. Using the selection tool (F1), click on the object twice to put it into rotate mode. Then, drag the centre anywhere. This will create the attributes for specifying the transform centre so you don't have to input them yourself.
  2. Open the XML editor (Ctrl-Shift-X). It should immediately have the <svg:path> element selected.
  3. Switch to the nodes tool (F2) and select one of the ends of the segment you want to be flat.
  4. Select & copy the value of the X coordinate in the toolbar.
  5. In the XML editor, click on the row "inkscape:transform-center-x" in the right upper pane. In the right lower pane, replace the value with the number you copied from the toolbar. Press Ctrl-Enter to commit the change.
  6. Select & copy the value of the Y coordinate in the toolbar.
  7. In the XML editor, click on the row "inkscape:transform-center-y" in the right upper pane. In the right lower pane, replace the value with the number you copied from the toolbar. Press Ctrl-Enter to commit the change.

You should now see the little '+' icon for the transform centre exactly coinciding with the vertex you selected. :-)

2. Create a guide & rotate the polygon

At this point, rotating the polygon will preserve the position of the first vertex, the one that now coincides with the transform centre. To actually get the rotation you want, you now want to apply rotation so as to move the other vertex to the same x or y coordinate as the first. Start by creating a guide:

  1. Create a perfectly horizontal or vertical line using the free-form lines tool (F6), by clicking, and then holding down Ctrl before clicking a second time.
  2. Switch to the nodes tool (F2) and select the first vertex in your polygon, the one from the previous steps. If your guide is horizontal, select & copy the Y coordinate. If your guide is vertical, select & copy the X coordinate.
  3. Switch to the selection tool (F1) and select your guide again. Paste the copied coordinate into the corresponding coordinate on the toolbar for your line. It should now pass straight through the point of rotation of the polygon!

You're now all set for the final step: the actual rotation of the polygon. After completing the previous steps, the polygon will rotate precisely around the first point, and you can rotate it until the second point is also exactly on the guide:

  1. With the selection tool (F1), click on your polygon twice to get it into rotate/skew mode and rotate it until the second point is "pretty close" to the guide.
  2. Zoom in extremely close on that second point, as far as you can while keeping both the point and the guide on the screen.
  3. The keyboard shortcut Alt-[ or Alt-] rotates "by pixels", which means that the further zoomed in you are, the finer the rotation is. Rotate the polygon until you can't see any difference between the location of your second vertex and the guide.
  4. If you can zoom in further, do so and repeat the previous step. Repeat as needed.
  5. When you're done, delete the guide and admire your handy-work.

Hope that's helpful to someone out there. :-) It's a bit of leg work, but it does get the job done!

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Polygon rotation snap

Postby tylerdurden » Sat Oct 25, 2014 12:02 pm

~suv wrote:
brynn wrote:PS -- But I'm still curious why the node won't snap to the guide while rotating the star.

Because this snap feature does not (and never did) exist in current stable Inkscape (0.48) [1] - only guides can snap while rotating them (to other guides, to grid lines, to nodes, etc).

And yes, it will be a new snap feature [1] in the next major release (0.49) (*)

[1] Edit: this refers to snapping while rotating with the select tool (F1) (thx ragstian for mentioning that detail)


I can confirm the rotation snapping is functional in the pre-.91
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Polygon rotation snap

Postby Xav » Sat Oct 25, 2014 7:18 pm

brynn wrote:I guess that would work with a grid and snapping enabled. But on an open canvas (or grid without snapping) the star or polygon literally spins around as I draw it. I can't keep good enough control of the mouse to drag it precisely vertically.


Hold down CTRL whilst dragging to make it easier. With an odd number of sides Ragnar's approach works okay if you hold CTRL, and if you drag up rather than down you don't even have to press V afterwards. For an even number, however, you're still left having to rotate afterwards - but by a defined amount (180 divided by the number of sides) which you can easily do in the Transform dialog.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter


Return to “Help with using Inkscape”