License | MIT |
---|---|
Maintainer | Jonatan H Sundqvist |
Stability | experimental|stable |
Portability | POSIX (not sure) |
Safe Haskell | None |
Language | Haskell2010 |
Cartesian.Plane
Description
- data Vector num = Vector num num
- data Line num = Line (Vector num) (Vector num)
- type Polygon num = [Vector num]
- data Linear num = Linear {}
- inside :: Num n => Polygon n -> Vector n -> Bool
- dotwise :: (a -> b -> c) -> Vector a -> Vector b -> Vector c
- dot :: Floating a => Vector a -> Vector a -> a
- euclidean :: Floating a => Vector a -> Vector a -> a
- magnitude :: (Floating a, Eq a) => Vector a -> a
- mag :: (Floating a, Eq a) => Vector a -> a
- argument :: (Floating a, Eq a) => Vector a -> a
- arg :: (Floating a, Eq a) => Vector a -> a
- polar :: (Floating a, Eq a) => Vector a -> (a, a)
- intersect :: RealFrac n => Line n -> Line n -> Maybe (Vector n)
- intersects :: RealFrac r => Line r -> Line r -> Bool
- overlap :: Real a => (a, a) -> (a, a) -> Maybe (a, a)
- coefficients :: (Fractional a, Eq a) => Line a -> Maybe (a, a)
- solve :: (Fractional n, Eq n) => Linear n -> Linear n -> Maybe n
Documentation
TODO: Rename (?)
Constructors
Vector num num |
inside :: Num n => Polygon n -> Vector n -> Bool Source
type Domain
Determines if a point lies within a polygon using the odd-even method.
TODO: Use epsilon (?) TODO: How to treat points that lie on an edge
dotwise :: (a -> b -> c) -> Vector a -> Vector b -> Vector c Source
Performs component-wise operations
argument :: (Floating a, Eq a) => Vector a -> a Source
Angle (in radians) between the positive X-axis and the vector
intersect :: RealFrac n => Line n -> Line n -> Maybe (Vector n) Source
Yields the point at which two finite lines intersect. The lines are defined inclusively by their endpoints. The result is wrapped in a Maybe value to account for non-intersecting lines.
TODO: Move equation solving to separate function (two linear functions) TODO: Simplify logic by considering f(x) = y for vertical lines (?) TODO: Return Either instead of Maybe (eg. Left "parallel") (?)
TODO: Math notes, MathJax or LaTex TODO: Intersect for curves (functions) and single points (?) TODO: Polymorphic, typeclass (lines, shapes, ranges, etc.) (?)
intersects :: RealFrac r => Line r -> Line r -> Bool Source
inside :: (Num n, Ord n) => Triangle n -> Point n -> Bool inside _ _ = False
overlap :: Real a => (a, a) -> (a, a) -> Maybe (a, a) Source
Yields the overlap of two closed intervals (n ∈ R) TODO: Normalise intervals (eg. (12, 5) -> (5, 12))
coefficients :: (Fractional a, Eq a) => Line a -> Maybe (a, a) Source
TODO: Intersect Rectangles
Coefficients for the linear function of a Line (slope, intercept). Fails for vertical and horizontal lines.
TODO: Use Maybe (?) TODO: Rename (eg. toLinear, function) (?)