Work on chasm rooms
This commit is contained in:
@@ -15,9 +15,9 @@ import Linear.Metric
|
||||
import Control.Monad
|
||||
|
||||
-- | If two lines intersect, return 'Just' that point.
|
||||
intersectLineLine' :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectLineLine' #-}
|
||||
intersectLineLine' (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
intersectLineLine :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectLineLine #-}
|
||||
intersectLineLine (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
| den == 0 = Nothing
|
||||
| otherwise = Just $ V2 (x1 + (x2 - x1) * t' / den) (y1 + (y2 - y1) * t' / den)
|
||||
where
|
||||
@@ -28,7 +28,7 @@ intersectLineLine' (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
intersectLinePlane :: Point3 -> Point3 -> Point3 -> Point3 -> Maybe Point3
|
||||
intersectLinePlane l v p n = case dot v n of
|
||||
0 -> Nothing
|
||||
x -> Just $ l + ((dot (p - l) n) / x) *.*.* v
|
||||
x -> Just $ l + (dot (p - l) n / x) *.*.* v
|
||||
|
||||
-- this needs to be checked
|
||||
intersectSegPlane :: Point3 -> Point3 -> Point3 -> Point3 -> Maybe Point3
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
module Geometry.Polygon where
|
||||
|
||||
import Geometry.Intersect
|
||||
import qualified Control.Foldl as L
|
||||
import Data.Maybe
|
||||
import Geometry.Data
|
||||
@@ -46,6 +47,23 @@ rectVV (V2 x y) (V2 a b) = rectNSWE n s w e
|
||||
square :: Float -> [Point2]
|
||||
square n = rectWH n n
|
||||
|
||||
polyOrthDist :: Int -> Float -> [Point2]
|
||||
polyOrthDist n x = mapMaybe
|
||||
(\(ra, rb) -> intersectLineLine (rotateV ra bl) (rotateV ra br) (rotateV rb bl) (rotateV rb br))
|
||||
$ loopPairs rots
|
||||
where
|
||||
rot = 2 * pi / fromIntegral n
|
||||
rots = map ((rot *) . fromIntegral) [0 .. n -1]
|
||||
bl = V2 x x
|
||||
br = V2 (- x) x
|
||||
|
||||
polyCornerDist :: Int -> Float -> [Point2]
|
||||
polyCornerDist n x = map f rots
|
||||
where
|
||||
rot = 2 * pi / fromIntegral n
|
||||
rots = map ((rot *) . fromIntegral) [0 .. n -1]
|
||||
f a = rotateV a (V2 x 0)
|
||||
|
||||
mirrorXAxis :: [Point2] -> [Point2]
|
||||
mirrorXAxis ps = orderPolygon $ ps ++ mapMaybe f ps
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user