diff --git a/Graphics/Implicit/Definitions.hs b/Graphics/Implicit/Definitions.hs index e5d23f16..268f2269 100644 --- a/Graphics/Implicit/Definitions.hs +++ b/Graphics/Implicit/Definitions.hs @@ -102,6 +102,7 @@ data SymbolicObj2 = | IntersectR2 ℝ [SymbolicObj2] -- Simple transforms | Translate2 ℝ2 SymbolicObj2 + | Mirror2 ℝ2 SymbolicObj2 | Scale2 ℝ2 SymbolicObj2 | Rotate2 ℝ SymbolicObj2 -- Boundary mods @@ -125,6 +126,7 @@ data SymbolicObj3 = | DifferenceR3 ℝ [SymbolicObj3] -- Simple transforms | Translate3 ℝ3 SymbolicObj3 + | Mirror3 ℝ3 SymbolicObj3 | Scale3 ℝ3 SymbolicObj3 | Rotate3 (ℝ,ℝ,ℝ) SymbolicObj3 -- Boundary mods diff --git a/Graphics/Implicit/ObjectUtil/GetBox2.hs b/Graphics/Implicit/ObjectUtil/GetBox2.hs index bde1b390..1402cba0 100644 --- a/Graphics/Implicit/ObjectUtil/GetBox2.hs +++ b/Graphics/Implicit/ObjectUtil/GetBox2.hs @@ -68,6 +68,15 @@ getBox2 (Translate2 v symbObj) = then ((0,0),(0,0)) else (a^+^v, b^+^v) +getBox2 (Mirror2 a symbObj) = + let + (a,b) = getBox2 symbObj + mirror p = + let c = 2 * (p ⋅ a) / (a ⋅ a) + in c *^ a ^-^ p + in + (mirror a, mirror b) + getBox2 (Scale2 s symbObj) = let (a,b) = getBox2 symbObj diff --git a/Graphics/Implicit/ObjectUtil/GetBox3.hs b/Graphics/Implicit/ObjectUtil/GetBox3.hs index 811ad65f..cdb51c26 100644 --- a/Graphics/Implicit/ObjectUtil/GetBox3.hs +++ b/Graphics/Implicit/ObjectUtil/GetBox3.hs @@ -79,6 +79,15 @@ getBox3 (Translate3 v symbObj) = in (a^+^v, b^+^v) +getBox3 (Mirror3 a symbObj) = + let + (a,b) = getBox3 symbObj + mirror p = + let c = 2 * (p ⋅ a) / (a ⋅ a) + in p ^-^ c *^ a + in + (mirror a, mirror b) + getBox3 (Scale3 s symbObj) = let (a,b) = getBox3 symbObj diff --git a/Graphics/Implicit/ObjectUtil/GetImplicit2.hs b/Graphics/Implicit/ObjectUtil/GetImplicit2.hs index e803130f..e5800375 100644 --- a/Graphics/Implicit/ObjectUtil/GetImplicit2.hs +++ b/Graphics/Implicit/ObjectUtil/GetImplicit2.hs @@ -75,6 +75,15 @@ getImplicit2 (Translate2 v symbObj) = in \p -> obj (p ^-^ v) +getImplicit2 (Mirror2 a symbObj) = + let + obj = getImplicit2 symbObj + in + \p -> + let + c = 2 * (p ⋅ a) / (a ⋅ a) + in obj $ c *^ a ^-^ p + getImplicit2 (Scale2 s@(sx,sy) symbObj) = let obj = getImplicit2 symbObj diff --git a/Graphics/Implicit/ObjectUtil/GetImplicit3.hs b/Graphics/Implicit/ObjectUtil/GetImplicit3.hs index 0314f47b..02a51ab5 100644 --- a/Graphics/Implicit/ObjectUtil/GetImplicit3.hs +++ b/Graphics/Implicit/ObjectUtil/GetImplicit3.hs @@ -77,6 +77,15 @@ getImplicit3 (Scale3 s@(sx,sy,sz) symbObj) = in \p -> k * obj (p ⋯/ s) +getImplicit3 (Mirror3 a symbObj) = + let + obj = getImplicit3 symbObj + in + \p -> + let + c = 2 * (p ⋅ a) / (a ⋅ a) + in obj $ p ^-^ c *^ a + getImplicit3 (Rotate3 (yz, xz, xy) symbObj) = let obj = getImplicit3 symbObj diff --git a/Graphics/Implicit/Primitives.hs b/Graphics/Implicit/Primitives.hs index 8510c273..3fa206f9 100644 --- a/Graphics/Implicit/Primitives.hs +++ b/Graphics/Implicit/Primitives.hs @@ -71,6 +71,12 @@ class Object obj vec | obj -> vec where -> obj -- ^ Object to translate -> obj -- ^ Resulting object + -- | Mirror an object + mirror :: + vec -- ^ Vector defining plane to mirror across + -> obj -- ^ Object to mirror + -> obj -- ^ Resulting mirrored object + -- | Scale an object scale :: vec -- ^ Amount to scale by @@ -130,6 +136,7 @@ class Object obj vec | obj -> vec where instance Object SymbolicObj2 ℝ2 where translate = Translate2 + mirror = Mirror2 scale = Scale2 complement = Complement2 unionR = UnionR2 @@ -143,6 +150,7 @@ instance Object SymbolicObj2 ℝ2 where instance Object SymbolicObj3 ℝ3 where translate = Translate3 + mirror = Mirror3 scale = Scale3 complement = Complement3 unionR = UnionR3