Title: Iterative Sinus-Curve and the extension of line-curves Post by: SamTiba on March 19, 2017, 08:56:32 PM Think of the koch-curve, the levi c curve, the dragon curve and many others, they all start with one segment - a simple line - and iterative extend itself to a stunning fractal. They are also known as the first examples of fractals. The self-similarity and the simple definition made them popular.
The base definition of every of these curves consists of two information: Each point of our second step - when we apply the transformation for one time - has an amplitude and a phase. After that we have several segments where we are able to repeat our transformation, you can describe this as an addition of the modified amplitude under an angle. Is there a possible extension to curves? I want to find out with you together and made the first step: Think of the Sinus-fractal. For each point of one period we have an amplitude and the angle defined by the tangent (cosine). For the seperation I chose to half the segments every time (because the sine passes zero there). Now for the next step we add two smaller sines to the normal sine under the specific angle of that point. For the first three steps it looks like this: (https://scontent-fra3-1.xx.fbcdn.net/v/t1.0-9/17352218_1277079572327518_5600486632679947725_n.jpg?oh=ac9e7f42d8bf93c14a16f1b779032652&oe=595DF238) You can already see interesting parts, after 100 iterations with 40000 points it will look like this: (https://scontent-fra3-1.xx.fbcdn.net/v/t1.0-9/17425116_1277079575660851_1341863350122949375_n.jpg?oh=6983f175c58c129e8303f1ab9b4bbb20&oe=59602B8B) Zoom in on the point near [Pi,0]: (https://scontent-fra3-1.xx.fbcdn.net/v/t1.0-9/17424611_1277079578994184_6590410054806486927_n.jpg?oh=e7226b8cfcd5ca3b3583667d4541a99a&oe=596543AB) I am sorry for the bad quality, I just came up with this idea and found the results stunning and wanted to share it with you. I will share more information and images when I get them. Feel free to build it by yourself and enhance the features. I would also like to hear what you think of it (maybe it already exists ..). Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: DarkBeam on March 19, 2017, 08:59:22 PM :beer: lovely idea
Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 19, 2017, 09:04:01 PM As a whole it is kinda ugly, but I guess it gets interesting when you zoom in.
I always thought of the sine as the definition of smoothness because of it's connection to the circle, never thought the outcome would be such a strange thing. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 19, 2017, 09:42:11 PM This method seems to work out pretty good, here are two more examples.
I have the underlying function and the next two steps visualized in the final curve. First one is cosine - 1 (to start end and at zero) and the second one is x^3 - x in [-1,1]. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 19, 2017, 11:16:03 PM How exactly are you generating these? I just tried something evidently else, giving different results: Basically, assuming I did it right, displacing the original function by (potentially rescaled) copies of itself shifted along its normal. The results are quite wild depending on how you choose to rescale your function at each step.
The only problem I have is that it requires me to take derivatives of more and more complex expressions which eventually (much sooner than I'd hope for) takes a prohibitively long time to do, because I need to normalize the normal at each step, giving me a more and more nested square root at each step. Perhaps some high quality numeric differentiation could help with that... (http://puu.sh/uQARL/c2cbfe8492.png) This is in sage math (so essentially python plus symbolic calculation stuff) Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 19, 2017, 11:45:30 PM Nah mate, I guess you do not really need to normalize the tangent.
I transform the tangent to an angle and add it via the rotationmatrix multiplied with the value-vector [0,Val] (so its [-sin(phi)*Val,cos(phi)*Val]). I work with arrays, it may disable high resolution at high scales but works well for the beginning. If you want to have a closer look I can send you my code and explain it further (written in Matlab but quite easy and understandable). Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 20, 2017, 12:15:11 AM with 'it' I meant the next rescaled step.
I rescale with using a modulo on my array-access and a rescale-factor for my amplitude. (I'm somehow not able to edit comments properly so you get it in a new comment) Since every periodic function starts and ends at the same point (and mostly at zero aswell) they suit well for this method since we get smooth transitions. In attachement a Curve made with sin(x) + cos(2*x) - cos(3*x). It looks quite chaotic but I like the non-symmetry. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 20, 2017, 12:23:07 AM Wait, so you are shifting the function tangentially? - As said, I shifted along the normal.
If you convert the tangent of your function to an angle, you kind of already implicitly used a normalization. Plugging the angle back into cosine and sine will give you precisely the same components as if you had just normalized the tangent. I'm not sure but I think a square root is probably faster than an atan2 + cosine + sine. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 20, 2017, 02:30:27 AM I'm more used to using rotation coordinates due to my mechanic courses so it seemed more natural for me that way.
I guess I somehow shifted tangentially but since I swapped my value to the y-part I overall shifted along the normal. I double-checked my code and it seems like the tan-function is causing trouble, thats why we get all those spirals near to points where the tan-function is not continous. In fact these false results where more stunning then the real ones. Never thought computational mistakes can be so interesting. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 20, 2017, 08:58:02 AM Never thought computational mistakes can be so interesting. Heh. That's... actually kind of a staple of these fora.People try out new stuff all the time, then figure out they did something completely wrong somewhere, correct it and BAM the result is (comparatively) dull and boring. It still looks interesting though. And it's ALSO something different from what I got. So what are you doing now, exactly? Can you give some (pseudo-)code? Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 20, 2017, 11:41:27 AM the code is really easy, i give you the interesting part of mine (made in matlab) :
syms x pos = [x;sin(x)]; tangent = diff(pos,x)/norm(diff(pos,x),2); % itertaion depth for in = 2:n fac = 2^(in-1); pos = pos + [0,-1;1,0]*sin(fac*x)/fac*tangent; tangent = tangent + diff([x;sin(fac*x)/fac])/norm(diff([x;sin(fac*x)/fac]),2); end The last picture I posted was made using arrays, I just enhanced my symbolic-code and it takes long computing when you get to iteration-depth of 50 or up (compared to arrays) but it looks totally different again (and this time more interesting). Seems like im still not to the bottom of this. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 20, 2017, 12:11:14 PM I hope this is it. Results are stunning and smooth aswell.
As said before things can get strange when we use more complex periodic functions. In attachement the curves for cos(x) - 1 and sin(x) + cos(2*x) - cos(3*x) Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 20, 2017, 12:40:40 PM It works for surfaces aswell and looks great. Only problem is, that every function has to be continous (and best would be differentiable) at the edges elsewhise the surface will look very distorted.
Maybe you can avoid this with shifting the surface on a sphere (riemann sphere would work out good for every function?) so that we need fewer points to be edges. Attached a quick render I did with the function sin(x)*sin(y). Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 20, 2017, 11:37:38 PM Ok I think I now get almost what you do:
(http://puu.sh/uS9UO/2c61fa6a0d.png) Though I think you may have made an error in the normalization of the tangent? You gotta normalize the entire tangent, not just what ever piece you add at each iteration. Your tangent, and therefore your normal, probably tends to be too long (though since it's directed it may also occasionally end up being too short). You keep adding together vectors which have length 1, their sum not necessarily (or even likely) having length off 1 again. My own really silly error lay with getting the direction of the normal wrong. I totally need a high quality numeric differentiator though. This symbolic take just won't do. I can't even get five iterations deep in a reasonable time frame, at least not with sagemath and symbolic computations. Nice surfaces though. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: SamTiba on March 21, 2017, 12:01:30 AM You were totally right, I forgot that. I get the same curves then you afterwards, but another norming really slows down the computation.
For my surface I created the tangent in x- and y-direction and created the normal with the cross-product and normed it afterwards so I got the shifting right there. Since you can multiply functions in orthogonal directions to get a 'mixture' of them you can really use this behaviour to create functions for surfaces, since they keep the same value at the boundary. In attachement a render of sin(x) * (sin(y) + cos(2*y) - cos(3*y)) and I searched for some smooth rendering options in Matlab so I got it more 3D-looking this time. Note that the left image is a view from the top on the surface itself. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 21, 2017, 12:14:12 AM a nice bubbly mess. The only problem with surfaces is that self-intersection doesn't look all too great with them. I wonder if there are some nice scalings that happen to (perhaps just barely) avoid self-penetration.
Some possible extensions might include tripling the frequency and dividing the distance by three at each step, for instance. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 21, 2017, 12:21:07 AM (http://puu.sh/uSdpv/536046b5cf.png) here is what that would look like after 4 iterations for sine
Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 22, 2017, 01:44:36 PM I think there might be one last remaining problem, depending on what exactly you are trying to do, but that one might be really hard to fix:
Really, the curve should not be displaced according to the x-coordinate's distance, but rather according to the previous iteration's curve length (rescaled into a unit interval). As of right now it's impossible (I think), to recreate the Koch curve or similar with carefully chosen piecewise-linear functions. Ideally, proper rescaling should do this perfectly. It's essentially impossible to solve problem analytically though. That will require some fancy numeric integration and, to get to higher iterations, also fancy numeric differentiation. Do you think you can do something like that, SamTiba? I'll think about it and try to code something up too. Title: Re: Iterative Sinus-Curve and the extension of 'line-curves' Post by: kram1032 on March 22, 2017, 02:08:41 PM Sorry for these multiposts but I keep gettnig "database errors" whenever I try to edit a previous post.
Here is what, assuming I got it right in principle, the Koch curve (but without taking into account the curve length) looks like: (http://i.imgur.com/y0URViC.png) Completely wrong, clearly. Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: SamTiba on March 22, 2017, 11:04:26 PM Some special signs in the titel made editing hard for the database so I took them out - it should work fine now :)
I enhanced my code and came to a lot of possible extensions that I'm still currently working on. Got back to working with arrays because my Matlab can't handle piecewise functions. Extensions im working on: We can already start with a curve not with the normal [t,0]-line. We can shift along the tangent but shift along the normal aswell, this gets interesting if we don't start with a line but a curve. I found out (also with trying to rebuild the koch- and levi-c-curve) that the actual length of the curve is more important then thought, you can't simply split along the x-axis and say you reached half of the curve. In addition to that the scaling-factor is also not the same then the number of intersections. We have to take the differ in length of each curve into account. For example for the levi c curve the scaling-factor is sqrt(2)^(-n). It's hard to say for actual curves how to scale but I guess 2^(-n) for sine just sounds too easy. Unfortunately I don't have images to present today but I will get back to that later so that also the quiet image-hungry readers are happy aswell. Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: kram1032 on March 23, 2017, 09:27:17 AM simply taking the complete curve's arc length won't be sufficient, I'm pretty sure: Not only is the overall curve longer than the initial line segment, the speed the curve is traversed with isn't uniform (using the x-coordinate to trace it). The arc length at any given moment is what you'd have to go with.
The problem is that parametrizing curves by their arc length is already impossible to do in closed form with incredibly simple curves. (the most complex curve that features a reasonably simple arc length parametrization, I think, is the helical curve) Gotta do that numerically. Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: matsoljare on March 23, 2017, 04:18:57 PM Seems like this could be used for audio as well, if you played a very high iteration version as a waveform.
Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: kram1032 on March 23, 2017, 04:37:49 PM how would you convert a 2D plot into an audio wave? Or are you talking turning a spectrogram into audio?
Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: SamTiba on March 23, 2017, 10:45:44 PM My brother told me about this one aswell because he is studying in that field.
You can take any curve as an amplitude for one period and then fasten it up, so our curve would make the 'basic shape' for what you can then hear in 100-20khz. It's similar to using a sawtooth- or squarepulse-function but more enhanced and up to date the usage is spread in the modern music market. Problem is that we could only use an amplitude so that the function has to be uniqueness. I came to that idea already with using sequences out of the mandelbrot- or julia-fractal but I didn't manage to find something where every x-value had just one and only one y-value. Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: kram1032 on March 23, 2017, 11:04:47 PM yes, that's what I meant by "how would you convert a 2D plot into an audio wave?"
I mean, there are some outs, but they don't seem that "natural" if that makes sense. You could interpret the axes in different manners. For instance you could use them as a spectrum, so then the x-axis would be time as usual but the y-axis would represent frequencies being played at the same time. Having multiple y-values would be perfectly fine under that interpretation. But doing this always feels kind of arbitrary, imo... Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: matsoljare on March 24, 2017, 03:00:09 PM You would follow the line from beginning to end and use the X or Y value as the amplitude.
Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: kram1032 on March 24, 2017, 05:50:08 PM but that's the point: You can't. There are arbitrarily many y values for each x value and if you look at the opposite order it's even worse. To interpret the curve as a simple displacement-over-time curve, it HAS to have an unambiguous amplitude.
Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: SamTiba on April 28, 2017, 11:59:18 AM I spent a bit of time with the problem now and I'm ready to present a (hopefully) right result.
The process is now the following: 1) Start: Define the underlying curve and its tangent 2) Each step: distribute the parameter according to the length of the curve to pretend it from stretching, afterwards add the intersected and scaled version to the original position and create the new tangent by rotating the old tangent by the new one (and afterwards norming it) Attached the result after 15 steps and with a depth of 100k points, also plotted the first 5 curves, where you can nicely see how the length is distributed (it passes the previous curve after equal lengths). The result shows unstretched, fractalic behaviours and cool spirals. I am stunned of the mixing of smoothness and roughness in this curve. It may look very boring but it's just the start to something and can be extended nicely. Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: kram1032 on April 28, 2017, 06:10:35 PM This looks very plausible to me. To test it, unlike before, this should work out to be exactly the same (at most directly squashed or stretched, but with the turns and intersections in the same positions, relatively) curve even if you rescale it. I.e., what's the result if your first Sine curve is normalized to lie between 0 and 1?
Without properly taking the arc length parametrization into account, that would break. Another great test is trying to replicate the Koch curve or similar with this, as I attempted before. I actually also really like the look of this new curve! Since it appears to be smooth, I'd not be surprised if its fractal dimension actually ends up being 1. It may not even tend to infinite length. - Since you are now calculating the length, can you check if it look like it converges? And what about your surface version? Does that still work with this new arc-length aware code? I'd imagine it's not quite so obvious how to actually take curve arc length over to surfaces. Perhaps preserving local area or something? Oh, and one more request, if you don't mind: I really like the version where the frequency triples each time. It looks kind of like gears. Can you try that please? Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: SamTiba on May 01, 2017, 12:30:03 PM I did a few optimizations here, applying it to the koch- and levi c curve will take me a bit, stay tuned!
I spit out the length and you are right! The length converges to something around 15.3 . Didn't think of that and it actually surprises me. The implementation on the surface version is hard, since the Dimension gets really distorted after a time and it would get even more complicated. But I would say it is still possible! Would really like to see the results but since I would have to work with arrays then (and did the surface-version with symbolic maths before) it would take a lot of time. The tripled version looks like below in the image. The change of direction near the first crossing of the blue line (first step) seems kinda odd, but you can see how it evolves. Title: Re: Iterative Sinus-Curve and the extension of line-curves Post by: kram1032 on May 01, 2017, 11:17:12 PM Nice! If you repeat that length convergence test with the Koch or Levy curve, it shouldn't do so, of course. It should keep increasing in length. In case of the Koch curve by a factor of 4/3 each time, if I have that right in my head right now. |