I want to visualize two different algorithms that decide if there's overlap in a collection of circles in a plane in Java:
Is there a way to let an object of a vizualization class 'listen' to an object of the algorithm class in a way that it can for example see when the algorithm is performing an overlap check between a pair of circles and knows when to update the visualization?
other example: I can keep the list of active circles(those which intersect the sweep line) as a variable of the sweep line algorithm and let another class(visualization class) get that variable. But how will that class know when the list is updated and it has to update the visualization?
That's just the strategy I was thinking of. Maybe there are better ways...
Algorithm Visualizer is an interactive online platform that visualizes algorithms from code. Learning an algorithm gets much easier with visualizing it.
It is called algorithm visualization and can be defined as the use of images to convey some useful information about algorithms. Algorithm Visualization. In addition to the mathematical and empirical analyses of algorithms, there is yet a third way to study algorithms.11-Jan-2017.
Perhaps reading up on the Observer pattern can help you: https://en.wikipedia.org/wiki/Observer_pattern
You can either implement java.util.Observer or give the algorithm a callback function / object.
You can hand the observer arbitrary data, enough to allow it do decide when the algorithm is performing an overlap check.
I'm not sure whether or not this will help you or not, but if you can't change the code of the algorithm to support observers then one (interesting) option would be to look into aspect-oriented programming.
For example, in AspectJ (e.g. see http://en.wikipedia.org/wiki/AspectJ) you can specify (using things called 'pointcuts') places (called 'join points') where bits of extra code (called 'advice') should be run. You could use this to detect overlap checks being performed by the algorithm and respond to them as you see fit.
Of course, doing things this way would involve using AspectJ, so it wouldn't be possible with just normal Java - but it's something interesting you might want to look into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With