I need help integrating a Python/Cython program (calculation/
simulation) with Java (GUI front-end with Swing, mouselistener,
animating graphics).  If anyone has experience integrating different
languages with Sage and the notebook, experience combining Python (and
Cython/C) with other languages, or experience integrating server/
client code, you could probably help me out.

I know that if I write my code in Python/Cython, I can compile it to
C, and call the C program from Java.  But I think a much better way to
do this would be to have Python/Cython call Java-that way you run a
Python/Cython program.

I have looked into this and found JPE Java-Python Extension and JPype,
which aim to provide a way for a standard Python program to call a
Java program.  However, I fear that these may not work on all of the
platforms Sage supports.

And then I also will have to worry about letting the program be run
locally (easier), or from the Sage server (the Python/Cython would be
run on the server and the Java applet would be run locally), which
appears more difficult because I would presumably need to pipe mouse
actions and graphics calls over the Internet.
 (this seems computationally expensive to me)

Is there a better option?  I believe that even if I used JavaScript (a
client-side language) in place of Java, I would still need to pipe
mouse actions and graphics calls over the Internet (which I worry is
too computationally expensive).  Am I wrong about this network
communication being too expensive?

If I did everything in Java, then it would be easier to run the
program locally or on a server (as an applet that is downloaded to the
client), but I don't have the feeling that Java is the best
environment to do development for Sage in (if possible in practice at
all).

What are my options?  Should I just focus on making the program work
locally (either put functioning on the Sage server on a wish-list or
just require downloading the program and Sage to run it)?  It sure
would look nice to see my program running on the Sage server with a
Java front-end on a smart phone.

If MMORPGs can handle the problem of having animating graphics
controlled by mouse and keyboard locally with communication with a
server orchestrating a large percentage of the interaction, then Sage
should be able to too.  Maybe for the Python/Cython running on the
Sage server case, I could be very careful about the mouse actions that
are piped across the network. Instead of sending a packet every time
the mouse cursor moves a few pixels, maybe I could keep a queue of
mouse actions in the Java applet and then only send a packet every, oh
I don't know, fourth of a second with the total mouse movement.  I
tried something similar to this (storing mouse actions in a queue and
then combining them into larger total movements before responding to
them) for a physics demo I made in Java.  And as far as piping
graphics commands over the network, maybe instead of sending each and
every drawLine from the Sage server to the Java applet on the client,
maybe I could load the coordinates of the bodies into the applet, and
then only communicate the movement of the bodies (move(x,y,theta)).
Maybe I could have the Python/Cython compute the exact movement of the
bodies, but only give the Java applet a series of "snapshots" of
positions that are interpolated (likely better than linearly) by the
Java applet to create believable animation.

Kevin Stueve

On Nov 15, 3:42 pm, kstueve <kevin.stu...@gmail.com> wrote:
> I need my program to have a graphical interface when run either
> locally or on a remote server.  My options are either JavaScript and
> Java for the GUI front-end that communicates with the main Python
> program.
>
> Does anyone have any thoughts on using one over the other?  Although
> Java
> has the drawback that it isn't as widespread and seamless as
> JavaScript, it does have powerful graphics capabilities.  Do you think
> Java would produce smoother animation?
>
> I would appreciate it if anyone has any links to JavaScript libraries
> (or general suggestions on making a JavaScript GUI front-end that
> communicates with a Python program) that might be helpful.
>
> Here are links to Phun/Algodoo, a powerful commercial 2Dphysics
> program
> that gives students a qualitative understanding 
> ofphysicsprinciples.http://www.youtube.com/watch?v=0H5g9VS0ENMhttp://www.algodoo.com/wiki/Home
> That is the bar I am aiming for (with quantitative output too).
>
> Kevin Stueve
>
> On Nov 13, 5:09 pm, kstueve <kevin.stu...@gmail.com> wrote:
>
>
>
> > To sage-dev
> > Can someone please explain to me what traits are in the context of
> > tvisual?  The wiki page for it (http://www.enthought.com/traitsfrom
> > the pagehttps://svn.enthought.com/enthought/wiki/TVTKIntroduction) is
> > a dead link.
> > A google search of either vpython.org or svn.enthought.com produces
> > many results for visual, but none for tvisual.  I am guessing that
> > tvisual is part of TVTK and visual part of VPython.
>
> > I see tvtk at the 
> > pagehttps://svn.enthought.com/enthought/wiki/TVTKIntroduction
> > (traited vtk), and vtk 
> > athttp://mayavi.sourceforge.net/.http://www.vtk.org/saysthat vtk is the 
> > visualization toolkit.
>
> > Jason Grout said "Since we also already have momentum for
> > incorporating mayavi.."  Can someone please give me details.  Is Jason
> > saying that Sage-dev is in the process of making mayavi part of Sage,
> > so it would be easy to use parts of mayavi?
>
> > What are the benefits of using tvtk over vpython?  Vpython is faster.
> > How does Tvtk has a cleaner API?
>
> > Does pydy handle collisions and contact forces?  I have read papers
> > that say that calculating contact forces for a large number of
> > simultaneously contacting rigid bodies is an NP-hard problem that
> > involves quadratic programming.  There is lots of interdependency.
> > You can have a normal force and friction force at each contact point.
> > But you have to make sure that normal forces only push, not pull, and
> > you have to make sure that kinetic friction opposes motion (or pending
> > motion), and static friction is less than mu * Fn.  During a collision
> > you have to have an infinite force for an instant to keep the objects
> > from colliding.  If you take the time integral of force, you get
> > impulse, which is a change in momentum (mass times velocity), so what
> > you are basically saying is that you have an instantaneous transfer of
> > momentum.  If you have an ellipse roll, the normal force will increase
> > sharply to a maximum at the location of least curvature.  If you have
> > a "rounded square" defined by a certain equation, the normal force
> > will reach infinity at the location of zero curvature.  However, the
> > area under the curve is finite, meaning that an instantaneous impulse
> > is not occurring.  You just need a very good numerical integrator.
> > Including kinetic friction can lead to situations where an
> > instantaneous impulse is needed to prevent inter-penetration at times
> > other than a collision.  Additionally, in some cases there are
> > multiple allowed solutions for where the objects go.
>
> > I have considered using the penalty method for handling collisions,
> > which involves allowing inter-penetration and a virtual spring force
> > that appears during inter-penetration.  However very large spring
> > constants must be used, leading to stiff equations.  One benefit of
> > penalty methods is that the multiple solutions in impulse methods go
> > away-which solution you end up with depends on whether the objects
> > that are touching are inter-penetrating or just touching.
>
> > I am also considering handling only collisions between two objects at
> > a time (with rotation and friction), since most problems I want PPS
> > (PythonPhysicsSimulation) to handle would be covered.  One problem
> > that might be left out is two gliders on a track colliding, but for
> > this problem, you could lock the gliders to the track and consider the
> > gliders hitting as collision of two bodies, not three.  I think that
> > if you are careful, you could properly handle the gliders on a track
> > colliding with only two-object collision handling.
>
> > What I want to make is a program that does for freshmanphysics
> > (springs, ramps, collisions, rotation, pulleys, strings, etc) what my
> > circuit program at circuitengine.com does for freshman circuits (and
> > hopefully more).  You click a button and make a spring, ramp, block,
> > pulley etc.  You right click an object and adjust its properties.  You
> > hit start.  You can make graphs.  You can ask it to tell you how long
> > it takes for something to happen (e.g. height of object A is 10m), and
> > it uses some sort of decrease and conquer (binary search in the worst
> > case, but better can be done if we make an estimate of when the event
> > happens) to find the exact time that that happens.
>
> > Could anyone recommend any programs that have this sort of
> > functionality for me to look at?
>
> > Does anyone have any thoughts on using OpenModelica?
>
> > Another question:
> > Time permitting, I would like to be able to solve symbolicphysics
> > problems.  Instead of just giving initial conditions and solving for
> > later values, it would be nice to say (symbolically) "it takes t
> > seconds for the ball to reach the basket, at what angle was it
> > thrown".  How might you go about this?  I think that this could be
> > done using a theorem prover of sorts that searches the space of
> > theorems that can be proven from a small set of axioms and givens and
> > a set of manipulation rules.  Of course this is an NP-complete problem
> > that is intractable in general (think Fermat's last theorem), but most
> > problems given to freshmanphysicsstudents are only a few steps long,
> > meaning that the tree of possible proofs is relatively small and can
> > be exhaustively searched.
> > Does Sage have the ability to symbolically simplify "sin^2(theta)+cos^2
> > (theta)" to "1"?
>
> > For numeric problems such as "at what angle must the ball be thrown to
> > reach the basket in 2 seconds?", it might be possible to use some sort
> > of binary search to find the correct value.
>
> > Here is a link to my (very early) pre-draft of my writeup, so that you
> > can view the bibliography.http://docs.google.com/View?id=df9q29vh_45dfx2wmfg
>
> > I declare Crocker's rules.  http://www.sl4.org/crocker.html
>
> > Kevin Stueve
>
> > On Sep 23, 3:31 pm, Fernando Perez <fperez....@gmail.com> wrote:
>
> > > On Wed, Sep 23, 2009 at 4:41 AM, Prabhu Ramachandran
>
> > > <pra...@aero.iitb.ac.in> wrote:
> > > > Thanks Fernando.  The speed issue is still true but I wouldn't blame
> > > > traits since that isn't the source of the bottleneck. I think there are
> > > > a little too many events and too many renders. I have not had the time
> > > > to profile it carefully.
>
> > > Thanks for the clarifications, Prabhu.  I remembered the performance
> > > drop, but wasn't sure what all of the reasons were under the hood and
> > > I was worried I could misrepresent the issue.
>
> > > It would really be great to have vpython-like performance with the
> > > clean tvtk api!  Here's to hoping it's possible :)
>
> > > Cheers,
>
> > > f

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to