2010-08-25 10:00:19 -05:00
|
|
|
/**
|
|
|
|
* Simple triangles library
|
|
|
|
*
|
|
|
|
* Authors:
|
2010-08-25 11:35:45 -05:00
|
|
|
* - Eero 'rambo' af Heurlin 2010-
|
2010-08-25 10:00:19 -05:00
|
|
|
*
|
2010-08-25 11:35:45 -05:00
|
|
|
* License: LGPL 2.1
|
2010-08-25 10:00:19 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-08-26 02:08:44 -05:00
|
|
|
/**
|
|
|
|
* Standard right-angled triangle
|
|
|
|
*
|
2018-07-09 20:23:10 -05:00
|
|
|
* @param number o_len Length of the opposite side
|
|
|
|
* @param number a_len Length of the adjacent side
|
|
|
|
* @param number depth How wide/deep the triangle is in the 3rd dimension
|
|
|
|
* @param boolean center Whether to center the triangle on the origin
|
2010-08-26 02:08:44 -05:00
|
|
|
* @todo a better way ?
|
|
|
|
*/
|
2018-07-09 20:23:10 -05:00
|
|
|
module triangle(o_len, a_len, depth, center=false)
|
2010-08-26 02:08:44 -05:00
|
|
|
{
|
2018-07-09 20:23:10 -05:00
|
|
|
centroid = center ? [-a_len/3, -o_len/3, -depth/2] : [0, 0, 0];
|
|
|
|
translate(centroid) linear_extrude(height=depth)
|
2010-08-26 02:08:44 -05:00
|
|
|
{
|
|
|
|
polygon(points=[[0,0],[a_len,0],[0,o_len]], paths=[[0,1,2]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 10:01:17 -05:00
|
|
|
/**
|
|
|
|
* Standard right-angled triangle (tangent version)
|
|
|
|
*
|
2018-07-09 20:23:10 -05:00
|
|
|
* @param number tan_angle Angle of adjacent to hypotenuse (ie tangent)
|
|
|
|
* @param number a_len Length of the adjacent side
|
|
|
|
* @param number depth How wide/deep the triangle is in the 3rd dimension
|
|
|
|
* @param boolean center Whether to center the triangle on the origin
|
2010-08-27 10:01:17 -05:00
|
|
|
*/
|
2018-07-09 20:23:10 -05:00
|
|
|
module a_triangle(tan_angle, a_len, depth, center=false)
|
2010-08-27 10:01:17 -05:00
|
|
|
{
|
2018-07-09 20:23:10 -05:00
|
|
|
triangle(tan(tan_angle) * a_len, a_len, depth, center);
|
2010-08-27 10:01:17 -05:00
|
|
|
}
|
2010-08-26 06:35:51 -05:00
|
|
|
|
|
|
|
// Tests:
|
2010-08-27 10:07:20 -05:00
|
|
|
module test_triangle() { triangle(5, 5, 5); }
|
|
|
|
module test_a_triangle() { a_triangle(45, 5, 5); }
|
|
|
|
module test_triangles()
|
2010-08-27 10:01:17 -05:00
|
|
|
{
|
|
|
|
// Generate a bunch of triangles by sizes
|
|
|
|
for (i = [1:10])
|
|
|
|
{
|
|
|
|
translate([i*7, -30, i*7])
|
|
|
|
{
|
|
|
|
triangle(i*5, sqrt(i*5+pow(i,2)), 5);
|
|
|
|
}
|
|
|
|
}
|
2010-08-26 02:08:44 -05:00
|
|
|
|
2010-08-27 10:01:17 -05:00
|
|
|
// Generate a bunch of triangles by angle
|
|
|
|
for (i = [1:85/5])
|
|
|
|
{
|
2011-09-07 20:49:39 -05:00
|
|
|
translate([i*7, 22, i*7])
|
2010-08-27 10:01:17 -05:00
|
|
|
{
|
|
|
|
a_triangle(i*5, 10, 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|