Is it possible to use python in Unity3D for console development? - python

I am developing a 3D Graphing Calculator software in Unity3D. I am struggling to find good numerical/symbolic math libraries written in C/C#. Also, I want to make the calculator programmable (like the TI-84 Calculators everyone uses in school).
I found Python to be a very good language for the backbone of this project. SymPy and NumPy are really good math libraries. And Python would be really good for users to program the calculator. (Here is already a calculator, the Numworks, that supports Python programs. The team ported Python to the hardware.)
If I am developing for the PC, I could just use Python with openGL, or use IronPython in Unity.
However, I'm developing for the Nintendo 3DS. It may sound like a strange hardware choice, but it makes good sense. The 3DS has a stereoscopic display perfect for showing 3D functions. It has a joy stick to operate the camera. It has a touch screen to handle input. Imagine showing a height map of a 3D function on the lower display. You can use it to trace the function. You can draw a region D on it, and have the 3DS integrate over the region. You can take directional derivatives with your stylus. The possibility is endless.
The problem, of course, is that Unity doesn't support Python, and IronPython only supports Windows/Mac/Linux/Android.
Do you have any suggestions for me?
For example, any possible way to use python in unity for the 3DS? Any good math library in C/C#? Can I implement a good enough Python interpreter in C# to handle user's program (doesn't have to be complaint)?

You could try the Math.Net library for C#, it should have the functionality you need, or you could try IronPython, here is an article that might help you get started.
http://shrigsoc.blogspot.com/2016/07/ironpython-and-unity.html

Related

Tools for plotting QVector3D data?

I have a series of points (x,y,z) that I would like to plot as a vector in a 3D plane. Something like this.
I am successfully using QCustomPlot elsewhere, but the documentation says it cannot be used for 3D plots. Googling turned up QwtPlot3D, but it hasn't been maintained since 2007, as far as I can tell, and I don't want to run into any problems since I'm using Qt5. I was also looking at QtCharts but can't seem to find any example of plotting x,y,z data points.
Does anyone have tips for including a 3D graph in my C++/Qt application? Is there a tool that would work better with Python with Qt, rather than C++? Or another technology entirely? This graph will be part of a larger UI.
This might help, though I haven't used it:
http://doc.qt.io/QtDataVisualization/
Spend a little time looking into OpenGL. To display OpenGL scenes in Qt you would use QGLWidget (for Qt 4.x) or QOpenGLWidget (for Qt 5.x). OpenGL allows you to write graphics that run on a GPU card, meaning you can tap into the same horsepower used for 3D video games. Given time and inclination, you can build up a good 3D graphics library.
https://www.opengl.org/
http://doc.qt.io/qt-5/qopenglwidget.html
The Qt tutorials can help, but you'll also want to read other OpenGL tutorials. Here are some tutorials targeting older versions of Qt:
ftp://ftp.informatik.hu-berlin.de/pub1/Mirrors/ftp.troll.no/QT/pub/developerguides/qtopengltutorial/OpenGLTutorial.pdf
http://www.decom.ufop.br/sibgrapi2012/eproceedings/tutorials/t3-survey_paper.pdf
Tutorials tend to start with "immediate mode" examples, meaning the CPU is continually involved with updating data and writing that data to the GPU. As soon as you grasp the basics you'll want to implement "retained mode" code, meaning (very loosely) that the GPU manages the data and the need for CPU resources is minimized.
All that said, getting into OpenGL is a commitment. If you want the user to be able to change the viewpoint of the chart, or zoom in/out, or mouse over a plot to check individual values, etc., then it will take some time to implement. For a standard that's so widely use it's odd that the documentation and available textbooks aren't better--don't expect to find the OpenGL textbook equivalent of Kernighan & Ritchie or the Perl camel book.
There may be some Qt 3D graphing project somewhere that enjoys active development, and with luck maybe some other SO user will know about one.

CFD work with Python

I am a meteorologist, and lately I am trying to investigate the possibility of building my one sondes.
In order to do that, I have the following work plan :
I would like to generate 3D models pyformex. An alternative is openSCAD. But I start with pyformex - to generate simple cylindrical sonde shapes with associated extra features, e.g. intake tube or such.
Next, I will like to split it in Meshes, using PyDistMesh; as well as prepare a raytraced point cloud model with Xrt.
In the third step, I would like to perform the CFD works.
Now, my questions :
Are there some other simple Python Libraries to generate 3D models? I would like a very simple system, where i can issue commands like p = Parallelogram (length, height, width), or p.position(x,y,z) etc. It would be nice to have built in mouse interaction - that is, a built in drawing component, which I can use to display the model, and rotate/ zoom/pan with mouse.
Any other mesh generation tools?
For this step, I would need a multiphysics system. I tried to use OpenFOAM, it is too huge (to hack through). I have taken a look at SU2, but it seems to focus more on aerospace engineering, than Fluid Dynamics (I would like to simulate the flight of the sonde - which is closer to aerospace engineering, as well as the state of the atmosphere). Fluidity seems to suit my needs better, but I dont find a python fork thereof. So are there some general purpose, not too bloated up, multiphysics python library for geophysical and general hydrodynamic simulations? I have taken a look a MOOSE, also dont find a python binding for it.
Scientific visualization : Are there some 3 or 4 (or may be higher dimensional) visualization libraries? I would prefer to issue simple commands as Plot instead of first generating a window / form, and then putting the graphs on it, if possible.
FINALLY, and most importantly, if the same can be done by C++ or Fortan, or some other language besides java, I would also consider using those.
Have a look at http://freecadweb.org/. This seems to be under active development. It is a fairly complete open source CAD package written in python. I believe it also has tools for meshing.
For cfd, you might want to consider openfoam - http://www.openfoam.com/. This is an open source cfd package with the obligatory steep learning curve. There seem to be some python libraries to be available that link to it, however I'm not sure how active these are:
http://openfoamwiki.net/index.php/Contrib/PyFoam
http://pythonflu.wikidot.com/

Object Tracking: MATLAB vs. Python Numpy

I will soon be starting a final year Engineering project, consisting of the real-time tracking of objects moving on a 2D-surface. The objects will be registered by my algorithm using feature extraction.
I am trying to do some research to decide whether I should use MATLAB or use Python Numpy (Numerical Python). Some of the factors I am taking into account:
1.) Experience
I have reasonable experience in both, but perhaps more experience in image processing using Numpy. However, I have always found MATLAB to be very intuitive and easy to pick up.
2.) Real-Time abilities
It is very important that my choice be able to support the real-time acquisition of video data from an external camera. I found this link for MATLAB showing how to do it. I am sure that the same would be possible for Python, perhaps using the OpenCV library?
3.) Performance
I have heard, although never used, that MATLAB can easily split independent calculations across multiple cores. I should think that this would be very useful, and I am not sure whether the same is equally simple for Numpy?
4.) Price
I know that there is a cost associated with MATLAB, but I will be working at a university and thus will have access to full MATLAB without any cost to myself, so price is not a factor.
I would greatly appreciate any input from anyone who has done something similar, and what your experience was.
Thanks!
Python (with NumPy, SciPy and MatPlotLib) is the new Matlab. So I strongly recommend Python over Matlab.
I made the change over a year ago and I am very happy with the results.
Here it is a short pro/con list for Python and Matlab
Python pros:
Object Oriented
Easy to write large and "real" programs
Open Source (so it's completely free to use)
Fast (most of the heavy computation algorithms have a python wrapper to connect with C libraries e.g. NumPy, SciPy, SciKits, libSVM, libLINEAR)
Comfortable environment, highly configurable (iPython, python module for VIM, ...)
Fast growing community of Python users. Tons of documentation and people willing to help
Python cons:
Could be a pain to install (especially some modules in OS X)
Plot manipulation is not as nice/easy as in Matlab, especially 3D plots or animations
It's still a script language, so only use it for (fast) prototyping
Python is not designed for multicore programming
Matlab pros:
Very easy to install
Powerful Toolboxes (e.g. SignalProcessing, Systems Biology)
Unified documentation, and personalized support as long as you buy the licence
Easy to have plot animations and interactive graphics (that I find really useful for running experiments)
Matlab cons:
Not free (and expensive)
Based on Java + X11, which looks extremely ugly (ok, I accept I'm completely biased here)
Difficult to write large and extensible programs
A lot of Matlab users are switching to Python :)
I would recommend python.
I switched from MATLAB -> python about 1/2 way through my phd, and do not regret it. At the most simplistic, python is a much nicer language, has real objects, etc.
If you expect to be doing any parts of your code in c/c++ I would definitely recommend python. The mex interface works, but if your build gets complicated/big it starts to be a pain and I never sorted out how to effectively debug it. I also had great difficulty with mex+allocating large blocks interacting with matlab's memory management (my inability to fix that issue is what drove me to switch).
As a side note/self promotion, I have Crocker-Grier in c++ (with swig wrappers) and pure python.
If you're experienced with both languages it's not really a decision criterion.
Matlab has problems coping with real time settings especially since most computer vision algorithms are very costly. This is the advantage of using a tried and tested library such as OpenCV where many of the algorithms you'll be using are efficiently implemented. Matlab offers the possibility of compiling code into Mex-files but that is a lot of work.
Matlab has parallel for loops parfor which makes multicore processing easy (or at least easier). But the question is if that will suffice to get real-time speeds.
No comment.
The main advantage of Matlab is that you'll obtain a running program very quickly due to its good documentation. But I found that code reusability is bad with Matlab unless you put a heavy emphasis on it.
I think the final decision has to be if you have to/can run your algorithm real-time which I doubt in Matlab, but that depends on what methods you're planning to use.
Others have made a lot of great comments (I've opined on this topic before in another answer https://stackoverflow.com/a/5065585/392949) , but I just wanted to point out that Python has a number of really excellent tools for parallel computing/splitting up work across multiple cores. Here's a short and by no means comprehensive list:
IPython Parallel toolkit: http://ipython.org/ipython-doc/dev/parallel/index.html
mpi4py: https://code.google.com/p/mpi4py
The multiprocessing module in the standard library: http://docs.python.org/library/multiprocessing.html
pyzmq: http://zeromq.github.com/pyzmq/ (what the IPython parallel toolkit is based on)
parallel python (pp): http://www.parallelpython.com/
Cython's wrapping of openmp: http://docs.cython.org/src/userguide/parallelism.html
You will also probably find cython to be much to be a vastly superior tool compared to what Matlab has to offer if you ever need to interface external C-libraries or write C-extensions, and it has excellent numpy support built right in.
There is a list with a bunch of other options here:
http://wiki.python.org/moin/ParallelProcessing

Modelling a robotic arm motion in 3D, ideas?

I hope you don't mind if I ask for a bit of advice regarding modelling robotic systems. I've recently become rather interested in using inverse kinematics (IK) to control a 5 dof robotic manipulator. I have a solid foundation in IK but what I'm having trouble with is a way to visualize how the manipulator moves with respect to joint angles.
I've looked into using 3D toolkits (such as Blender, Panda3D, vPython) to create a 3d model of the arm, but I'm not sure if I should be looking something with physics support. I'm also not sure how well I can model motion with these packages. Anyone have any suggestions? What I'm NOT looking for is a full blown robotic simulator like Microsoft's Robotic Studio, I'd like to start with the basics and learn how everything works first, ie code the IK in Python, then visualize the motion in 3D. I'm very familiar with Python, so something that interfaces with Python would be preferable.
Thanks!
Well the great thing about Blender is that its API is actually in python!
In addition, it supports inverse kinematics (IK) quite well in addition to many other modeling tools.
Blender Cookie is a great resource.
Here is a tutorial on making IK rigs in Blender.
Blenders python api is documented quite extensively, and it even has an interactive python shell built right in so that you can see the effects of your script as you go along.
The physics engine that blender uses is the popular bullet physics engine, which has been used in many commercial games as well as a few feature films (2012 among them).
This isn't really a hard problem, is it? Presumably you're working out the math on your own; so if your robotic arm is visualized as, say, a few rectangular solids then all you need is something that will render these at the x,y,z coordinates and with the orientation vector you supply, updating when need be. OpenGL should do just fine for this, you could probably do it in <50 lines.
Python-Ogre is a wrapper around the very mature C++ engine OGRE 3D. I have used it for a pretty significant project and I would give the Python wrapper a mixed but mostly positive review. It's very capable and does a good job of wrapping all C++ functionality in a mostly Pythonic interface. You can get the physics support through one of the many OGRE extension modules which provide those capabilities.
The biggest negative is that the documentation for the Python interface is poor, and you will have to rely on the C++ library's documentation to make sense of some things. To give you a sense of what's possible, I was able to implement a scripting language around OGRE using Python and PyV8 (the language was Javascript), as I prototyped a C++ project.
The resulting prototype was very mature and robust, and I was able to wrap the internals of OGRE with high-level Javascript. With the scripting language I was able to script animation, materials, rendering and physics.

Simple simulations for Physics in Python?

I would like to know similar, concrete simulations, as the simulation about watering a field here.
What is your favorite library/internet page for such simulations in Python?
I know little Simpy, Numpy and Pygame. I would like to get examples about them.
If you are looking for some game physics (collisions, deformations, gravity, etc.) which looks real and is reasonably fast consider re-using some physics engine libraries.
As a first reference, you may want to look into pymunk, a Python wrapper of Chipmunk 2D physics library. You can find a list of various Open Source physics engines (2D and 3D) in Wikipedia.
If you are looking for physically correct simulations, no matter what language you want to use, it will be much slower (almost never real-time), and you need to use some numerical analysis software (and probably to write something yourself). Exact answer depends on the problem you want to solve. It is a fairly complicated field (of math).
For example, if you need to do simulations in continuum mechanics or electromagnetism, you probably need Finite Difference, Finite Volume or Finite Element methods. For Python, there are some ready-to-use libraries, for example: FiPy (FVM), GetFem++ (FEM), FEniCS/DOLFIN (FEM), and some other.
Here is some simple astronomy related python. And here is a hardcore code from the same guy.
And Eagleclaw solves and plots various hyperbolic equations using some python. However, most of the code is written in Fortran to do the computations and python to plot the results. If you are studying physics though you may have to get used to this kind of Fortran wrapped code. It is a reality. But this isn't really what your looking for I guess. The good thing it that it is documented in a literate programming style so it should be understandable.
Maybe PyODE?
I've heard of PyBox2D, which is a port of the really nice Box2D. To quote the site:
Box2D is a feature rich 2d rigid body physics engine, written in C++ by Erin Catto. It has been used in many games, including Crayon Physics Deluxe, winner of the 2008 Independent Game Festival Grand Prize.

Categories

Resources