diff --git a/.gitignore b/.gitignore index 1dfc28d..792fb5f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,10 @@ var sdist develop-eggs .installed.cfg +#lib lib64 __pycache__ - +build # Installer logs pip-log.txt diff --git a/README.rst b/README.rst index 9134cca..73d5d58 100644 --- a/README.rst +++ b/README.rst @@ -1,45 +1,75 @@ pydy-viz ======== -Exploration of visualization for PyDy systems. +Visualization of multibody systems generated with PyDy. Installation ============ Probably easiest to install the main dependencies from your package manager, -e.g.: +e.g.:: -$ apt-get python-numpy python-matplotlib + $ apt-get python-numpy python-setuptools -Download the source and then install with setuptools (this will pull in the -latest version of SymPy). +Then download the source and install with setuptools (this will automatically +install the latest version of SymPy):: -$ python setup.py install + $ python setup.py install Tests ===== -The Python tests require nose: +The Python tests require nose so get them with your package manager:: + $ apt-get python-nose python-coverage -$ pip install nose coverage +or pip:: -nosetests -v --with-coverage --cover-package=pydy_viz + $ pip install nose coverage -or run +The tests can be run from the root directory with:: -bin/test + $ nosetests -after nose is installed. +And to see more detail with coverage, run:: -For Javascript testing, Jasmine and blanket.js(code coverage) is used. -It is supplied with the source, -to run Javascript tests .. -Go to directory pydy_viz/static/js -run a simple HTTP Server in python(some cross browser issues with blanket.js) + $ nosetests -v --with-coverage --cover-package=pydy_viz -$ python -m SimpleHTTPServer +These are alternative ways to run the Python tests:: -and visit http://localhost:8000/SpecRunner.html + $ bin/test + $ python setup.py nosetests + +For the Javascript tests the Jasmine and blanket.js libraries are used. Both +of these libraries are included in pydy-viz with the source. To run the +Javascript tests, go to the javascript library directory:: + + $ cd pydy_viz/static/js + +Then run a simple HTTP Server with Python (the server is required due to some +cross browser issues with blanket.js):: + + $ python -m SimpleHTTPServer + +Now visit http://localhost:8000/SpecRunner.html in a webgl compliant browser. + +Documentation +============= + +Requires: + +- Sphinx +- numpydoc + +:: + + pip install sphinx numpydoc + +To build the HTML docs:: + + $ sphinx-build -b html docs/src docs/build + +View:: + + $ firefox docs/build/index.html -in a webgl compliant browser. diff --git a/docs/source/index.rst b/docs/source/index.rst deleted file mode 100644 index b4f813e..0000000 --- a/docs/source/index.rst +++ /dev/null @@ -1,24 +0,0 @@ -.. PyDy Visualization Package documentation master file, created by - sphinx-quickstart on Fri Jul 5 12:03:22 2013. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to PyDy Visualization Package's documentation! -====================================================== - -This Page is provided to document the progress and features of the visualization package PyDy-Viz - - - -.. toctree:: - :maxdepth: 2 - - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` - diff --git a/docs/src/Makefile b/docs/src/Makefile new file mode 100644 index 0000000..47ff580 --- /dev/null +++ b/docs/src/Makefile @@ -0,0 +1,130 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = ../_build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/yeadon.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/yeadon.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/yeadon" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/yeadon" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + make -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/src/api.rst b/docs/src/api.rst new file mode 100644 index 0000000..9394990 --- /dev/null +++ b/docs/src/api.rst @@ -0,0 +1,14 @@ +API +--- +All the module specific docs have some test cases, which will +prove helpful in understanding the usage of the particular module. + + +.. toctree:: + :maxdepth: 2 + + python_api.rst + javascript_api.rst + + + diff --git a/docs/source/conf.py b/docs/src/conf.py similarity index 92% rename from docs/source/conf.py rename to docs/src/conf.py index 396684b..b3ba2de 100644 --- a/docs/source/conf.py +++ b/docs/src/conf.py @@ -14,11 +14,11 @@ import sys import os - +import pydy_viz # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ @@ -30,14 +30,12 @@ # ones. extensions = [ 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', + 'numpydoc' ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['ytemplates'] +templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' @@ -49,7 +47,7 @@ master_doc = 'index' # General information about the project. -project = u'PyDy Visualization Package' +project = u'PyDy Visualization Distribution' copyright = u'2013, Tarun Gaba' # The version info for the project you're documenting, acts as replacement for @@ -57,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '0.0.1' +version = pydy_viz.__version__ # The full version, including alpha/beta/rc tags. -release = '0.0.1' +release = pydy_viz.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -133,7 +131,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['ystatic'] +html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. @@ -177,7 +175,7 @@ #html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'PyDyVisualizationPackagedoc' +htmlhelp_basename = 'PyDyVisualizationDistributiondoc' # -- Options for LaTeX output --------------------------------------------- @@ -197,7 +195,7 @@ # (source start file, target name, title, # author, documentclass [howto/manual]). latex_documents = [ - ('index', 'PyDyVisualizationPackage.tex', u'PyDy Visualization Package Documentation', + ('index', 'PyDyVisualizationDistribution.tex', u'PyDy Visualization Distribution Documentation', u'Tarun Gaba', 'manual'), ] @@ -227,7 +225,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'pydyvisualizationpackage', u'PyDy Visualization Package Documentation', + ('index', 'pydyvisualizationdistribution', u'PyDy Visualization Distribution Documentation', [u'Tarun Gaba'], 1) ] @@ -241,8 +239,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'PyDyVisualizationPackage', u'PyDy Visualization Package Documentation', - u'Tarun Gaba', 'PyDyVisualizationPackage', 'One line description of project.', + ('index', 'PyDyVisualizationDistribution', u'PyDy Visualization Distribution Documentation', + u'Tarun Gaba', 'PyDyVisualizationDistribution', 'One line description of project.', 'Miscellaneous'), ] @@ -262,7 +260,7 @@ # -- Options for Epub output ---------------------------------------------- # Bibliographic Dublin Core info. -epub_title = u'PyDy Visualization Package' +epub_title = u'PyDy Visualization Distribution' epub_author = u'Tarun Gaba' epub_publisher = u'Tarun Gaba' epub_copyright = u'2013, Tarun Gaba' diff --git a/docs/src/index.rst b/docs/src/index.rst new file mode 100644 index 0000000..a781e8b --- /dev/null +++ b/docs/src/index.rst @@ -0,0 +1,32 @@ +.. PyDy Visualization Package documentation master file, created by + sphinx-quickstart on Fri Jul 5 12:03:22 2013. + You can adapt this file completely to your liking, but it should at + least + contain the root `toctree` directive. + +PyDy Visualization Package's documentation! +=========================================== + +This is the central page for all PyDyViz's Documentation. +If you are already familiar with PyDy mechanics +package(sympy.physics.mechanics), you can start with the Tutorial. + + +Contents: + +.. toctree:: + :maxdepth: 2 + + introduction.rst + installation.rst + tutorials.rst + api.rst + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/src/installation.rst b/docs/src/installation.rst new file mode 100644 index 0000000..3fad69f --- /dev/null +++ b/docs/src/installation.rst @@ -0,0 +1,69 @@ +Installation +------------ + + +There are different methods you can use to get PyDyViz up and running +for your system. + +Dependencies: + +1) Python +2) SymPy +3) NumPy + +SciPy is used by the Code Generator module for numerical integration +of Equations of Motions.So not exactly a dependency for PyDyViz, +but is required anyways for Code Generator to work. + +Git +=== + +If you are a developer, or looking for the latest features without +waiting for another release, you can install the development version +from the git repository. + +Issue the following command from terminal:: + + $ git clone git://github.com/PythonDynamics/pydy-viz.git + +and then change directory to the cloned directory and run setup.py +install:: + + $ cd pydy-viz + $ python setup.py install + +and you will have the latest development version on board. + +Run PyDyViz +=========== + +You can check the installation by running the following command from +Python Interpreter:: + + >>> import pydy_viz + +If it does not throws any error/traceback, it means that PyDyViz +is installed. + + +You can check the version of the software by issuing following +command from interpreter:: + + >>> import pydy_viz + >>> print pydy_viz.__version__ + +Questions +========= + +If you have any question about installation, or any general question, +feel free to visit the IRC channel at irc.freenode.net, channel `#pydy`_. +In addition, our `mailing list`_ is an excellent source of +community support. + +If you think there’s a bug or you would like to request a feature, +please open an `issue`_. + + +.. _issue: https://github.com/PythonDynamics/pydy-viz/issues +.. _mailing list: http://groups.google.com/group/pydy +.. _#pydy: irc://irc.freenode.net/pydy diff --git a/docs/src/introduction.rst b/docs/src/introduction.rst new file mode 100644 index 0000000..f3590b2 --- /dev/null +++ b/docs/src/introduction.rst @@ -0,0 +1,18 @@ +Introduction +------------ + +PyDyViz ( short for PythonDynamics Visualizations) is a plugin to +facilitate browser based animations for PythonDynamics framework. + + +The plugin is used to generate animations for the multibody physical +systems. The systems are defined in PyDy Mechanics, and solved +numerically by PyDy Code Generator. + +Frontend is based on WebGraphics Library (Three.js) and code generation +is taken care of by PyDy. + +The package also provides a Python wrapper for some basic functionality +for Three.js i.e Geometries, Lights, Cameras etc. + + diff --git a/docs/src/javascript_api.rst b/docs/src/javascript_api.rst new file mode 100644 index 0000000..16194a5 --- /dev/null +++ b/docs/src/javascript_api.rst @@ -0,0 +1,99 @@ +JavaScript functions Reference +------------------------------- + +Canvas +====== +Canvas is the base class for handling all the animation and +visualization generation. + +canvas/initialize.js +==================== +Constructor: +^^^^^^^^^^^^ + +This function acts as a class constructor for Canvas class +It takes the JSON Object variable as the argument, which contains +all the data in the JSON format. +It binds onClick methods of certain Divs on the frontend +with some Canvas.prototype functions. + +Canvas.prototype.initialize +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function initializes the starting canvas, on which +all the visualizations are drawn. + +It adds following to the canvas: + - A Primary Camera + - Primary Trackball Controls + - A Primary Light + - Axes + - Grid + - A Div for displaying total number of frames. + - A Div for displaying the current frame animation is + running on. + +canvas/addObjects.js +==================== +Canvas.prototype.addControls +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function initializes the Primary Controls, +which were defined in Canvas.prototype.initialize function. + +It generates a controlsID, which contains the return value +of requestAnimationFrame, and can be used to call +cancelAnimationFrame, for stopping mouse controlled animation. + +Canvas.prototype.resetControls +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function simply calls the controls reset method +for the Primary Controls(canvas.prototype.primaryControls). + +Canvas.prototype.addCameras +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function parses the JSON Object for cameras +and adds them to the scene. +All the cameras are stored in a Canvas.cameras object, +which is an instance of THREE.Object3D(); + +Canvas.prototype.addLights +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function parses the JSON Object for lights +and adds them to the scene. +All the lights are stored in a Canvas.lights object, +which is an instance of THREE.Object3D(); + +Canvas.prototype.addFrames +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function parses the JSON Object for frames +and adds them to the scene. +All the frames are stored in a Canvas.frames object, +which is an instance of THREE.Object3D(); + +canvas/animate.js +================= +Canvas.prototype.startAnimation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function kick starts the animation. +It iterates over the frames and apply transformation matrices +from Simulation Matrix of that frame, iteratively. +by default animation is done for a single loop, +which can be changed to looped by the check button from the UI. + +Canvas.prototype.pauseAnimation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function pauses the animation, but retains the +current animation frame. + +Canvas.prototype.stopAnimation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This prototype function stops the animation, and resets +current animation frame to 0. diff --git a/docs/src/pymodules/cameras.rst b/docs/src/pymodules/cameras.rst new file mode 100644 index 0000000..5d1eaf7 --- /dev/null +++ b/docs/src/pymodules/cameras.rst @@ -0,0 +1,17 @@ +Cameras +======= + +Perspective Camera +^^^^^^^^^^^^^^^^^^ +.. autoclass:: pydy_viz.camera.PerspectiveCamera + :members: + + +OrthoGraphic Camera +^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: pydy_viz.camera.OrthoGraphicCamera + :members: + + + diff --git a/docs/src/pymodules/lights.rst b/docs/src/pymodules/lights.rst new file mode 100644 index 0000000..cf3c6cb --- /dev/null +++ b/docs/src/pymodules/lights.rst @@ -0,0 +1,13 @@ +Lights +======= + +PointLight +^^^^^^^^^^ + +.. autoclass:: pydy_viz.light.PointLight + :members: + + + + + diff --git a/docs/src/pymodules/scene.rst b/docs/src/pymodules/scene.rst new file mode 100644 index 0000000..93bdc6f --- /dev/null +++ b/docs/src/pymodules/scene.rst @@ -0,0 +1,10 @@ +Scene +======= + +.. autoclass:: pydy_viz.scene.Scene + :members: + + + + + diff --git a/docs/src/pymodules/shapes.rst b/docs/src/pymodules/shapes.rst new file mode 100644 index 0000000..0751489 --- /dev/null +++ b/docs/src/pymodules/shapes.rst @@ -0,0 +1,89 @@ +Shapes +===== + +Shape +^^^^^ + +.. autoclass:: pydy_viz.shapes.Shape + :members: + + +Cube +^^^^ + +.. autoclass:: pydy_viz.shapes.Cube + :members: + +Cylinder +^^^^^^^^ + +.. autoclass:: pydy_viz.shapes.Cylinder + :members: + +Cone +^^^^ + +.. autoclass:: pydy_viz.shapes.Cone + :members: + +Sphere +^^^^^^ + +.. autoclass:: pydy_viz.shapes.Sphere + :members: + +Circle +^^^^^^ + +.. autoclass:: pydy_viz.shapes.Circle + :members: + +Plane +^^^^^ + +.. autoclass:: pydy_viz.shapes.Plane + :members: + +Tetrahedron +^^^^^^^^^^^ + +.. autoclass:: pydy_viz.shapes.Tetrahedron + :members: + + +Octahedron +^^^^^^^^^^ + +.. autoclass:: pydy_viz.shapes.Tetrahedron + :members: + +Icosahedron +^^^^^^^^^^^ + +.. autoclass:: pydy_viz.shapes.Icosahedron + :members: + +Torus +^^^^^ + +.. autoclass:: pydy_viz.shapes.Torus + :members: + +TorusKnot +^^^^^^^^^ + +.. autoclass:: pydy_viz.shapes.TorusKnot + :members: + +Tube +^^^^ + +.. autoclass:: pydy_viz.shapes.Tube + :members: + + +Mesh +^^^^ + +.. autoclass:: pydy_viz.shapes.Mesh + :members: diff --git a/docs/src/pymodules/visualization_frame.rst b/docs/src/pymodules/visualization_frame.rst new file mode 100644 index 0000000..024f5db --- /dev/null +++ b/docs/src/pymodules/visualization_frame.rst @@ -0,0 +1,7 @@ +VisualizationFrame +================== + +.. autoclass:: pydy_viz.VisualizationFrame + :members: + + diff --git a/docs/src/python_api.rst b/docs/src/python_api.rst new file mode 100644 index 0000000..c36230c --- /dev/null +++ b/docs/src/python_api.rst @@ -0,0 +1,12 @@ +Python Modules Reference +======================== + +.. toctree:: + :maxdepth: 2 + + pymodules/shapes.rst + pymodules/visualization_frame.rst + pymodules/cameras.rst + pymodules/lights.rst + pymodules/scene.rst + diff --git a/docs/src/tutorials.rst b/docs/src/tutorials.rst new file mode 100644 index 0000000..8fe8d8e --- /dev/null +++ b/docs/src/tutorials.rst @@ -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 + diff --git a/docs/src/tutorials/basic.rst b/docs/src/tutorials/basic.rst new file mode 100644 index 0000000..dfdb87b --- /dev/null +++ b/docs/src/tutorials/basic.rst @@ -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 + diff --git a/pydy_viz/static/index.html b/pydy_viz/static/index.html index a183ece..a9de5bf 100644 --- a/pydy_viz/static/index.html +++ b/pydy_viz/static/index.html @@ -4,7 +4,7 @@ My first Three.js app - + diff --git a/pydy_viz/static/js/canvas/addObjects.js b/pydy_viz/static/js/canvas/addObjects.js index 0cc95bc..1b47d58 100644 --- a/pydy_viz/static/js/canvas/addObjects.js +++ b/pydy_viz/static/js/canvas/addObjects.js @@ -102,7 +102,6 @@ Canvas.prototype.addFrames = function(){ switch(_frame.shape.type){ case "Cube": - alert("In Cube"); var _geometry = new THREE.CubeGeometry( _frame.shape.length, _frame.shape.length, @@ -114,14 +113,14 @@ Canvas.prototype.addFrames = function(){ var _geometry = new THREE.CylinderGeometry( _frame.shape.radius, _frame.shape.radius, - _frame.shape.height, + _frame.shape.length, 50,50); break; case "Cone": var _geometry = new THREE.CylinderGeometry( _frame.shape.radius, - 0.1, + _frame.shape.radius/100, _frame.shape.length, 50,50); break; diff --git a/pydy_viz/static/js/canvas/animate.js b/pydy_viz/static/js/canvas/animate.js index 14a307c..de4c53b 100644 --- a/pydy_viz/static/js/canvas/animate.js +++ b/pydy_viz/static/js/canvas/animate.js @@ -1,5 +1,6 @@ Canvas.prototype.startAnimation = function(){ + $("#startAnimation").unbind("click"); for(var key in JSONObj.frames){ Canvas.prototype._animate(key, Canvas.prototype.animationCounter); @@ -14,18 +15,15 @@ Canvas.prototype.startAnimation = function(){ cancelAnimationFrame(Canvas.prototype.animationID); Canvas.prototype.animationCounter = 0; } - + }; Canvas.prototype._animate = function(key, counter) { - console.log(Canvas.prototype.scene.children[4].children[key]); var _element = JSONObj.frames[key].simulation_matrix[counter]; var matrix = new THREE.Matrix4(); matrix.elements = _element; - // TODO Replace exact number by getObjectbyName .. - console.log("key, counter, element:" + key, counter, _element); - + Canvas.prototype.scene.getObjectByName("frames").children[key].matrix.identity(); Canvas.prototype.scene.getObjectByName("frames").children[key].applyMatrix(matrix) @@ -35,7 +33,8 @@ Canvas.prototype._animate = function(key, counter) Canvas.prototype.pauseAnimation = function(){ cancelAnimationFrame(Canvas.prototype.animationID); Canvas.prototype.animationID = undefined; - + $("#startAnimation").click(Canvas.prototype.startAnimation); + }; Canvas.prototype.stopAnimation = function(){ Canvas.prototype.animationCounter = 0; @@ -45,7 +44,8 @@ Canvas.prototype.stopAnimation = function(){ for(var key in JSONObj.frames){ Canvas.prototype._animate(key, 0); } - + $("#startAnimation").click(Canvas.prototype.startAnimation); + }; Canvas.prototype._transform = function(key, i){ diff --git a/pydy_viz/static/js/canvas/initialize.js b/pydy_viz/static/js/canvas/initialize.js index 5ad2df0..557ebad 100644 --- a/pydy_viz/static/js/canvas/initialize.js +++ b/pydy_viz/static/js/canvas/initialize.js @@ -88,8 +88,6 @@ Canvas.prototype.initialize = function(){ this.scene.add(this.axes); this.renderer.render(this.scene, this.primaryCamera); - // copying to vars for - // Setting a basic Point Light for colors ... this.primaryLight = new THREE.PointLight(0xffffff); this.primaryLight.position.set(10,10,-10); diff --git a/pydy_viz/static/js/lib/jquery.js b/pydy_viz/static/js/lib/jquery.min.js similarity index 100% rename from pydy_viz/static/js/lib/jquery.js rename to pydy_viz/static/js/lib/jquery.min.js diff --git a/pydy_viz/visualization_frame.py b/pydy_viz/visualization_frame.py index 1cffe08..c7ac169 100644 --- a/pydy_viz/visualization_frame.py +++ b/pydy_viz/visualization_frame.py @@ -288,10 +288,8 @@ def evaluate_transformation_matrix(self, dynamic_values, constant_values): args = np.hstack((states, constant_values)) new = self._numeric_transform(*args) - print 'N:', n - print 'new:', new + self._visualization_matrix = new.reshape(n, 16) - print 'after reshape:', self._visualization_matrix return self._visualization_matrix def generate_visualization_dict(self):