-
-
Notifications
You must be signed in to change notification settings - Fork 360
Verlet implementation in Common Lisp #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
berquist
merged 11 commits into
algorithm-archivists:master
from
Trashtalk217:verlet-lisp
Oct 8, 2019
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7b5c628
Added a proof for the Euclidean Algorithm
Trashtalk217 131ae54
Revert "Added a proof for the Euclidean Algorithm"
Trashtalk217 8cce3c9
First version of Verlet in Common Lisp.
Trashtalk217 54cc5d3
Added common lisp to verlet.md file.
Trashtalk217 763dffe
Fixed indentation and made stormer and velocity return a list instead…
Trashtalk217 7fc7f22
replaced temp variables and removed unnecessary looping variable
Trashtalk217 ac4b84d
Fixed weird indentation bug and the .md file
Trashtalk217 e7d32e8
the loop macro is incredible and safed a a couple of lines
Trashtalk217 ed4371c
removed unneccesary brackets and redid the indentation
Trashtalk217 0d26bcf
redid some words
Trashtalk217 bc9a58a
changed the doc strings
Trashtalk217 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;;;; Verlet integration implementation in Common Lisp | ||
|
||
(defun verlet (pos acc dt) | ||
"Finds the time it takes for an object to hit the ground using verlet integration." | ||
(loop | ||
with prev-pos = pos | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for time = 0 then (incf time dt) | ||
while (> pos 0) | ||
;; The starting speed is assumed to be zero. | ||
do (psetf | ||
pos (+ (* pos 2) (- prev-pos) (* acc dt dt)) | ||
prev-pos pos) | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
finally (return time))) | ||
|
||
(defun stormer-verlet (pos acc dt) | ||
"Finds the time and velocity when an object hits the ground using the stormer-verlet method." | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(loop | ||
with prev-pos = pos | ||
for time = 0 then (incf time dt) | ||
for vel = 0 then (incf vel (* acc dt)) | ||
while (> pos 0) | ||
;; Variables are changed in parallel by 'psetf', so there's no need for a temporary variable. | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
do (psetf | ||
pos (+ (* pos 2) (- prev-pos) (* acc dt dt)) | ||
prev-pos pos) | ||
finally (return (list time vel)))) | ||
|
||
(defun velocity-verlet (pos acc dt) | ||
"Finds the time and velocity when an object hist the ground using the velocity in calculations." | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(loop | ||
for time = 0 then (incf time dt) | ||
for vel = 0 then (incf vel (* acc dt)) | ||
for p = pos then (incf p (+ (* vel dt) (* 0.5 acc dt dt))) | ||
while (> p 0) | ||
finally (return (list time vel)))) | ||
|
||
(format T "Time for Verlet integration: ~d~%" (verlet 5 (- 10) 0.01)) | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
(defvar stormer-verlet-result (stormer-verlet 5 (- 10) 0.01)) | ||
(format T "Time for Stormer Verlet integration is: ~d~%" (first stormer-verlet-result)) | ||
(format T "Velocity for Stormer Verlet integration is: ~d~%" (second stormer-verlet-result)) | ||
|
||
(defvar velocity-verlet-result (velocity-verlet 5 (- 10) 0.01)) | ||
(format T "Time for velocity Verlet integration is: ~d~%" (first velocity-verlet-result)) | ||
(format T "Velocity for velocity Verlet integration is: ~d~%" (second velocity-verlet-result)) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.