Last active
August 4, 2020 11:25
-
-
Save gbroques/d52f31fe629392017d254b4d71b91516 to your computer and use it in GitHub Desktop.
Make a hexagonal prism in FreeCAD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import radians, sqrt | |
import Part | |
from FreeCAD import Matrix, Vector | |
def make_hexagonal_prism(minimal_diameter: float, height: float) -> Part.Solid: | |
hexagon_wire = make_hexagon_wire(minimal_diameter) | |
hexagon_face = Part.Face(hexagon_wire) | |
return hexagon_face.extrude(Vector(0, 0, height)) | |
def make_hexagon_wire(minimal_diameter: float) -> Part.Wire: | |
r"""Make hexagon wire. | |
:: | |
_____ ┯ | |
/ \ | | |
/ \ | minimal diameter | |
\ / | | |
\_____/ | | |
┷ | |
:param minimal_diameter: Diameter of the inscribed circle | |
distance between parallel sides, | |
or flat-to-flat distance. | |
:return: Hexagon wire | |
""" | |
matrix = Matrix() | |
matrix.rotateZ(radians(60)) | |
hexagon_vertices = [] | |
vector = Vector(minimal_diameter / sqrt(3), 0, 0) | |
for i in range(6): | |
hexagon_vertices.append(vector) | |
vector = matrix.multiply(vector) | |
hexagon_vertices.append(vector) | |
return Part.makePolygon(hexagon_vertices) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was adapted from the following code-snippet:
https://forum.freecadweb.org/viewtopic.php?t=6558&start=50#p125042