using Godot; using System.Collections; using System.Collections.Generic; namespace Rokojori { public enum TriangleSide { AB, BC, CA } public class TriangleSides { public static readonly TriangleSide[] ALL = { TriangleSide.AB, TriangleSide.BC, TriangleSide.CA }; } public class Triangle3 { public Vector3 a; public Vector3 b; public Vector3 c; public Triangle3( Vector3 a, Vector3 b, Vector3 c ) { this.a = a; this.b = b; this.c = c; } public float perimeter { get { var sideA = ( b - a ).Length(); var sideB = ( c - b ).Length(); var sideC = ( a - c ).Length(); return sideA + sideB + sideC; } } public float semiperimeter { get { return perimeter * 0.5f; } } public static float ComputeTriangleArea( Vector3 a, Vector3 b, Vector3 c ) { var sideA = ( b - a ).Length(); var sideB = ( c - b ).Length(); var sideC = ( a - c ).Length(); var perimeter = sideA + sideB + sideC; var semiperimeter = 0.5f * perimeter; var areaValue = Mathf.Sqrt( semiperimeter * ( semiperimeter - sideA ) * ( semiperimeter - sideB ) * ( semiperimeter - sideC )) ; return areaValue; } public float area { get { return ComputeTriangleArea( a, b, c ); } } public Line3 GetSide( TriangleSide side ) { switch ( side ) { case TriangleSide.AB: return new Line3( a, b ); case TriangleSide.BC: return new Line3( b, c ); case TriangleSide.CA: return new Line3( c, a ); } return null; } } }