From c986401ee8b6c1ebe8393f2af50cc630f28c1a8c Mon Sep 17 00:00:00 2001 From: Scott Winkler Date: Wed, 4 Apr 2018 23:30:38 -0700 Subject: [PATCH] add reflect method for matrix --- geometry.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/geometry.go b/geometry.go index 0cb1436..70b0d67 100644 --- a/geometry.go +++ b/geometry.go @@ -3,6 +3,8 @@ package pixel import ( "fmt" "math" + + "github.com/scottwinkler/pixel" ) // Clamp returns x clamped to the interval [min, max]. @@ -371,6 +373,15 @@ func (m Matrix) Rotated(around Vec, angle float64) Matrix { return m } +//Reflect reflects everything around a given point by the given angle in radians +func (m Matrix) Reflect(around pixel.Vec, angle float64) pixel.Matrix { + sin2t, cos2t := math.Sincos(2 * angle) + m[4], m[5] = m[4]-around.X, m[5]-around.Y + m = m.Chained(pixel.Matrix{cos2t, sin2t, sin2t, -cos2t, 0, 0}) + m[4], m[5] = m[4]+around.X, m[5]+around.Y + return m +} + // Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied // after the transformations of this Matrix. func (m Matrix) Chained(next Matrix) Matrix {