MCPcopy Index your code
hub / github.com/EngoEngine/engo / triangleArea

Function triangleArea

common/collision.go:468–481  ·  view source on GitHub ↗

triangleArea computes the area of the triangle given by the three points

(p1, p2, p3 engo.Point)

Source from the content-addressed store, hash-verified

466
467// triangleArea computes the area of the triangle given by the three points
468func 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//

Callers 1

ContainsMethod · 0.85

Calls 4

AcosFunction · 0.92
PowFunction · 0.92
SinFunction · 0.92
PointDistanceMethod · 0.45

Tested by

no test coverage detected