Skip to content

Instantly share code, notes, and snippets.

@Erhannis
Forked from o8ruza8o/CutCircularArc.json
Created February 3, 2016 06:26
Show Gist options
  • Save Erhannis/b52053ad78229a5b52dd to your computer and use it in GitHub Desktop.
Save Erhannis/b52053ad78229a5b52dd to your computer and use it in GitHub Desktop.
Plethora Add-In Technical Exercise

Plethora Technical Exercise

The aim of this exercise is to test your ability to write clean, well structured code. Feel free to choose any imperative object oriented language that is freely available.

You are given the task of automating the quoting for parts to be made with a 2 axis laser cutting machine. When a user submits their design for laser cutting, it automatically gets converted to a 2D object which represents the profile of the design's extrusion.

Profile Representation

A profile contains a set of edges, each of which derive from a type of curve. Edges adjoin to one another at vertices so that each edge has one or two vertex endpoints. Each edge and vertex element is keyed by a unique integer, id. A profile is stored in a JSON file that is organized like Schema.json.

We will consider two types of curve in this exercise, straight line segments and circular arcs. While a line segment is completely defined via its vertices, circular arcs contain the additional Center and ClockwiseFrom fields. The ClockwiseFrom field references the vertex from which the circular arc may be drawn clockwise until it reaches the other vertex for that edge.

All units are in inches.

Quoting

Main considerations that should be taken into account when quoting a part are material costs and machine cost.

Material costs are proportional to the area of stock used for the part in optimal orientation. Stock is pre cut into rectangular shape where, to consider kerf thickness from the laser, additional padding is added to the design's bounds in each dimension to define stock size.

Machine costs are proportional to the time laser spends cutting. It may be considered that the speed of the laser traveling in a straight line is the maximal laser cutting speed, v_max, while for a circular arc of nonzero radius, R, it is given by v_max * exp(-1/R).

Task

(1) Write code to deserialize extrusion profiles so that it can be represented in memory.

(2) Write a program that takes a profile and produces a quote. Assume:

- Padding: 0.1in

- Material Cost: $0.75/in^2

- Maximal laser cutter speed: 0.5 in/s

- Machine Time Cost: $0.07/s

(3) Keep all of your progress in a git repository and when you are done, push your repository and send an email letting me know you're done.

(4) Include a brief description of how to use your code and what you would do to improve it if you had more time. Please, make sure to reference any external code used.

Examples

Three example JSON files are provided for you to test your code:

(1) Rectangle.json - a simple 3in x 5in rectangle.

Your program should output: 14.10 dollars

(2) ExtrudeCircularArc.json - a 2in x 1in rectangle with semicircle added onto one of the 1in sides.

Your program should output: 4.47 dollars

(3) CutCircularArc.json - a 2in x 1in rectangle with semicircle cut into one of the 1in sides.

Your program should output: 4.06 dollars

{
"Edges": {
"53330552": {
"Type": "LineSegment",
"Vertices": [
10212927,
43495525
]
},
"24807479": {
"Type": "CircularArc",
"Vertices": [
43495525,
55915408
],
"Center": {
"X": 2.0,
"Y": 0.5
},
"ClockwiseFrom": 43495525
},
"21940722": {
"Type": "LineSegment",
"Vertices": [
55915408,
63248778
]
},
"32368095": {
"Type": "LineSegment",
"Vertices": [
63248778,
10212927
]
}
},
"Vertices": {
"10212927": {
"Position": {
"X": 0.0,
"Y": 0.0
}
},
"43495525": {
"Position": {
"X": 2.0,
"Y": 0.0
}
},
"55915408": {
"Position": {
"X": 2.0,
"Y": 1.0
}
},
"63248778": {
"Position": {
"X": 0.0,
"Y": 1.0
}
}
}
}
{
"Edges": {
"5903470": {
"Type": "LineSegment",
"Vertices": [
53131231,
46104728
]
},
"8419032": {
"Type": "CircularArc",
"Vertices": [
46104728,
12289376
],
"Center": {
"X": 2.0,
"Y": 0.5
},
"ClockwiseFrom": 12289376
},
"8662426": {
"Type": "LineSegment",
"Vertices": [
12289376,
10852974
]
},
"30567910": {
"Type": "LineSegment",
"Vertices": [
10852974,
53131231
]
}
},
"Vertices": {
"53131231": {
"Position": {
"X": 0.0,
"Y": 0.0
}
},
"46104728": {
"Position": {
"X": 2.0,
"Y": 0.0
}
},
"12289376": {
"Position": {
"X": 2.0,
"Y": 1.0
}
},
"10852974": {
"Position": {
"X": 0.0,
"Y": 1.0
}
}
}
}
{
"Edges": {
"33476626": {
"Type": "LineSegment",
"Vertices": [
32854180,
27252167
]
},
"43942917": {
"Type": "LineSegment",
"Vertices": [
27252167,
59941933
]
},
"2606490": {
"Type": "LineSegment",
"Vertices": [
59941933,
23458411
]
},
"9799115": {
"Type": "LineSegment",
"Vertices": [
23458411,
32854180
]
}
},
"Vertices": {
"32854180": {
"Position": {
"X": 0.0,
"Y": 0.0
}
},
"27252167": {
"Position": {
"X": 0.0,
"Y": 3.0
}
},
"59941933": {
"Position": {
"X": 5.0,
"Y": 3.0
}
},
"23458411": {
"Position": {
"X": 5.0,
"Y": 0.0
}
}
}
}
{
"Edges": [
id: {
"Type": "LineSegment",
"Vertices": [id],
},
id: {
"Type": "CircularArc",
"Center": {
"X": double,
"Y": double,
},
"ClockwiseFrom": id,
"Vertices": [id],
}
],
"Vertices": [
id: {
"Position": {
"X": double,
"Y": double,
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment