Created
April 18, 2022 05:58
-
-
Save Hermann-SW/68abcab9ffcf8a61d2422f5c34564896 to your computer and use it in GitHub Desktop.
First (nearly) minimal script for execution in FreeCAD Python console
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
# store as eg. '/home/pi/tetrahedron.py', then execute in FreeCad Python console by: | |
# exec(open('/home/pi/tetrahedron.py').read()) | |
import FreeCAD,FreeCADGui | |
import Part | |
import math | |
if FreeCAD.ActiveDocument == None: | |
FreeCAD.newDocument() | |
obj=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","tetrahedron") | |
r = 5 | |
v=[ FreeCAD.Vector( math.sqrt(8/9), 0, -1/3).multiply(r), | |
FreeCAD.Vector(-math.sqrt(2/9), math.sqrt(2/3), -1/3).multiply(r), | |
FreeCAD.Vector(-math.sqrt(2/9), -math.sqrt(2/3), -1/3).multiply(r), | |
FreeCAD.Vector( 0, 0, 1).multiply(r) ] | |
faces=[] | |
faces.append(Part.Face(Part.makePolygon([v[0],v[1],v[2],v[0]]))) | |
faces.append(Part.Face(Part.makePolygon([v[0],v[1],v[3],v[0]]))) | |
faces.append(Part.Face(Part.makePolygon([v[0],v[2],v[3],v[0]]))) | |
faces.append(Part.Face(Part.makePolygon([v[1],v[2],v[3],v[1]]))) | |
shell = Part.makeShell(faces) | |
solid = Part.makeSolid(shell) | |
obj.Shape = solid | |
obj.ViewObject.Proxy=0 | |
FreeCAD.ActiveDocument.recompute() | |
FreeCADGui.SendMsgToActiveView("ViewFit") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Coordinates taken from Wikipedia:
https://en.wikipedia.org/wiki/Tetrahedron#Coordinates_for_a_regular_tetrahedron