Drawing hexagons and other regular polygons

2D CAD software for Windows, Mac OS X and Linux
Post Reply
debenriver
Posts: 619
Joined: Sat Dec 03, 2011 9:19 pm
Location: Maine USA and Suffolk England
Contact:

Drawing hexagons and other regular polygons

Post by debenriver »

Hi Eric

Is there a way that drawing regular polygons can be improved. Specifically hexagons because of drawing nuts and bolts.

In practical terms, hexagons for a nut or bolt head need to be drawn by the "Across Flats" (AF) dimension. So for example an M5 nut is 8mm AF. Its stated dimension across the points is not entirely accurate (in terms of drawing a hexagon) as the corners are rounded off. An M5 nut is 8.76mm across points (because the points are slightly chamfered off), which if you draw a hexagon to that dimension gives 7.59 AF.

With RealCADD at the moment you can draw an accurate hexagon across points by drawing a line the across points length and then drawing the hexagon from the centre of the line to the end points. But there is no way (that I have found) to do the same for an AF dimension.

Holding the shift key or the option key down just drags the final control point out so the hexagon is no longre closed. It doesn't constrain the hexagon so two sides are vertical or horizontal – or to any constraint angle

I have tried using the control key – and drawing from the centre of a line the AF dimension – and sometimes this will align with the end points of the line and the two opposing sides of the hexagon vertical – thus drawing an accurate AF hexagon. But it usually seems to cause RealCADD to crash, and is pretty unreliable anyway.

And it's not particularly easy to construct a hexagon from lines as the relationship between the length of the sides and the AF dimension involves √3.

It might be better if a hexagon at least – surely the most used regular polygon – could be drawn like a rectangle/square as a regular object rather than as a polygon. And perhaps a triangle as well, as this has the same problems being a 3-sided polygon.

Another line in the Tool window perhaps?

Cheers -- George
Eric Pousse
Posts: 868
Joined: Sat Dec 03, 2011 12:31 pm
Location: Tours - France

Re: Drawing hexagons and other regular polygons

Post by Eric Pousse »

Bonjour George

A little script can do the job :

Code: Select all

Dim dx, dy, long as double

dx = lastx - firstx
dy = lasty - firsty
long = sqrt(dx * dx + dy * dy)
    
Add_Polygon(firstx + long, firsty + long * tan(0.5235987756), 0.75, 7, 0, False, False, 100, 100)
Add_PointToPolygon(firstx + long, firsty - long * tan(0.5235987756))
Add_PointToPolygon(firstx, firsty - long / cos(0.5235987756))
Add_PointToPolygon(firstx - long, firsty - long * tan(0.5235987756))
Add_PointToPolygon(firstx - long, firsty + long * tan(0.5235987756))
Add_PointToPolygon(firstx, firsty + long / cos(0.5235987756))
Add_PointToPolygon(firstx + long, firsty + long * tan(0.5235987756))
The first click is the center of the hexagon and the length between the 2 clicks is AF / 2.

Voilà.
Cordialement.
Eric Pousse
debenriver
Posts: 619
Joined: Sat Dec 03, 2011 9:19 pm
Location: Maine USA and Suffolk England
Contact:

Re: Drawing hexagons and other regular polygons

Post by debenriver »

Ah - hadn't thought of that!

Ok - great - but I don't quite know how to get it to work. Do I have to have any User input? Does it run after clic and drag or Immediately? It's going to draw a line not a rectangle?

I can't seem to make it work just as it is. It just produces an error and crashes RealCADD. Sorry – I'm a bit rusty with Scripts!

Many thanks -- george
Eric Pousse
Posts: 868
Joined: Sat Dec 03, 2011 12:31 pm
Location: Tours - France

Re: Drawing hexagons and other regular polygons

Post by Eric Pousse »

Sorry George,

The complete script is here :
https://adx-online.com/hexagon.zip

Simply, draw a line, the first point is the center of the hexagon and the length of the line is AF / 2.

Cordialement.
Eric Pousse
debenriver
Posts: 619
Joined: Sat Dec 03, 2011 9:19 pm
Location: Maine USA and Suffolk England
Contact:

Re: Drawing hexagons and other regular polygons

Post by debenriver »

Thanks Eric

Works fine!! Don't know what I was doing wrong ....

Nice to use the Script availability – apart from my two beamcamber scripts (which are a bit specialist I suppose), the others have been overtaken by program advances!

Cheers -- George

PS - will you be able to fix the font size problem soon do you think??
Eric Pousse
Posts: 868
Joined: Sat Dec 03, 2011 12:31 pm
Location: Tours - France

Re: Drawing hexagons and other regular polygons

Post by Eric Pousse »

debenriver wrote: Sat Oct 16, 2021 12:22 pm PS - will you be able to fix the font size problem soon do you think??
Yes it is fixed and I will upload a new version very soon.
Eric Pousse
Post Reply