{-# LANGUAGE TypeFamilies #-}{-# OPTIONS_GHC -fno-warn-orphans #-}------------------------------------------------------------------------------- |-- Module : Diagrams.ThreeD.Types-- Copyright : (c) 2011 diagrams-lib team (see LICENSE)-- License : BSD-style (see LICENSE)-- Maintainer : diagrams-discuss@googlegroups.com---- Basic types for three-dimensional Euclidean space.-------------------------------------------------------------------------------module Diagrams.ThreeD.Types ( -- * 3D Euclidean space r3, unr3, mkR3 , p3, unp3, mkP3 , r3Iso, p3Iso, project , r3SphericalIso, r3CylindricalIso , V3 (..), P3, T3 , R1 (..), R2 (..), R3 (..) ) whereimport Control.Lens (Iso', iso, _1, _2, _3)import Diagrams.Angleimport Diagrams.Coreimport Diagrams.Pointsimport Diagrams.TwoD.Typesimport Linear.Metricimport Linear.V3 as V-------------------------------------------------------------- 3D Euclidean space-- Basic R3 typestype P3 = Point V3type T3 = Transformation V3r3Iso :: Iso' (V3 n) (n, n, n)r3Iso = iso unr3 r3-- | Construct a 3D vector from a triple of components.r3 :: (n, n, n) -> V3 nr3 (x,y,z) = V3 x y z-- | Curried version of `r3`.mkR3 :: n -> n -> n -> V3 nmkR3 = V3-- | Convert a 3D vector back into a triple of components.unr3 :: V3 n -> (n, n, n)unr3 (V3 x y z) = (x,y,z)-- | Construct a 3D point from a triple of coordinates.p3 :: (n, n, n) -> P3 np3 = P . r3-- | Convert a 3D point back into a triple of coordinates.unp3 :: P3 n -> (n, n, n)unp3 (P (V3 x y z)) = (x,y,z)p3Iso :: Iso' (P3 n) (n, n, n)p3Iso = iso unp3 p3-- | Curried version of `r3`.mkP3 :: n -> n -> n -> P3 nmkP3 x y z = p3 (x, y, z)type instance V (V3 n) = V3type instance N (V3 n) = ninstance Transformable (V3 n) where transform = applyr3SphericalIso :: RealFloat n => Iso' (V3 n) (n, Angle n, Angle n)r3SphericalIso = iso (\v@(V3 x y z) -> (norm v, atan2A y x, acosA (z / norm v))) (\(r,θ,φ) -> V3 (r * cosA θ * sinA φ) (r * sinA θ * sinA φ) (r * cosA φ))r3CylindricalIso :: RealFloat n => Iso' (V3 n) (n, Angle n, n)r3CylindricalIso = iso (\(V3 x y z) -> (sqrt $ x*x + y*y, atan2A y x, z)) (\(r,θ,z) -> V3 (r*cosA θ) (r*sinA θ) z)instance HasR V3 where _r = r3SphericalIso . _1instance HasTheta V3 where _theta = r3CylindricalIso . _2instance HasPhi V3 where _phi = r3SphericalIso . _3