triangleArea computes the area of the triangle given by the three points
(p1, p2, p3 engo.Point)
| 466 | |
| 467 | // triangleArea computes the area of the triangle given by the three points |
| 468 | func triangleArea(p1, p2, p3 engo.Point) float32 { |
| 469 | // Law of cosines states: (note a2 = math.Pow(a, 2)) |
| 470 | // a2 = b2 + c2 - 2bc*cos(alpha) |
| 471 | // This ends in: alpha = arccos ((-a2 + b2 + c2)/(2bc)) |
| 472 | a := p1.PointDistance(p3) |
| 473 | b := p1.PointDistance(p2) |
| 474 | c := p2.PointDistance(p3) |
| 475 | alpha := math.Acos((-math.Pow(a, 2) + math.Pow(b, 2) + math.Pow(c, 2)) / (2 * b * c)) |
| 476 | |
| 477 | // Law of sines state: a / sin(alpha) = c / sin(gamma) |
| 478 | height := (c / math.Sin(math.Pi/2)) * math.Sin(alpha) |
| 479 | |
| 480 | return (b * height) / 2 |
| 481 | } |
| 482 | |
| 483 | // CollisionComponent keeps track of the entity's collisions. |
| 484 | // |
no test coverage detected