Kevin's comment is great: that is the simplest method of using a .jar that isn't wrapped as a Processing library (or setup with that structure). Simply drag and drop the .jar file into your sketch.
If you only have a single sketch to prototype with and share, this is by far the easiest option.
If you need to use the .jar in multiple sketches, and perhaps share that with others, you can use the method bellow on mimicking a Processing library structure.
That library isn't wrapped as a Processing library and depends on the Apache Commons Math library. In theory, you could use that in Processing, but it's long winded, as you'd have to:
- Download commons-math3-3.6.1-bin.zip
- Unzip it, and rename commons-math3-3.6.1.jar to commons_math.jar (Processing is restrictive on certain characters in library names)
- Make a folder in Documents/Processing/libraries named commons_math then inside of it another folder named library (so you'll have Documents/Processing/libraries/commons_math/library)
- Copy commons_math.jar in Documents/Processing/libraries/commons_math/library
- Restart Processing
At this point, you should be able to do this in Processing: Sketch > Import Library... > (Contributed) commons_math and you'll see ALL the packages imported. You should be able to run the sketch, demonstrating you can use the library.
Next up is the trilateration library, which isn't build, so you'll need install/setup gradle, build it, then repeat the procedure above for the trilateration library. An alternative is to create 3 tabs in the sketch(to try and keep it tidy), one for each of trilateration library classes, copy the source code, remote the public
modifier prefixing each class (as Processing sketches in the Processing IDE allow a single public class) and remove the package declaration.
Finally you should be able to use this library in Processing...phew!
It's tedious, a pain to maintain, etc., etc. ,etc.
I recommend using eclipse instead. If you want to save time creating a Processing Project, instead of manually copying the Processing core libraries, creating a main class extending PApplet, etc. you can install Proclipsing.
It's an eclipse plugin that makes it easy to create Processing Java projects.
Once you're in eclipse and can run a basic sketch, all you need to do is:
- Add the Apache Commons Math jar into the projects lib/user folder

- Add the library to the build path

- Download/unzip the trilateration library
- From the library folder's src/main/java drag the com folder on top of the eclipse project's src

- Copy the example code from the library's readme:

- Notice some code is in red, because the classes aren't imported. Press
CMD+Shift+O
(on OSX)/Ctrl+Shift+O
(on Linux/Windows). This will organize imports (and do the job for you). The first suggestion works like a charm:
- Right click the sketch and choose Run As > Java Application:

Woo hoo! You can run the sample code now.
It doesn't look impressive though: nothing is displayed, not even in console, but hey, it compiles :D
You can easily add a few print statements to see the results:
println(centroid);
println("standardDeviation",standardDeviation);
println("covarianceMatrix",covarianceMatrix);
At this point you can start modifying the code do what you want it to do.
Bare in mind most drawing functions in Processing take float
arguments and this library works mostly with double
so be sure to cast from double
to float
before drawing.
If you've been using Processing for a while, the eclipse route sounds doable and there's so many nice features in the IDE to speed up development.
Is there a faster way ? Could be: have a look at the M2E which makes it easy to integrate with Maven in eclipse. The trilateration library has Maven support. In theory, you can have Maven do the heavy tedious work of adding the Apache Commons Math, compile and add the trilateration library to your project. This is going further from Processing land and moving more into Java territory, but if you have the time: it's work exploring. The more Java you know, the easier it will be to get Processing to do your bidding :)
In an ideal, you would use the Processing Library Template to not only use the .jar you plan to use, but also add utility functions to interact with PApplet
directly (perhaps convert between org.apache.commons.math3 Vector types to Processing PVector, etc.).
This could then be easily be shared publicly with the wider Processing community.