Skip to content
Snippets Groups Projects
Commit 028c23ac authored by mehtank's avatar mehtank
Browse files

Initial boatbase

parent 772d9975
Branches
No related merge requests found
from svggen.api.component import Component
from svggen.api.composables.graph.Face import Face, Rectangle, RightTriangle
from svggen.api.composables.GraphComposable import Graph
from svggen.api.ports.EdgePort import EdgePort
import svggen.utils.mymath as math
class BoatBase(Component):
_test_params = {
"length": 100,
"width": 20,
"height": 10,
"bow": 35,
"stern": 5,
}
def define(self):
self.addParameter("length", 100)
self.addParameter("width", 30)
self.addParameter("height", 20)
self.addParameter("bow", 15)
self.addParameter("stern", 5)
def assemble(self):
l = self.getParameter("length")
w = self.getParameter("width")
h = self.getParameter("height")
b = self.getParameter("bow")
s = self.getParameter("stern")
graph = Graph()
bottom = Rectangle("", l, w)
graph.addFace(bottom, "bt")
lt = Rectangle("", l, h)
graph.attachFace("bt.e0", lt, "e2", prefix="lt", angle=90)
rt = Rectangle("", l, h)
graph.attachFace("bt.e2", rt, "e0", prefix="rt", angle=90)
def point(lbl, b, edge, flip=False):
lb = math.sqrt(h*h+b*b)
ab = math.rad2deg(math.arctan2(h,b))
f = Face("", ((w/2.,0), (0, lb), (-w/2., 0)))
graph.attachFace("bt."+edge, f, "e0", prefix=lbl, angle=ab)
lb = math.sqrt(w*w/4.+b*b)
ab = math.rad2deg(math.arctan2(w/2.,b))
f1 = RightTriangle("", h, lb); e1 = "e0"
f1a = RightTriangle("", h, lb)
f1b = RightTriangle("", lb, h)
f2 = RightTriangle("", lb, h); e2 = "e2"
f2a = RightTriangle("", lb, h)
f2b = RightTriangle("", h, lb)
if flip:
f1, f2 = f2, f1
f1a, f2a = f2a, f1a
f1b, f2b = f2b, f1b
e1, e2 = e2, e1
graph.attachFace("rt."+edge, f1, e1, prefix=lbl+"rt", angle=ab)
graph.attachFace(lbl+"rt.e1", f1a, "e1", prefix=lbl+"rta", angle=180)
graph.attachFace(lbl+"rta."+e2, f1b, e1, prefix=lbl+"rtb", angle=-180)
graph.attachFace("lt."+edge, f2, e2, prefix=lbl+"lt", angle=ab)
graph.attachFace(lbl+"lt.e1", f2a, "e1", prefix=lbl+"lta", angle=180)
graph.attachFace(lbl+"lta."+e1, f2b, e2, prefix=lbl+"ltb", angle=-180)
point("bow", b, "e1")
point("stern", s, "e3", flip=True)
self.composables["graph"] = graph
if __name__ == "__main__":
h = BoatBase()
h._make_test()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment