From 62d6647243a0a655b7b29898bbdcb48f9b8c005e Mon Sep 17 00:00:00 2001 From: Daniel Bergey Date: Mon, 14 Oct 2013 13:59:34 +0000 Subject: [PATCH] Basic scaling on all 3D axes --- src/Diagrams/ThreeD/Transform.hs | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Diagrams/ThreeD/Transform.hs b/src/Diagrams/ThreeD/Transform.hs index 2f277674..288e7b08 100644 --- a/src/Diagrams/ThreeD/Transform.hs +++ b/src/Diagrams/ThreeD/Transform.hs @@ -25,6 +25,7 @@ import Diagrams.Coordinates import Diagrams.ThreeD.Types import Diagrams.ThreeD.Vector +import Control.Lens ((*~), (//~)) import Data.Semigroup import Data.AffineSpace @@ -94,6 +95,42 @@ rotatationAbout p d a w ^* ((w <.> v) * (1 - cos th)) t = p .-. origin + +-- Scaling ------------------------------------------------- + +-- | Construct a transformation which scales by the given factor in +-- the x direction. +scalingX :: Double -> T3 +scalingX c = fromLinear s s + where s = (_x *~ c) <-> (_x //~ c) + +-- | Scale a diagram by the given factor in the x (horizontal) +-- direction. To scale uniformly, use 'scale'. +scaleX :: (Transformable t, V t ~ R3) => Double -> t -> t +scaleX = transform . scalingX + +-- | Construct a transformation which scales by the given factor in +-- the y direction. +scalingY :: Double -> T3 +scalingY c = fromLinear s s + where s = (_y *~ c) <-> (_y //~ c) + +-- | Scale a diagram by the given factor in the y (vertical) +-- direction. To scale uniformly, use 'scale'. +scaleY :: (Transformable t, V t ~ R3) => Double -> t -> t +scaleY = transform . scalingY + +-- | Construct a transformation which scales by the given factor in +-- the z direction. +scalingZ :: Double -> T3 +scalingZ c = fromLinear s s + where s = (_z *~ c) <-> (_z //~ c) + +-- | Scale a diagram by the given factor in the z direction. To scale +-- uniformly, use 'scale'. +scaleZ :: (Transformable t, V t ~ R3) => Double -> t -> t +scaleZ = transform . scalingZ + -- | Get the matrix equivalent of an affine transform, as a triple of -- columns paired with the translation vector. This is mostly -- useful for implementing backends.