Fluid simulation in Matlab - matlab

I have a (vertical) cylinder in Matlab, built using the patch command. For every 'level' of the cylinder I have a different radius, so that the 3D plot displays something like this:
Also, I used a sequence of images to simulate the movement of the structure (the radius at every level changes overtime).
What I would like to do now is the simulation of a certain mass of fluid passing through the cylinder. Say, the first image will show the fluid (a sphere?) on top, and the successive ones will show the fluid following the shape of the cylinder.
I tried to solve this problem by simply colouring the facets of the cylinder, but I would need something more "hydraulic-like".
How can I approach this problem? How fluids can be treated/modelled in Matlab environment?
Any suggestion/tip would be appreciated.

Related

Creating patterns in matlab / octave to show Moiré patterns

How can I create radial images like this (see images below)
My goal is to control the number of radial arms, thinkness, along with the angle they are created. I'm trying to create patterns that will show me different Moiré patterns when overlapped and turned / animated in octave / matlab.
PS: I'm using octave 3.8.1
I've tried the code here but it doesn't give me the fine tuning all of the following parameters, of radial arm amount, angle, and thickness. Also the image package is needed which I'm trying to avoid.
http://www.mathworks.com/matlabcentral/answers/uploaded_files/20287/moire_pattern.m
As I see it the two approaches which would be worth investigating first are equations and patches.
You could for instance generate a generic equation for an arm with parameters to control the rotation angle and the shape of the curve. You could then plot that at each of a given number of rotation angles, with varying linewidths (a plot property not an equation parameter). Your equation would probably not look pretty as you'd be best off specifying it parametrically (in terms of a third variable) or in polar coordinates, and then translating it to cartesian for the plot commands.
With patches you'd be computing the outline of the arm (as opposed to the centreline) and would probably find it convenient to generate the patch for one arm and then transform it for each rotation. This would be a one-liner with the appropriate rotational transform matrix, and the expression you use to generate the arm wouldn't need to be nearly so complex as it wouldn't need to handle the rotation. A quadratic might even do at a push.
Another advantage of patches is that, having generated an arm and rotated it around, you could also flip it and generate the figure with the opposite sense for very little extra code.

Corner Detection in 2D Vector Data

I am trying to detect corners (x/y coordinates) in 2D scatter vectors of data.
The data is from a laser rangefinder and our current platform uses Matlab (though standalone programs/libs are an option, but the Nav/Control code is on Matlab so it must have an interface).
Corner detection is part of a SLAM algorithm and the corners will serve as the landmarks.
I am also looking to achieve something close to 100Hz in terms of speed if possible (I know its Matlab, but my data set is pretty small.)
Sample Data:
[Blue is the raw data, red is what I need to detect. (This view is effectively top down.)]
[Actual vector data from above shots]
Thus far I've tried many different approaches, some more successful than others.
I've never formally studied machine vision of any kind.
My first approach was a homebrew least squares line fitter, that would split lines in half resurivly until they met some r^2 value and then try to merge ones with similar slope/intercepts. It would then calculate the intersections of these lines. It wasn't very good, but did work around 70% of the time with decent accuracy, though it had some bad issues with missing certain features completely.
My current approach uses the clusterdata function to segment my data based on mahalanobis distance, and then does basically the same thing (least squares line fitting / merging). It works ok, but I'm assuming there are better methods.
[Source Code to Current Method] [cnrs, dat, ~, ~] = CornerDetect(data, 4, 1) using the above data will produce the locations I am getting.
I do not need to write this from scratch, it just seemed like most of the higher-class methods are meant for 2D images or 3D point clouds, not 2D scatter data. I've read a lot about Hough transforms and all sorts of data clustering methods (k-Means etc). I also tried a few canned line detectors without much success. I tried to play around with Line Segment Detector but it needs a greyscale image as an input and I figured it would be prohibitivly slow to convert my vector into a full 2D image to feed it into something like LSD.
Any help is greatly appreciated!
I'd approach it as a problem of finding extrema of curvature that are stable at multiple scales - and the split-and-merge method you have tried with lines hints at that.
You could use harris corner detector for detecting corners.

MATLAB: Plotting lines inside an RGB Cube

I'm a MATLAB newbie and while I've found a few ways to create and show a RGB cube, I haven't figured out how to plot something within it.
Here's some context: I've got a few approaches to colour cycling implemented in javascript/html5. Concretely, my first attempt naively interpolates between provided "endpoints" in the RGB-colour space, another approach performs a similar translation in HSV-colour space.
What I'd like to do is gain some geometric intuition as to what my different models of colour cycling actually look like if I were to plot out the transitions in an RGB-cube. So to that end, I need to do the following:
1. Create a RGB Cube (I can already do this by cutting/pasting a solution that uses patch() that was found here
2. Plot my colour cycling models inside a semi-translucent RGB Cube from 1
Would appreciate any help on this!

Heat map generator of a floor plan image

I want to generate a heat map image of a floor. I have the following things:
A black & white .png image of the floor
A three column array stored in Matlab.
-- The first two columns indicate the X & Y coordinates of the floorpan image
-- The third coordinate denotes the "temperature" of that particular coordinate
I want to generate a heat map of the floor that will show the "temperature" strength in those coordinates. However, I want to display the heat map on top of the floor plan so that the viewers can see which rooms lead to which "temperatures".
Is there any software that does this job? Can I use Matlab or Python to do this?
Thanks,
Nazmul
One way to do this would be:
1) Load in the floor plan image with Matlab or NumPy/matplotlib.
2) Use some built-in edge detection to locate the edge pixels in the floor plan.
3) Form a big list of (x,y) locations where an edge is found in the floor plan.
4) Plot your heat map
5) Scatterplot the points of the floor plan as an overlay.
It sounds like you know how to do each of these steps individually, so all you'll need to do is look up some stuff on how to overlay plots onto the same axis, which is pretty easy in both Matlab and matplotlib.
If you're unfamiliar, the right commands look at are things like meshgrid and surf, possibly contour and their Python equivalents. I think Matlab has a built-in for Canny edge detection. I believe this was more difficult in Python, but if you use the PIL library, the Mahotas library, the scikits.image library, and a few others tailored for image manipulation, it's not too bad. SciPy may actually have an edge filter by now though, so check there first.
The only sticking point will be if your (x,y) data for the temperature are not going to line up with the (x,y) pixel locations in the image. In that case, you'll have to play around with some x-scale factor and y-scale factor to transform your heat map's coordinates into pixel coordinates first, and then plot the heat map, and then the overlay should work.
This is a fairly low-tech way to do it; I assume you just need a quick and dirty plot to illustrate how something's working. This method does have the advantage that you can change the style of the floorplan points easily, making them larger, thicker, thinner, different colors, or transparent, depending on how you want it to interact with the heat map. However, to do this for real, use GIMP, Inkscape, or Photoshop and overlay the heatmap onto the image after the fact.
I would take a look at using Python with a module called Polygon
Polygon will allow you to draw up the room using geometric shapes and I believe you can just do the borders of a room as an overlay on your black and white image. While I haven't used to a whole lot at this point, I do know that you only need a single (x,y) coordinate pair to be able to "hit test" against the given shape and then use that "hit test" to know the shape who's color you'd want to change.
Ultimately I think polygon would make your like a heck of a lot easier when it comes to creating the room shapes, especially when they aren't nice rectangles =)
A final little note though. Make sure to read through all of the documentation that Jorg has with his project. I haven't used it in the Python 3.x environment yet, but it was a little painstaking to get it up an running in 2.7.
Just my two cents, enjoy!

Single Axis Simulation in Matlab

Hi i wanted to generate a single axis graph (dont know if this is called a graph exactly) in matlab something like this
In the above image the numerical values represent time ( 1 till 23) min and the vertical thin black lines represent event A . Some of the vertical black lines have a red circle on top denoting occurrence of an event B along with the event A. Is it possible to generate such a simulated image in matlab ? If so what keywords should i look for. Any suggestions to get me quickly started on generating such a graph/Simulation. (Note: I havent actually used matlab a lot.. certainly never generated graphs in it)
You probably want a stem graph, and then do something like:
stem(event_times, ones(size(event_times));
You can overlay multiple graphs to get the red circles, etc.