-
Notifications
You must be signed in to change notification settings - Fork 5
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
Tutorials #78
Open
tarzzz
wants to merge
2
commits into
master
Choose a base branch
from
Tutorials
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tutorials #78
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ Contents: | |
|
||
introduction.rst | ||
installation.rst | ||
tutorials.rst | ||
api.rst | ||
|
||
|
||
|
This file contains 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,13 @@ | ||
Tutorials | ||
========= | ||
|
||
There are two types of tutorials in this documentation. | ||
The first one is a basic example for animation. In the basic example, | ||
a simple mass-spring system is animated using SymPy mechanics and PyDyViz. | ||
|
||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
tutorials/basic.rst | ||
|
This file contains 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,80 @@ | ||
Basic Tutorial | ||
-------------- | ||
|
||
In this tutorial, we are going to analyze a mass spring damper problem, and animate it using the package. | ||
For this tutorial to work, you have following additional dependency: | ||
|
||
* Scipy_ | ||
|
||
We are going to break this tutorial into three parts, | ||
* Mechanics Part: where we define the system and derive Equations Of Motion. | ||
* Simulation Part: where we numerically solve Equations of Motion(using SciPy). | ||
* Visualization Part: where we actually generate the animations in a browser. | ||
|
||
|
||
|
||
Equation Of Motion Generation | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
We will be using SymPy Mechanics module for EoM generation. | ||
|
||
For more details on Mechanics Please refer to SymPy docs and tutorials. | ||
|
||
First we import necessary functionality from SymPy:: | ||
|
||
>>> from sympy.physics.mechanics import * | ||
>>> from sympy import symbols,cos,Eq,sqrt,sin | ||
|
||
Now, we will create some symbols for coordinates, speed, force etc of the mass(bob). | ||
|
||
>>> q = dynamicsymbols('q') # Generalized coordinate | ||
>>> u = dynamicsymbols('u') # Generalized speed | ||
>>> f = dynamicsymbols('f') # Net Force applied to the box | ||
>>> m = symbols('m') # Mass of body | ||
>>> g, k, t, L = symbols('g k t L') # Gravity,spring constant, time and length of unstretched spring | ||
|
||
|
||
Now we create an inertial reference frame, assign an origin, and set origin velocity to zero. | ||
|
||
>>> I = ReferenceFrame('I') # Inertial reference frame | ||
>>> O = Point('O') # Origin point | ||
>>> O.set_vel(I, 0) # Origin's velocity is zero | ||
|
||
Now we define the bob as a Particle. | ||
|
||
>>> P = Point('P') # Center Of Mass of the box | ||
>>> P.set_pos(O, q * I.y) # Set the position of P | ||
>>> P.set_vel(I, u * I.y ) # Set the velocity of P | ||
>>> bob = Particle('bob',P,m) | ||
|
||
We assign forces acting on the Particle. Coordinate axes are defined to be as : | ||
* x-axis: running from left to right, | ||
* y-axis: running from top to bottom, | ||
* z-axis: running from behind the plane to above the plane. | ||
|
||
Following the above notion, Gravity is taken to be in (+I.y) direction, | ||
and force due to spring(F=Kx), in -I.y direction. | ||
|
||
>>> f = m*g* I.y - k*(q)*I.y #Net force on bob. | ||
>>> force = [(P,f)] | ||
|
||
Setting up equation of motion for the body:: | ||
|
||
>>> diff_eq = [q.diff(t) - u] | ||
|
||
|
||
|
||
|
||
|
||
Advanced Tutorial | ||
----------------- | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
.. _Scipy: http://www.scipy.org | ||
|
This file contains 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,65 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
"http://www.w3.org/TR/html4/loose.dtd"> | ||
<html> | ||
<head> | ||
<title>Jasmine Spec Runner</title> | ||
|
||
<link rel="shortcut icon" type="image/png" href="jasmine/jasmine_favicon.png"> | ||
<link rel="stylesheet" type="text/css" href="jasmine/jasmine.css"> | ||
<script type="text/javascript" src="jasmine/jasmine.js"></script> | ||
<script type="text/javascript" src="jasmine/jasmine-html.js"></script> | ||
|
||
<!-- blanket.js for test coverage --> | ||
|
||
<script type="text/javascript" src="lib/blanket.min.js"></script> | ||
<script type="text/javascript" data-cover-only="canvas/" src="lib/jasmine-blanket.js"></script> | ||
|
||
<!-- include source files here... --> | ||
<script type="text/javascript" src="specs/specHelper.js"></script> | ||
<script type="text/javascript" src="lib/jquery.js"></script> | ||
<script type="text/javascript" src="lib/jquery-ui.js"></script> | ||
<script type="text/javascript" src="lib/three.min.js"></script> | ||
<script type="text/javascript" src="lib/TrackballControls.js"></script> | ||
|
||
<script type="text/javascript" src="canvas/initialize.js" data-cover></script> | ||
<script type="text/javascript" src="canvas/addObjects.js" data-cover></script> | ||
<script type="text/javascript" src="canvas/animate.js" data-cover></script> | ||
|
||
<!-- include spec files here... --> | ||
<script type="text/javascript" src="specs/canvasSpecs.js"></script> | ||
|
||
|
||
<script type="text/javascript"> | ||
(function() { | ||
var jasmineEnv = jasmine.getEnv(); | ||
jasmineEnv.updateInterval = 1000; | ||
|
||
var htmlReporter = new jasmine.HtmlReporter(); | ||
|
||
jasmineEnv.addReporter(htmlReporter); | ||
|
||
jasmineEnv.specFilter = function(spec) { | ||
return htmlReporter.specFilter(spec); | ||
}; | ||
|
||
var currentWindowOnload = window.onload; | ||
|
||
window.onload = function() { | ||
if (currentWindowOnload) { | ||
currentWindowOnload(); | ||
} | ||
execJasmine(); | ||
}; | ||
|
||
function execJasmine() { | ||
jasmineEnv.execute(); | ||
} | ||
|
||
})(); | ||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
</body> | ||
</html> |
This file contains 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,20 @@ | ||
Copyright (c) 2008-2011 Pivotal Labs | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8 spaces after commas