Macro Triangle AH
File:Text-x-python Macro triangleAH |
Description |
---|
This macro create one triangle creates a triangle by giving the head angle and the height of the triangle. Author: mario52 |
Author |
mario52 |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.0 |
Date last modified |
None |
FreeCAD Version(s) |
None |
Default shortcut |
None |
See also |
None |
Description
This macro create one triangle creates a triangle by giving the head angle and the height of the triangle (the triangle of the head is positioned to the xyz coordinates 0.0.0)
Use
Copy the macro triangleAH complete in the Python console FreeCAD and type:
triangleAH(angle=90, height=10)
# or
triangleAH(90, 10)
Script
Macro_triangleAH.FCMacro
__title__ = "triangleAH"
__author__ = "Mario52"
__version__ = "00.01"
__date__ = "20/03/2015"
from math import cos, sin, tan, degrees, radians, sqrt
import Draft, Part
def triangleAH(angle, height):
def line_length(x1 = 0.0, y1 = 0.0, z1 = 0.0, length = 10.0, angle2 = 0.0): # search coordinates
x2 = x1 + (length * cos(radians(angle2)))
y2 = y1 + (length * sin(radians(angle2)))
z2 = z1 #+ ()
return x2,y2,z2 # return coordinates (xyz) to point
x0 = y0 = z0 = 0.0
a0 = line_length(x1=x0,y1=y0,z1=z0,length=height,angle2=0 ) #
hypo = height / cos(radians(angle/2))
a0 = line_length(x1=x0,y1=y0,z1=z0,length=0, angle2 = angle ) # point 0 (depart sommet)
a = line_length(x1=a0[0],y1=a0[1],z1=a0[2],length= hypo, angle2=-(angle/2)) #
b = line_length(a[0],a[1],a[2],length= (abs(a[1])*2), angle2=90.0) # base du triangle
return Draft.makeWire([FreeCAD.Vector(a0),FreeCAD.Vector(a),FreeCAD.Vector(b)],closed=True,face=False,support=None) # create triangle
Version
ver 00.01 20/03/2015 :