generative-toolbelt.triangle
A set of functions to create, manage, and draw Triangles.
Triangles are sets with three Points like this: {:a {:x 100 :y 100} :b {:x 100 :y 100} :c {:x 100 :y 100}}.
add-point-to-triangles
(add-point-to-triangles triangles point)
Add a point to the triangulated mesh.
Takes a list of Triangles and a Point.
Returns a list of Triangles.
bounds
(bounds points)
Returns the bounding rectangle Point from a list of Points.
Returns a vector of 4 Points.
circumscribe-triangle
(circumscribe-triangle {:keys [a b c]})
Calculates a special Circle structure that circumscribe a Triangle.
NOTE: The Circlo structure that this function returns is different from generative-toolbelt.circle/make-circle since it has been optimize for the triangulation function.
Returns a special Circle structure.
contains-point?
(contains-point? {:keys [x y radius-squared]} point)
Checks if a Point is inside the special Circle structure or not.
Returns a boolean.
draw-triangle
(draw-triangle {:keys [a b c]} & [drawOptions])
Draws a Triangle into the current graphics canvas.
draw-triangles
(draw-triangles triangles & [drawOptions])
Draws a sequence of Triangles into the current graphics canvas.
Slightly faster than draw-triangle when a lot of triangles needs to be drawn with the same `drawOptions`.
edges
(edges {:keys [a b c]})
Scompose a Triangle into a vector of Lines.
get-triangle-guide
(get-triangle-guide tri)
Gets an alternative form of the Triangle structure that tells where the longest side is and what are its opposite sides.
is-from-bounds?
(is-from-bounds? boundSet {:keys [a b c]})
Checks if a Triangle is on a bounding box or not.
Returns a boolean.
make-new-triangles
(make-new-triangles containers point)
Creates new Triangles from a list of Triangles and a Point.
Returns a list of Triangles.
make-triangle
(make-triangle a b c)
Creates a Triangle with three Points.
Returns a Triangle.
mktr
(mktr ax ay bx by cx cy)
Creates a Triangle with canvas-relative coordinates.
Returns a Triangle.
move-triangle-by
(move-triangle-by tri vect)
Translate a Triangle by a certain distance Vector.
Returns a new Triangle.
outer-edges
(outer-edges triangles)
Gets the outer edges of a list of Triangles.
Returns a list of Lines.
split-recursive
(split-recursive t depth maxdepth oddsToSplit)
Recursivly splits a Triangle based on the current recursion depth and the odds to get split.
`t` is a Triangle.
`depth` is the current recursion step.
`maxdepth` is the target recursion level.
`oddsToSplit` is a 0-1 float indicating the odds to get split.
Returns a non-flattened list of Triangles.
split-triangle
(split-triangle tri)
Splits a Triangle by its longest side, creating two new Triangles.
Returns a list of two Triangles.
triangle-centroid
(triangle-centroid tri)
Calculate the centroid of a Triangle.
Returns a Point.
triangle-subdivision
(triangle-subdivision triangles maxdepth oddsToSplit)
Split a list of Triangles recursively.
`maxdepth` is the maximum depth level we want to reach with the recursion.
`oddsToSplit` is a 0-1 float indicating the odds to get split.
Returns a flattened list of Triangles.
triangulate
(triangulate points)