Graph Grammars

An elegant method to save a grammar using topologicpy is to store each rule as an edge and to store the whole grammar as a list of edges. The two vertices of each edge store the shapes (closed wires). The start vertex stores the left-side shape and the end vertex of the edge stores the right-side shape. The edge itself stores a dictionary with values that indicate its name, purpose, and any other needed information.

from topologicpy.Vertex import Vertex
from topologicpy.Edge import Edge
from topologicpy.Wire import Wire
from topologicpy.Face import Face
from topologicpy.Topology import Topology

# Create an L-shaped polygon with specific parameters
t_shape_01 = Wire.TShape(width=0.5, a=0.25, b=0.25, placement="lowerleft")

t_shape_02 = Topology.Translate(t_shape_01, 2, 0, 0)
t_shape_02 = Topology.Rotate(t_shape_02, angle=32.5)
t_shape_02 = Topology.Scale(t_shape_02, x=2, y=2, z=2)
Topology.Show(t_shape_01, t_shape_02)
rep_01 = Wire.Representation(t_shape_01, mantissa=6)
rep_02 = Wire.Representation(t_shape_02, mantissa=6)

print(rep_01)
print(rep_02)

print(Wire.IsSimilar(t_shape_01, t_shape_02))
[1.0, 90.0, 2.0, 90.0, 4.0, 90.0, 2.0, 90.0, 1.0, 90.0, 6.0, 2.0, 90.0, 6.0, 90.0]
[1.0, 90.0, 2.0, 89.999969, 4.0, 90.000066, 2.0, 89.999965, 1.0, 90.0, 6.0, 2.0, 90.000073, 6.0, 90.000012]
True