Generating eroded mountain terrain in a local / 'bottom-up' way - math

I'm picturing a typical random polygon hillside with ridges that come together into bigger ridges as you ascend and canyons that come together into bigger canyons as you descend.
The way you normally make something like this is to start with the top of the whole mountain and iterate until you have enough detail in the area you're interested in and then stop.
OK, suppose there is no absolute mountain top; it just keeps going; and I want to generate the neighboring chunk before I get to it so it matches up with what is already there.
After thinking about it for a while I think this is probably either impossible or involves a kind of math I haven't even heard of. On the other hand it -seems- like it 'should' be possible, (with extra information stored per-vertex)?

Maybe try doing it in 2D first and see what you can come up with.
It looks possible in 2D, in 3d it would work too but not with a real mountain with a top, more with an endless slope that does not converge to a point.
What you want to do is actually reversing the gravity rules in some sense.
Not sure if this is really an answer, but the question is quite vague too :)

Related

2D space organic projection

I'm currently working on a glsl shader (EDIT : I'm starting to think that a shader isn't necessarily the best solution and as I'm doing this in processing, I can consider a vectorial solution too) supposed to render something like this but filling the entire 2D space (or at least a larger surface):
To do so, I want to map the repeating patterns on the general leaves shapes that you can see on the top of the sketch below.
My problem is this mapping part : is it possible to find a function that project XY coordinates on the screen to another position in such a way that I can map my patterns the way I want? The leaves must have some kind of UV coordinates inside them (to be able to apply the repeating pattern) and the transformation must be a conformal map because otherwise, there would be some distortions in the pattern.
I've tried several lines of thought but I haven't managed to get the final result :
recursion :
the idea is to first cut the plane in stripes, then cut the stripes in leaves shapes that touch the top and the bottom of the stripes (because that's easier) and finally recursively cut the leaves in halves until the result looks more random. as long as the borders of the stripe aren't on the screen, it shouldn't be too noticeable. The biggest difficulty here is to avoid the distortion.
voronoi :
it may be possible to find a distance function guided by a vector field such that the Voronoi diagram looks more like what I'm looking for. However I don't think it will be possible to have the UV mapping I want. If it's the case, a good approximation woult do the trick, the result doesn't need to be exact as long as it isn't too noticable.
distortion :
it could also be possible to find a more direct way to do this projection. While desperately looking for a solution, I came across the fact that a continuous complex function is a conform map but I haven't managed to go any further.
Finaly, there may be another solution I haven't thought about and I would be glad if someone gave me a complete solution or just a new idea I haven't tried yet.

Is there a name for this type of problem involving dominos?

There's this problem that my professor showed me that I thought was interesting.
The problem is as follows:
If you have a 2^n by 2^n checkerboard and remove one square from it, will you be able to fill it with L-shaped trominos?
The answer to this is yes, the method of which I thought was interesting.
Example
In this example, X is the removed square and the numbers represent the shape of the L-shaped trominos. In every possible permutation of checkerboards, there should be a solution to fill up every square with trominos.
Does anyone know if this kind of problem is named in a field of math? I'd love to learn more about these.
I'm also going to attempt to program this, anyone have any ideas that could help?
There's a broad family of problems called tiling problems that ask when, whether, and how to tile different shapes using a fixed collection of figures.
There are other questions about figure subdivisions, where the question is when, whether, or how to subdivide some larger figure apart into smaller figures of various shapes.

How can I produce visualizations combining network graphs and imaginary maps?

Basically, I'm looking for something like this awesome research project: Gmap, which was referenced in this related SO question.
It's a rather novel data visualization that combines a network graph with an imaginary set of regions that looks like a map. Basically, the map-ification helps humans comprehend the enormous data set better.
Cool, huh? GMap doesn't appear to be open source, though I plan to contact the authors.
I already know how to create a network graph with a force-directed layout (currently using Prefuse/Flare), so an answer could be a way to layer a mapping algorithm on top of an existing graph. I'm also not concerned about the client-side at all right now - this would be a backend process, and I am flexible about technology stack and data output at this stage.
There's also this paper that describes the algorithm backing GMap. If you have heard of Voronoi diagrams (which rock, but make my head hurt), this paper is for you. I quit after Calc 1, though, so I'm hoping to avoid remembering what sigmas and epsilons are.
As a start, could you do a simple closest point sort of an algorithm? So it looks something like this: You have your force directed layout and have computed some sort of bounding box. Now you want to render it. Adjust your bounding box to line up to the origin and then as you calculate the color of each pixel, find it's closest point. This should generate some semblance of regions and should be quite simple to try out. Of course, it isn't going to be as pretty as GMap, but maybe a start? The runtime would be awful, but... I don't know about you but computing boundary lines directly sounds a lot harder to me.

How to determine all line segments from a list of points generated from a mouse gesture?

Currently I am interning at a software company and one of my tasks has been to implement the recognition of mouse gestures. One of the senior developers helped me get started and provided code/projects that uses the $1 Unistroke Recognizer http://depts.washington.edu/aimgroup/proj/dollar/. I get, in a broad way, what the $1 Unistroke Recognizer is doing and how it works but am a bit overwhelmed with trying to understand all of the internals/finer details of it.
My problem is that I am trying to recognize the gesture of moving the mouse downards, then upwards. The $1 Unistroke Recognizer determines that the gesture I created was a downwards gesture, which is infact what it ought to do. What I really would like it to do is say "I recognize a downards gesture AND THEN an upwards gesture."
I do not know if the lack of understanding of the $1 Unistroke Recognizer completely is causing me to scratch my head, but does anyone have any ideas as to how to recognize two different gestures from moving the mouse downwards then upwards?
Here is my idea that I thought might help me but would love for someone who is an expert or even knows just a bit more than me to let me know what you think. Any help or resources that you know of would be greatly appreciated.
How My Application Currently Works:
The way that my current application works is that I capture points from where the mouse cursor is while the user holds down the left mouse button. A list of points then gets feed to a the gesture recognizer and it then spits out what it thinks to be the best shape/gesture that cooresponds to the captured points.
My Idea:
What I wanted to do is before I feed the points to the gesture recognizer is to somehow go through all the points and break them down into separate lines or curves. This way I could feed each line/curve in one at a time and from the basic movements of down, up, left, right, diagonals, and curves I could determine the final shape/gesture.
One way I thought would be good in determining if there are separate lines in my list of points is sampling groups of points and looking at their slope. If the slope of a sampled group of points differed X% from some other group of sampled points then it would be safe to assume that there is indeed a separate line present.
What I Think Are Possible Problems In My Thinking:
Where do I determine the end of a line and the start of a separate line? If I was to use the idea of checking the slope of a group of points and then determined that there was a separate line present that doesn't mean I nessecarily found the slope of a separate line. For example if you were to draw a straight edged "L" with a right angle and sample the slope of the points around the corner of the "L" you would see that the slope would give resonable indication that there is a separate line present but those points don't correspond to the start of a separate line.
How to deal with the ever changing slope of a curved line? The gesture recognizer that I use handles curves already in the way I want it too. But I don't want my method that I use to determine separate lines keep on looking for these so called separate lines in a curve because its slope is changing all the time when I sample groups of points. Would I just stop sampling points once the slope changed more than X% so many times in a row?
I'm not using the correct "type" of math for determining separate lines. Math isn't my strongest subject but I did do some research. I tried to look into Dot Products and see if that would point me in some direction, but I don't know if it will. Has anyone used Dot Prodcuts for doing something like this or some other method?
Final Thoughts, Remarks, And Thanks:
Part of my problem I feel like is that I don't know how to compeletly ask my question. I wouldn't be surprised if this problem has already been asked (in one way or another) and a solution exist that can be Googled. But my search results on Google didn't provide any solutions as I just don't know exactly how to ask my question yet. If you feel like it is confusing please let me know where and why and I will help clarify it. In doing so maybe my searches on Google will become more precise and I will be able to find a solution.
I just want to say thanks again for reading my post. I know its long but didn't really know where else to ask it. Imma talk with some other people around the office but all of my best solutions I have used throughout school have come from the StackOverflow community so I owe much thanks to you.
Edits To This Post:
(7/6 4:00 PM) Another idea I thought about was comparing all the points before a Min/Max point. For example, if I moved the mouse downards then upwards, my starting point would be the current Max point while the point where I start moving the mouse back upwards would be my min point. I could then go ahead and look to see if there are any points after the min point and if so say that there could be a new potential line. I dunno how well this will work on other shapes like stars but thats another thing Im going to look into. Has anyone done something similar to this before?
If your problem can be narrowed down to breaking apart a general curve into straight or smoothly curved partial lines then you could try this.
Comparing the slope of the segments and identifying breaking points where it is greater then some threshold would work in a very simplified case. Imagine a perfectly formed L-shape where you have a right angle between two straight lines. Obviously the corner point would be the only one where the slope difference is above the threshold as long as the threshold is between 0 and 90 degrees, and thus a identifiable breaking point.
However, the vertical and horizontal lines may be slightly curved so the threshold would need to be large enough for these small differences in slope to be ignored as breaking points. You'd also have to decide how sharp a corner the algorithm should pick up as a break. is 90 deg or higher required, or is even 30 deg enough? This is an important question.
Finally, to make this robust I would not be satisfied comparing the slopes of two adjacent segments. Hands may shake, corners may be smoothed out and the ideal conditions to find straight lines and sharp corners will probably never occur. For each point investigated for a break I would take the average slope of the N previous segments and compare it to the average slope of the N following segments. This can be efficiently implemented using a running mean. By choosing a good sample number N (depending on the accuracy of the input, the total number of points, etc) the algorithm can avoid the noise and make better detections.
Basically the algorithm would be:
For each investigated point (beginning N points into the sequence and ending N points before the end.)
Compute average slope of the N previous segments.
Compute average slope of the N next segments.
If the difference of the averages is greater than the Threshold, mark current point as a breaking point.
This is quite off the top of my head. You'd have to try it in your application.
if you work with absolute angles, like upwards and downwards, you can simply take the absolute slope between two points (not necessarily adjacent) to determine if it's RIGHT, LEFT, UP, DOWN (if that is enough of a distinction)
the art is to find a distance between points so that the angle is not random (with 1px, the angle will be a multiple of 45°)
There is a firefox plugin for Navigation using mouse gestures that works very well. I think it's FireGestures, but I'm not sure. I guess you can get some inspiration from that one
Additional thought: If you draw a shape by connectiong successive points, then connecting back to the first point, the ratio between the area and the final line segment's length is also an indicator for the gesture's "edginess"
If you are just interested in up/down/left/right, a first approximation is to check 45 degree segments of a circle. This is easily done by checking the the horizontal difference between (successive) points against the vertical difference between points.
Say you have a greater positive horizontal difference than vertical difference, then that would be 'RIGHT'.
The only difficulty then comes for example, in distinguishing UP/DOWN from UP/RIGHT/DOWN. But this could be done by distances between points. If you determine that the mouse has moved RIGHT for less than 20 pixels say, then you can ignore that movement.

Programming math-based images for use in high-resolution artwork [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm interested in creating poster-sized images that contain repeating patterns, similar to the two (public domain) images below, the Flower of Life and a Penrose tiling:
My questions:
How do people usually create images like these on a computer? I'm hoping the answer isn't, "Open Adobe Illustrator and guess at intersection points," since such points can be defined mathematically. But I also imagine that not everyone with an interest in geometric patterns is also familiar with programming.
What is the best environment for creating such images? In particular, what's the best way to get high-resolution images out of Java, Python, Processing, etc? Or, is Mathematica the best tool?
Actually calculating the points and doing the math isn't the hard part, in my mind (at least, it's not the focus of this question). I'm interested in the best way to get a high-quality visual product out of a program.
The best way to create images like these is to learn to write PostScript. It's a clean language, easy to learn, and quite powerful once you know it well.
Bill Casselman's manuals are by far the best reference for high quality mathematical illustration.
Use a vector image format like SVG. This will scale perfectly to any resolution.
Inkscape is a great tool for creating these.
Once you have a vector image format, there are many options for using it in programming languages, depending on your language of choice.
For example -
.NET - SvgNet
ActionScript - svgweb
C++ - LeadTools
XAML for WPF/Silverlight - ViewerSVG (Converts SVG to XAML)
I don't know how those images were created, I would guess they were scanned from a book, but, in my work with fractals, I tend to start with just using the <canvas> tag, mainly so that I can change the size of the element and see it drawn more iterations, so I can get the highest resolution.
That is the problem with something like SVG is that you would need to pick a resolution and then create it, and it will scale well up and down, but if you developed it at one resolution, then you go to a higher resolution to demo, you may see more gaps than you would like.
If you want to just do it and save it as a static image then any GUI will work, as you are saving a GIF at that point, but if you want it, for example, on a web page, and have it look as good as it can on that browser then you may want to look at using javascript.
The math part isn't hard, and so drawing the image is fairly easy, once you derive the recursive algorithm that is needed. I tend to go to the next iteration until the size is below a threshold, for example, a radius of < 3, then it exits.
Well, #2 is going to be kind of a holy war so I'll address #1. :)
The key to images of this nature is recursion. Basically they are the same image repeated over and over in a controlled way to get an intersting result. Take the flower of life for example. You repeat the center petal six times (the method to do the petals is up to you). Then you create six more flowers using the petals tip as the center and overlapping one of the petals. You then recursively move outward. After a few "rounds" you stop and draw the containing circle. Basically the recusion simulates the stamp, move and rotate that would be required if you were doing it by hand.
When I have played around with these kinds of things I have always found that experimentation is the best way to get cool new things. Of course that could be just my lack of imagination. :)
I know I am not very math heavy in this answer but that is up to you and experimentation. Just remember that COS and SIN are your friends and there are 360 degrees in a cricle (or 2pi radians depending on your math package).
EDIT: Adding some math for the "Flower"
Starting with a center of (Xo, Yo) and a flower radius of r...
The tips of the petals (P0, P1, etc) are determined by...
X = Xo + (sin((n * pi)/3 + (pi / 6)) * r)
Y = Yo - (cos((n * pi)/3 + (pi / 6)) * r)
where n is the petal number (0..5)
Once you compute a petal tip, just draw the petal and then start a new flower at the tip. You would also set a bounding circle so that any point outside that circle would not be drawn.
I would try to create a PDF with iText in Java. PDF supports vector graphics, so it should scale without problems. I don't know how well iText scales w.r.t. performance when you have a really big number of graphic elements.
A1. You might want to look at turtle-graphics, l-systems, iterated function systems, space filling curves, and probably a lot of other approaches I'm not familiar with or haven't thought of yet.
A2. You can program any of these with any of the languages you suggest. I like Mathematica, but I know that not everyone has a copy of it and I have a copy 'cos I work in number-crunching and get to play with it for making pretty pictures. But Processing, which is free, was designed to be artist-friendly and might be a better starting point for you. Both Mathematica and Processing do the graphics right there and then, no calls to external libraries (or worrying which ones to use).
And, while I agree with everyone who says that vectors are the way to go, don't forget that the final productions step, onto paper or screen, is rendering so give some thought to how that will be done. This might, for example, lead you to Postscript or PDF for an output format.
Have fun
Mark
Well, I used to draw flowers of life with a compass, back then in junior school ... very simple actually ... but I don't think that's the answer you're looking for.
Basically it consists of drawing a circle of the same radius, from every point, until you encounter the big circle (limit).

Resources