Hi All,
@SamPage’s excellent makehatch routine has stopped working in Rhino7 alas! I’m looking at making a grasshopper and python equivalent using this LISP .pat file maker routine as a base. the .pat file is an elegant format but I’m having difficulty reverse engineering it in code. The hacky script is as follows, but It’s not outputting the correct values. the .pat file (test) output should look like this:
*rigidEPS
;
;angle, x, y, shift, offset, dash, space
108.434948823, 2, 3, -9.486832981, 3.16227766, 3.16227766, -28.460498941
45, 1, 6, 7.071067812, 7.071067812, 4.242640687, -9.899494937
333.434948823, 4, 9, 8.94427191, 4.472135955, 4.472135955, -17.8885438
251.565051177, 8, 7, 9.486832981, 3.16227766, 3.16227766, -28.4604989
236.309932474, 7, 4, 13.8675049, -2.773501, 3.605551275, -32.4499615
165.963756532, 5, 1, 9.701425, 2.42535625, 4.123105626, -37.107950631
Vector math pro’s any clues? Any help gratefully appreciated, there’s a custom hatch making hole in rhino and this would fill it!
R
here’s the . gh, python code below,
import rhinoscriptsyntax as rs
import Rhino as rh
import System as sys
import scriptcontext as sc
import math
import Rhino.Geometry as rg
lines = [ [(2, 3, 0), (1, 6, 0)],
[(1, 6, 0), (4, 9, 0)],
[(4, 9, 0), (8, 7, 0)],
[(8, 7, 0), (7, 4, 0)],
[(7, 4, 0), (5, 1, 0)],
[(5, 1, 0), (1, 2, 0)]
]
def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
if lines:
def write_pat_file(lines):
with open('output.pat', 'w') as f:
pat_string = '*rigidEPS\n;\n;angle, x, y, deltaX, deltaY, dist, gap\n'
for line in lines:
x1, y1, _ = line[0]
x2, y2, _ = line[1]
startPoint = rg.Point3d(x1,y1,0)
endPoint = rg.Point3d(x2,y2,0)
curLine = rg.Line(startPoint,endPoint)
Dist = curLine.Length
angle = math.degrees(math.atan2(y2 - y1, x2 - x1))
if angle < 0:
angle += 360
x_axis = rg.Vector3d.XAxis
vec = startPoint - endPoint
vec2 = endPoint - startPoint
ang_to = rg.Vector3d.VectorAngle(vec, x_axis)
ang_from = rg.Vector3d.VectorAngle(vec2, x_axis)
angleRadians = round(math.radians(math.atan2(y2 - y1, x2 - x1)), 6)
Dist = curLine.Length
if abs(x1-x2) <0.0001 or abs(y1-y2) <0.0001:
delta_x = 0
delta_y = 10
Dist = curLine.Length
Gap = Dist * - 10
else:
Ang = ang_to if ang_to < math.pi else ang_from
#Ang = ang_from
AngZone = math.floor(Ang / (math.pi / 4))
Factor = 1
RF = 1
Gap = 0
print AngZone
if AngZone == 0:
DeltaY = abs(math.sin(Ang))*10
DeltaX = (2 * math.sin(Ang/2)) / math.cos(Ang/2) * 20
print str(DeltaX) + " test"
print DeltaY
print Ang
Gap = -(Dist - abs(Factor / DeltaY))*10
elif AngZone == 1:
DeltaY = abs(math.cos(Ang))*10
DeltaX = -abs(math.sin(Ang))*10
print DeltaX
print DeltaY
Gap = -(Dist - abs(Factor / DeltaY))*10
elif AngZone == 2:
DeltaY = abs(math.cos(Ang))*10
DeltaX = -abs((1/abs(math.cos(Ang))) - abs(math.tan(Ang)))*10
print DeltaX
print DeltaY
elif AngZone == 3:
DeltaY = abs(math.sin(Ang))* 10
DeltaX = abs(math.cos(Ang))* 10
print DeltaX
print DeltaY
Gap = (Dist - (abs((Factor / DeltaX)*100)))
print Gap
pat_string += '{}, {}, {}, {}, {}, {}, {}, {}\n'.format(angle, x1, y1, DeltaX, DeltaY, Dist, Gap, AngZone)
return pat_string
a = write_pat_file(lines)
print(a)