omdl  v0.9.5
OpenSCAD Mechanical Design Library
triangle.scad
Go to the documentation of this file.
1 //! Triangle shapes, conversions, properties, and tests functions.
2 /***************************************************************************//**
3  \file
4  \author Roy Allen Sutton
5  \date 2015-2019
6 
7  \copyright
8 
9  This file is part of [omdl] (https://github.com/royasutton/omdl),
10  an OpenSCAD mechanical design library.
11 
12  The \em omdl is free software; you can redistribute it and/or modify
13  it under the terms of the [GNU Lesser General Public License]
14  (http://www.gnu.org/licenses/lgpl.html) as published by the Free
15  Software Foundation; either version 2.1 of the License, or (at
16  your option) any later version.
17 
18  The \em omdl is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with the \em omdl; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301, USA; or see <http://www.gnu.org/licenses/>.
27 
28  \details
29 
30  \amu_define group_name (Triangles)
31  \amu_define group_brief (Triangle mathematical functions.)
32 
33  \amu_include (include/amu/pgid_path_pstem_pg.amu)
34 *******************************************************************************/
35 
36 //----------------------------------------------------------------------------//
37 // group and macros.
38 //----------------------------------------------------------------------------//
39 
40 /***************************************************************************//**
41  \amu_include (include/amu/group_in_parent_start.amu)
42  \amu_include (include/amu/includes_required.amu)
43 
44  \amu_define html_image_w (512)
45  \amu_define latex_image_w (2.25in)
46  \amu_include (include/amu/scope_diagram_2d_object.amu)
47 
48  \details
49 
50  See [Wikipedia](https://en.wikipedia.org/wiki/Triangle)
51  for more information.
52 *******************************************************************************/
53 
54 //----------------------------------------------------------------------------//
55 // shape generation
56 //----------------------------------------------------------------------------//
57 
58 //! \name Shapes
59 //! @{
60 
61 //! Compute the side lengths of a triangle given its vertex coordinates.
62 /***************************************************************************//**
63  \param c <coords-3d | coords-2d> A list, [v1, v2, v3], the 3d or 2d
64  vertex coordinates.
65 
66  \returns <decimal-list-3> A list of side lengths [s1, s2, s3].
67 
68  \details
69 
70  Each side length is opposite the corresponding vertex.
71 
72  \amu_eval ( object=triangle_ppp2sss ${object_diagram_2d} )
73 
74  No verification is performed to ensure that the given sides specify
75  a valid triangle. See [Wikipedia] for more information.
76 
77  [Wikipedia]: https://en.wikipedia.org/wiki/Solution_of_triangles
78 *******************************************************************************/
79 function triangle_ppp2sss
80 (
81  c
82 ) =
83  let
84  (
85  v1 = c[0],
86  v2 = c[1],
87  v3 = c[2],
88 
89  s1 = distance_pp(v2, v3),
90  s2 = distance_pp(v3, v1),
91  s3 = distance_pp(v1, v2)
92  )
93  [s1, s2, s3];
94 
95 //! Compute the side lengths of a triangle given two sides and the included angle.
96 /***************************************************************************//**
97  \param v <decimal-list-3> A list, [s1, a3, s2], the side lengths
98  and the included angle.
99 
100  \returns <decimal-list-3> A list of side lengths [s1, s2, s3].
101 
102  \details
103 
104  Each side length is opposite the corresponding vertex.
105 
106  \amu_eval ( object=triangle_sas2sss ${object_diagram_2d} )
107 
108  No verification is performed to ensure that the given sides specify
109  a valid triangle. See [Wikipedia] for more information.
110 
111  [Wikipedia]: https://en.wikipedia.org/wiki/Solution_of_triangles
112 *******************************************************************************/
113 function triangle_sas2sss
114 (
115  v
116 ) =
117  let
118  (
119  s1 = v[0],
120  a3 = v[1],
121  s2 = v[2],
122 
123  s3 = sqrt( s1*s1 + s2*s2 - 2*s1*s2*cos(a3) )
124  )
125  [s1, s2, s3];
126 
127 //! Compute the side lengths of a triangle given a side and two adjacent angles.
128 /***************************************************************************//**
129  \param v <decimal-list-3> A list, [a1, s3, a2], the side length
130  and two adjacent angles.
131 
132  \returns <decimal-list-3> A list of side lengths [s1, s2, s3].
133 
134  \details
135 
136  Each side length is opposite the corresponding vertex.
137 
138  \amu_eval ( object=triangle_asa2sss ${object_diagram_2d} )
139 
140  No verification is performed to ensure that the given sides specify
141  a valid triangle. See [Wikipedia] for more information.
142 
143  [Wikipedia]: https://en.wikipedia.org/wiki/Solution_of_triangles
144 *******************************************************************************/
145 function triangle_asa2sss
146 (
147  v
148 ) =
149  let
150  (
151  a1 = v[0],
152  s3 = v[1],
153  a2 = v[2],
154 
155  a3 = 180 - a1 - a2,
156 
157  s1 = s3 * sin( a1 ) / sin( a3 ),
158  s2 = s3 * sin( a2 ) / sin( a3 )
159  )
160  [s1, s2, s3];
161 
162 //! Compute the side lengths of a triangle given a side, one adjacent and the opposite angle.
163 /***************************************************************************//**
164  \param v <decimal-list-3> A list, [a1, a2, s1], a side length,
165  one adjacent and the opposite angle.
166 
167  \returns <decimal-list-3> A list of side lengths [s1, s2, s3].
168 
169  \details
170 
171  Each side length is opposite the corresponding vertex.
172 
173  \amu_eval ( object=triangle_aas2sss ${object_diagram_2d} )
174 
175  No verification is performed to ensure that the given sides specify
176  a valid triangle. See [Wikipedia] for more information.
177 
178  [Wikipedia]: https://en.wikipedia.org/wiki/Solution_of_triangles
179 *******************************************************************************/
180 function triangle_aas2sss
181 (
182  v
183 ) =
184  let
185  (
186  a1 = v[0],
187  a2 = v[1],
188  s1 = v[2],
189 
190  a3 = 180 - a1 - a2,
191 
192  s2 = s1 * sin( a2 ) / sin( a1 ),
193  s3 = s1 * sin( a3 ) / sin( a1 )
194  )
195  [s1, s2, s3];
196 
197 //! Compute a set of vertex coordinates for a triangle given its side lengths in 2D.
198 /***************************************************************************//**
199  \param v <decimal-list-3> A list, [s1, s2, s3], the side lengths.
200  \param a <integer> The axis alignment index
201  < \b x_axis_ci | \b y_axis_ci >.
202  \param cw <boolean> Order vertices clockwise.
203 
204  \returns <coords-2d> A list of vertex coordinates [v1, v2, v3],
205  when \p cw = \b true, else [v1, v3, v2].
206 
207  \details
208 
209  Each side length is opposite the corresponding vertex. The triangle
210  will be constructed with \em v1 at the origin. Side \em s2 will be
211  on the 'x' axis or side \em s3 will be on the 'y' axis as
212  determined by parameter \p a.
213 
214  \amu_eval ( object=triangle2d_sss2ppp ${object_diagram_2d} )
215 
216  No verification is performed to ensure that the given sides specify
217  a valid triangle. See [Wikipedia] for more information.
218 
219  [Wikipedia]: https://en.wikipedia.org/wiki/Solution_of_triangles
220 *******************************************************************************/
221 function triangle2d_sss2ppp
222 (
223  v,
224  a = x_axis_ci,
225  cw = true
226 ) =
227  let
228  (
229  s1 = v[0],
230  s2 = v[1],
231  s3 = v[2],
232 
233  v1 = origin2d,
234 
235  v2 = (a == x_axis_ci) ?
236  // law of cosines
237  let(x = (-s1*s1 + s2*s2 + s3*s3) / (2*s2))
238  [x, sqrt(s3*s3 - x*x)]
239  : [0, s3],
240 
241  v3 = (a == x_axis_ci) ?
242  [s2, 0]
243  // law of cosines
244  : let(y = (-s1*s1 + s2*s2 + s3*s3) / (2*s3))
245  [sqrt(s2*s2 - y*y), y]
246  )
247  (cw == true) ? [v1, v2, v3] : [v1, v3, v2];
248 
249 //! @}
250 
251 //----------------------------------------------------------------------------//
252 // shape properties
253 //----------------------------------------------------------------------------//
254 
255 //! \name Properties
256 //! @{
257 
258 //! Compute the area of a triangle given its vertex coordinates in 2D.
259 /***************************************************************************//**
260  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
261  \param s <boolean> Return the vertex ordering sign.
262 
263  \returns <decimal> The area of the given triangle.
264 *******************************************************************************/
265 function triangle2d_area
266 (
267  c,
268  s = false
269 ) =
270  let
271  (
272  sa = is_left_ppp(p1=c[0], p2=c[1], p3=c[2]) / 2
273  )
274  (s == false) ? abs(sa) : sa;
275 
276 //! Compute the centroid of a triangle.
277 /***************************************************************************//**
278  \param c <coords-3d | coords-2d> A list of 3d or 2d vertex
279  coordinates [v1, v2, v3].
280  \param d <integer> The number of dimensions [2:3].
281 
282  \returns <point-3d | point-2d> The centroid coordinate.
283 
284  \details
285 
286  When \p d is assigned \b 0, \p d is set to the minimun number of
287  coordinates of the vertices in \p c.
288 
289  See [Wikipedia] for more information.
290 
291  [Wikipedia]: https://en.wikipedia.org/wiki/Centroid
292 *******************************************************************************/
293 function triangle_centroid
294 (
295  c,
296  d = 2
297 ) =
298  let
299  (
300  v1 = c[0],
301  v2 = c[1],
302  v3 = c[2],
303 
304  e = (d == 0) ? min(len(v1), len(v2), len(v3)) : d
305  )
306  [ for (i=[0:e-1]) (v1[i] + v2[i] + v3[i])/3 ];
307 
308 //! Compute the center coordinate of a triangle's incircle in 2D.
309 /***************************************************************************//**
310  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
311 
312  \returns <point-2d> The incircle center coordinate [x, y].
313 
314  \details
315 
316  The interior point for which distances to the sides of the triangle
317  are equal. See [Wikipedia] for more information.
318 
319  [Wikipedia]: https://en.wikipedia.org/wiki/Incircle_and_excircles_of_a_triangle
320 *******************************************************************************/
321 function triangle2d_incenter
322 (
323  c
324 ) =
325  let
326  (
327  v1 = c[0],
328  v2 = c[1],
329  v3 = c[2],
330 
331  d1 = distance_pp(v2, v3),
332  d2 = distance_pp(v3, v1),
333  d3 = distance_pp(v1, v2)
334  )
335  [
336  ( (v1[0] * d1 + v2[0] * d2 + v3[0] * d3) / (d3 + d1 + d2) ),
337  ( (v1[1] * d1 + v2[1] * d2 + v3[1] * d3) / (d3 + d1 + d2) )
338  ];
339 
340 //! Compute the inradius of a triangle's incircle in 2D.
341 /***************************************************************************//**
342  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
343 
344  \returns <decimal> The incircle radius.
345 
346  \details
347 
348  See [Wikipedia] for more information.
349 
350  [Wikipedia]: https://en.wikipedia.org/wiki/Incircle_and_excircles_of_a_triangle
351 *******************************************************************************/
352 function triangle2d_inradius
353 (
354  c
355 ) =
356  let
357  (
358  v1 = c[0],
359  v2 = c[1],
360  v3 = c[2],
361 
362  d1 = distance_pp(v2, v3),
363  d2 = distance_pp(v3, v1),
364  d3 = distance_pp(v1, v2)
365  )
366  sqrt( ((-d3+d1+d2) * (+d3-d1+d2) * (+d3+d1-d2)) / (d3+d1+d2) ) / 2;
367 
368 //! Compute the center coordinate of a triangle's excircle in 2D.
369 /***************************************************************************//**
370  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
371  \param v <integer> Return coordinate opposite vertex \p v.
372 
373  \returns <point-2d> The excircle center coordinate [x, y].
374 
375  \details
376 
377  A circle outside of the triangle specified by \p v1, \p v2, and \p
378  v3, tangent to the side opposite \p v and tangent to the
379  extensions of the other two sides away from \p v. See [Wikipedia]
380  for more information.
381 
382  [Wikipedia]: https://en.wikipedia.org/wiki/Incircle_and_excircles_of_a_triangle
383 *******************************************************************************/
384 function triangle2d_excenter
385 (
386  c,
387  v = 1
388 ) =
389  let
390  (
391  v1 = c[0],
392  v2 = c[1],
393  v3 = c[2],
394 
395  d1 = distance_pp(v2, v3),
396  d2 = distance_pp(v3, v1),
397  d3 = distance_pp(v1, v2)
398  )
399  (v == 1) ? [ ((-d1*v1[0]+d2*v2[0]+d3*v3[0])/(-d1+d2+d3)),
400  ((-d1*v1[1]+d2*v2[1]+d3*v3[1])/(-d1+d2+d3)) ]
401  : (v == 2) ? [ ((+d1*v1[0]-d2*v2[0]+d3*v3[0])/(+d1-d2+d3)),
402  ((+d1*v1[1]-d2*v2[1]+d3*v3[1])/(+d1-d2+d3)) ]
403  : (v == 3) ? [ ((+d1*v1[0]+d2*v2[0]-d3*v3[0])/(+d1+d2-d3)),
404  ((+d1*v1[1]+d2*v2[1]-d3*v3[1])/(+d1+d2-d3)) ]
405  : origin2d;
406 
407 //! Compute the exradius of a triangle's excircle in 2D.
408 /***************************************************************************//**
409  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
410  \param v <integer> Return coordinate opposite vertex \p v.
411 
412  \returns <decimal> The excircle radius of the excircle opposite \p v.
413 
414  \details
415 
416  See [Wikipedia] for more information.
417 
418  [Wikipedia]: https://en.wikipedia.org/wiki/Incircle_and_excircles_of_a_triangle
419 *******************************************************************************/
420 function triangle2d_exradius
421 (
422  c,
423  v = 1
424 ) =
425  let
426  (
427  v1 = c[0],
428  v2 = c[1],
429  v3 = c[2],
430 
431  d1 = distance_pp(v2, v3),
432  d2 = distance_pp(v3, v1),
433  d3 = distance_pp(v1, v2),
434  s = (+d1+d2+d3)/2
435  )
436  (v == 1) ? sqrt(s * (s-d2) * (s-d3) / (s-d1))
437  : (v == 2) ? sqrt(s * (s-d1) * (s-d3) / (s-d2))
438  : (v == 3) ? sqrt(s * (s-d1) * (s-d2) / (s-d3))
439  : 0;
440 
441 //! Compute the coordinate of a triangle's circumcenter.
442 /***************************************************************************//**
443  \param c <coords-3d | coords-2d> A list of 3d or 2d vertex
444  coordinates [v1, v2, v3].
445  \param d <integer> The number of dimensions [2:3].
446 
447  \returns <point-3d | point-2d> The circumcenter coordinate.
448 
449  \details
450 
451  A circle that passes through all of the vertices of the triangle.
452  The radius is the distance from the circumcenter to any of vertex.
453  When \p d is assigned \b 0, \p d is set to the minimun number of
454  coordinates of the vertices in \p c. See [Wikipedia] for more
455  information.
456 
457  [Wikipedia]: https://en.wikipedia.org/wiki/Circumscribed_circle
458 *******************************************************************************/
459 function triangle_circumcenter
460 (
461  c,
462  d = 2
463 ) =
464  let
465  (
466  v1 = c[0],
467  v2 = c[1],
468  v3 = c[2],
469 
470  s2a = sin( 2 * angle_ll([v1, v3], [v1, v2]) ),
471  s2b = sin( 2 * angle_ll([v2, v1], [v2, v3]) ),
472  s2c = sin( 2 * angle_ll([v3, v2], [v3, v1]) ),
473 
474  e = (d == 0) ? min(len(v1), len(v2), len(v3)) : d
475  )
476  [ for (i=[0:e-1]) (v1[i]*s2a + v2[i]*s2b + v3[i]*s2c) / (s2a+s2b+s2c) ];
477 
478 //! @}
479 
480 //----------------------------------------------------------------------------//
481 // shape property tests
482 //----------------------------------------------------------------------------//
483 
484 //! \name Tests
485 //! @{
486 
487 //! Test the vertex ordering, or orientation, of a triangle in 2D.
488 /***************************************************************************//**
489  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
490 
491  \returns <boolean> \b true if the vertices are ordered clockwise,
492  \b false if the vertices are ordered counterclockwise, and
493  \b undef if the ordering can not be determined.
494 *******************************************************************************/
495 function triangle2d_is_cw
496 (
497  c
498 ) =
499  let
500  (
501  il = is_left_ppp(p1=c[0], p2=c[1], p3=c[2])
502  )
503  (il < 0) ? true
504  : (il > 0) ? false
505  : undef;
506 
507 //! Test if a point is inside a triangle in 2d.
508 /***************************************************************************//**
509  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
510  \param p <point-2d> A test point coordinate [x, y].
511 
512  \returns <boolean> \b true when the point is inside the polygon and
513  \b false otherwise.
514 
515  \details
516 
517  See [Wikipedia] for more information.
518 
519  [Wikipedia]: https://en.wikipedia.org/wiki/Barycentric_coordinate_system
520 *******************************************************************************/
521 function triangle2d_is_pit
522 (
523  c,
524  p
525 ) =
526  let
527  (
528  v1 = c[0],
529  v2 = c[1],
530  v3 = c[2],
531 
532  d = ((v2[1]-v3[1]) * (v1[0]-v3[0]) + (v3[0]-v2[0]) * (v1[1]-v3[1]))
533  )
534  (d == 0) ? true
535  : let
536  (
537  a = ((v2[1]-v3[1]) * ( p[0]-v3[0]) + (v3[0]-v2[0]) * ( p[1]-v3[1])) / d
538  )
539  (a < 0) ? false
540  : let
541  (
542  b = ((v3[1]-v1[1]) * ( p[0]-v3[0]) + (v1[0]-v3[0]) * ( p[1]-v3[1])) / d
543  )
544  (b < 0) ? false
545  : ((a + b) < 1);
546 
547 //! @}
548 
549 //----------------------------------------------------------------------------//
550 // shape rounding
551 //----------------------------------------------------------------------------//
552 
553 //! \name Rounding
554 //! @{
555 
556 //! Compute the rounding center coordinate for a given radius of a triangle vertex in 2D.
557 /***************************************************************************//**
558  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
559  \param r <decimal> The vertex rounding radius.
560 
561  \returns <decimal> The rounding center coordinate.
562 *******************************************************************************/
564 (
565  c,
566  r
567 ) = let( ir = triangle2d_inradius(c) )
568  (c[1]-r/(r-ir) * triangle2d_incenter(c)) * (ir-r)/ir;
569 
570 //! Compute the rounding tangent coordinates for a given radius of a triangle vertex in 2D.
571 /***************************************************************************//**
572  \param c <coords-2d> A list of vertex coordinates [v1, v2, v3].
573  \param r <decimal> The vertex rounding radius.
574 
575  \returns <decimal> The rounding tangent coordinates [t1, t2].
576 *******************************************************************************/
578 (
579  c,
580  r
581 ) = let
582  (
583  rc = triangle2d_vround3_center(c, r),
584  im = sqrt( pow(distance_pp(c[1], rc),2) - pow(r,2) ),
585  t1 = c[1] + im * unit_l([c[1], c[0]]),
586  t2 = c[1] + im * unit_l([c[1], c[2]])
587  )
588  [t1, t2];
589 
590 //! @}
591 
592 //! @}
593 //! @}
594 
595 //----------------------------------------------------------------------------//
596 // openscad-amu auxiliary scripts
597 //----------------------------------------------------------------------------//
598 
599 /*
600 BEGIN_SCOPE diagram;
601  BEGIN_OPENSCAD;
602  include <omdl-base.scad>;
603  include <tools/operation_cs.scad>;
604  include <tools/drafting/draft-base.scad>;
605 
606  module dt (vl = empty_lst, al = empty_lst, sl = empty_lst)
607  {
608  s = 10;
609  t = [6, 8, 7];
610  r = min(t)/len(t)*s;
611 
612  c = triangle2d_sss2ppp(t)*s;
613 
614  draft_polygon(c, w=s*2/3);
615  draft_axes([[0,12], [0,7]]*s, ts=s/2);
616 
617  for (i = [0 : len(c)-1])
618  {
619  cv = c[i];
620  os = shift(shift(v=c, n=i, r=false), 1, r=false, c=false);
621 
622  if ( !is_empty( find( mv=i, v=vl )) )
623  draft_dim_leader(cv, v1=[mean(os), cv], l1=5, t=str("v", i+1), bs=0, cmh=s*1, cmv=s);
624 
625  if ( !is_empty( find( mv=i, v=al )) )
626  draft_dim_angle(c=cv, r=r, v1=[cv, second(os)], v2=[cv, first(os)], t=str("a", i+1), a=0, cmh=s, cmv=s);
627 
628  if ( !is_empty( find( mv=i, v=sl )) )
629  draft_dim_line(p1=first(os), p2=second(os), t=str("s", i+1), cmh=s, cmv=s);
630  }
631  }
632 
633  object = "triangle_sas2sss";
634 
635  if (object == "triangle_ppp2sss") dt( vl = [0,1,2]);
636  if (object == "triangle_sas2sss") dt( vl = [0,1,2], al = [2], sl = [0,1]);
637  if (object == "triangle_asa2sss") dt( vl = [0,1,2], al = [0,1], sl = [2]);
638  if (object == "triangle_aas2sss") dt( vl = [0,1,2], al = [0,1], sl = [0]);
639  if (object == "triangle2d_sss2ppp") dt( sl = [0,1,2]);
640  END_OPENSCAD;
641 
642  BEGIN_MFSCRIPT;
643  include --path "${INCLUDE_PATH}" {var_init,var_gen_svg}.mfs;
644 
645  defines name "objects" define "object"
646  strings "
647  triangle_ppp2sss
648  triangle_sas2sss
649  triangle_asa2sss
650  triangle_aas2sss
651  triangle2d_sss2ppp
652  ";
653  variables add_opts_combine "objects";
654  variables add_opts "--viewall --autocenter";
655 
656  include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
657  END_MFSCRIPT;
658 END_SCOPE;
659 */
660 
661 //----------------------------------------------------------------------------//
662 // end of file
663 //----------------------------------------------------------------------------//
x_axis_ci
<integer> The coordinate axis index for the Euclidean space x-axis.
Definition: constants.scad:395
origin2d
<point-2d> The origin point coordinate in 2d Euclidean space.
Definition: constants.scad:407
function angle_ll(l1, l2, s=true)
Compute the angle between two lines or vectors in a 3d or 2d-space.
function is_left_ppp(p1, p2, p3)
Test if a point is left, on, or right of an infinite line in a 2d-space.
function unit_l(l)
Compute the normalized unit vector of a line or vector.
function distance_pp(p1, p2)
Compute the distance between two points.
function triangle2d_vround3_tangents(c, r)
Compute the rounding tangent coordinates for a given radius of a triangle vertex in 2D.
function triangle_sas2sss(v)
Compute the side lengths of a triangle given two sides and the included angle.
function triangle_asa2sss(v)
Compute the side lengths of a triangle given a side and two adjacent angles.
function triangle2d_is_cw(c)
Test the vertex ordering, or orientation, of a triangle in 2D.
function triangle_centroid(c, d=2)
Compute the centroid of a triangle.
function triangle_aas2sss(v)
Compute the side lengths of a triangle given a side, one adjacent and the opposite angle.
function triangle_circumcenter(c, d=2)
Compute the coordinate of a triangle's circumcenter.
function triangle2d_inradius(c)
Compute the inradius of a triangle's incircle in 2D.
function triangle2d_excenter(c, v=1)
Compute the center coordinate of a triangle's excircle in 2D.
function triangle2d_is_pit(c, p)
Test if a point is inside a triangle in 2d.
function triangle2d_vround3_center(c, r)
Compute the rounding center coordinate for a given radius of a triangle vertex in 2D.
function triangle2d_area(c, s=false)
Compute the area of a triangle given its vertex coordinates in 2D.
function triangle2d_sss2ppp(v, a=x_axis_ci, cw=true)
Compute a set of vertex coordinates for a triangle given its side lengths in 2D.
function triangle_ppp2sss(c)
Compute the side lengths of a triangle given its vertex coordinates.
function triangle2d_exradius(c, v=1)
Compute the exradius of a triangle's excircle in 2D.
function triangle2d_incenter(c)
Compute the center coordinate of a triangle's incircle in 2D.