Created
December 7, 2011 23:56
-
-
Save timjb/1445368 to your computer and use it in GitHub Desktop.
AI class: Simple Motion Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- https://www.ai-class.com/course/video/quizquestion/285 | |
| data State = S { x :: Double | |
| , y :: Double | |
| , theta :: Double | |
| , v :: Double | |
| , omega :: Double | |
| , dt :: Double | |
| } deriving (Show) | |
| iter :: Int -> (a -> a) -> a -> a | |
| iter 0 _ a = a | |
| iter n f a = iter (n-1) f (f a) | |
| step :: State -> State | |
| step a = S { x = x a + dt a * v a * (cos $ theta a) | |
| , y = y a + dt a * v a * (sin $ theta a) | |
| , theta = theta a + omega a * dt a | |
| , v = v a | |
| , omega = omega a | |
| , dt = dt a | |
| } | |
| main :: IO () | |
| main = print $ iter numSteps step startState | |
| where startState = S { x = 0 | |
| , y = 0 | |
| , theta = 0 | |
| , v = 10 | |
| , omega = pi / 8 | |
| , dt = 4 | |
| } | |
| numSteps = 4 | |
| -- Note to myself: I should think before I compute a solution. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment