Skip to content
Forum Archive

Lamé curve

51 posts

dirkdeftly#

Lamé curve

My newest mathematical project: Figuring out how to make an arbitrary Lamé curve in SSC. Lamé curves, for those who aren't UnConeD, are curves defined by the equation:
|x^n|/a+|y^n|/b=1
Initially I wanted to create the curve voted as the most aesthetically pleasing, where n=e and a/b=golden ratio. But then I realized I'd probably have to have some sort of base equation for it.
The problem is, the base equation I have uses x or y=i, and it gets all the points jumbled up in one place. Ideally I would create it with polar coordinates, but I don't know how...Any ideas?
UnConeD#
Actually I didn't know about Lamé curves either 🙂. In any case there are TONS of 'blablah curve's in math anyway, it's impossible to know them all.

A few observations, correct me if I'm wrong:

1) Since only the absolute value of x and y is used, the curve is symmetrical with respect to both the x and y axis (and the origin). So you only need to draw one quadrant and mirror it to the others.

2) The equation can be rewritten in the form y=f(x) for the first quadrant (where |x^n|=x^n and |y^n|=y^n):

|x^n|/a+|y^n|/b = 1
<=> (x^n)/a+(y^n)/b = 1
<=> (y^n)/b = 1 - (x^n)/a
<=> (y^n) = b*(1 - (x^n)/a)
<=> y = (b*(1 - (x^n)/a))^(1/n)
So you can draw it parametrically for an interval 'x'. You can also isolate 'x', and draw it parametrically for an interval 'y'. This is what I've done in the attached preset, but it looks more like a SuperEllipse to me: I'm not sure what a lamé curve is supposed to look like.
UnConeD#
I'm not sure why you want Lamé curves, but if you want something with a similar shape, you can cheat:

x=(cos(a))^n; y=(sin(a))^n;

should give you a similar, but less complicatedd to calculate, result.

You should experiment with regular polynomial shapes as well. Take for example the silhouette of the mushrooms in Whacko AVS II.

Once you've developed a little 'feeling' of how functions combine when multiplied and added, you can make really cool things (like Tie Fighters and X-Wings 😉).
Karnov#
concerning the lame' curve

yeah yeah i dunno that damn ascii

would anyone (i.e. unconed y atero) mind if i used above code in an AVS?


oh yeah

i am starting a movement to correct the only beef i have w/ the english language

the word "and" is too long
we should adopt the spanish "y"
it is 66% more effiecent 🙂
plus "and" _almost_ takes up 2 syllabes
"y" (pronounced "ee") only takes up, like, a half of syllable ;p
reply if you think i have a badass logic train going here
UnConeD#
Oh yeah while we're at it, we should start using abbreviations:

u = you
y = why
n = and

We can compress double letters into one, and skip ending vowels. I mean, everyone will understand what we're talking about right? Oh and replacing weird spellings with phonetical ones is really the way to go too:

so m shur ev1 wl undasta wh im tkin bout, n it rely s a gr8 id to sav sum tim bi typn lik diz.


NOT.
Zevensoft#
It's similar to Video Compression, the more compressed, the less bits required, but more CPU power required too, less compressed, the more bits required, but less CPU power. (Which is leveraged by the more bits required to up the required CPU power)

And back to the subject of non-circular curves, you can use a beizer, they are VERY fast.


Init:
pi=acos(-1);fov=pi*2/3;flv=tan(fov/2);n=100

Per Frame:
xp1=1;xp2=1;xp3=0;yp1=0;yp2=1;yp3=1;zp1=0;zp2=0;zp3=0;

Per Point:
z=(sqr(t)*zp1+2*(1-t)*t*zp2+sqr(1-t)*zp3);
x=(sqr(t)*xp1+2*(1-t)*t*xp2+sqr(1-t)*xp3)/(z+flv);
y=(sqr(t)*yp1+2*(1-t)*t*yp2+sqr(1-t)*yp3)/(z+flv);

There's a quarter-circle, just change the values for the (xp'n,yp'n,zp'n) to change the shape (first co-ord is one end, third co-ord is other end, and second co-ord is the apex of the containing triangle.)
UnConeD#edited
Zeven: there are of course a lot better methods for curves 😉. As I said, I don't really know why Atero wanted a Lamé/SuperEllipse, because they're kind of boring. But anyway sometimes it's fun to do something totally useless 😉

I just made a nice double cubic bezier scope... it's a single cubic bezier segment closed on itself. I also made the controlling lines visible. The only problem I see using beziers in AVS is the large amount of variables you need to store all the control points.
UnConeD#edited
I've been playing with the Béziérs a bit... I guess I didn't realise how well they work in AVS.

Here's a nice, anti-aliased bezier. Not very fast, but looks great and smooth. The sub-pixel sampling is done by additively drawing the scope with half-pixel offsets, and a final blur'n'multiply smoothens out the long stretches. If you compare it to the non-aa version you can clearly see the difference.

I also made a new avatar based on a filled in, looping bezier.
Jaheckelsafar#
When can we expect enviroment maps and photorealitisc organic models? 😛

You gonna go back and mess with that "professional renderer" scope you made before? (I lost my copy in a format a while ago, but it was pretty cool)
KeatonMill#
I suppose one of these days one of us is going to hafta write an OpenGL or Direct3D AVS type thing... I'd do it... except I've got no idea how to write a code parser.
UnConeD#
I tried making an AVS code parser a while ago... I got the basics runningn, but my code was sloppy (first time I tried a compiler) and there were a few critical bugs.

I'm going to try a flex-based compiler once I have time.
Scar Da Kookee#
mind if i took a look at it?

one thing i can do is look at code ^_^

and as for anything lame... 🙁
UnConeD#
Lol I'm not going to paste 700 lines of C code in here. 😉
The code is buggy and messy... I doubt you'd have any use for it.
dirkdeftly#
GYAH!

Umm...BACK ON TOPIC...I didn't really necessarily want to use this in a preset, but it would be cool to figure out if I could do a superegg. And I guess I should've clarified, is there any way to program it this way:
r=sin(i*tpi); (tpi=2*pi)
d=???

I know the conversion between polar and rectangular coordinates, but I don't know how I would make rectangular equations polar. The idea I had in mind was to have the points spread out equally (except for the fact that it's not a circle, but you know what I mean). That's easy - R is the same as a circle. But finding D is difficult. All I know is that when n=2, D=1. Then there's the shapes for n=0, a unit cross, and n=infinity, a unit square.

I'm too lazy to figure those out right now, cos I haven't been to the forums for a while and I'm catching up :P

--Atero
dirkdeftly#edited
WEE!! Dead post revival

So, does anyone have an answer? IS THERE NO END TO THE MADNESS?????

BTW, here is the code for a general superegg and a superegg lens (a 'glass' superegg placed upon a given texture) using movements:

d=(pow(abs(x),n)+pow(abs(y),n));
z=if(below(d,1),sqrt(1-d),0);
x=x/z; y=y/z;

For the lens you simply take the reciprocal of z (or reverse the projection):

x=x*z; y=y*z;

For integral powers, you do not need to take the absolute values of x and y for d.

n=<0 does not work. I'm also fairly sure there's a way to simplify n=2^a where a is integral. Have fun!

Edit:
Forgot to say, the movement has to be in rectangular coordinates, and cannot be made square unless you make it a dynamov (which will make it uberslow and ugly). Also, here's the code for the above mentioned 'most beautiful lame curve' as a superegg lens when viewed in a square window:

power=exp(1); phi=(1+sqrt(5))/2;
d=(pow(abs(x),power)+pow(abs(y*phi),power));
z=if(below(d,1),sqrt(1-d),0)*7;
x=x*z; y=y*z*phi;

I also fixed the general code so it's not fuxx0red no more 😉
jheriko#
Okay... I know that this is an old thread and you may have solved some of the problems but Lamé curves (which are also called Fermat curves if a=b) are of the form (x/a)^n+(y/b)^n=1, I dunno where your modulus came from, anyway, this is a locus equation and is therefore difficult to draw using a superscope, you just have to cheat by drawing the curve in each quadrant (like UnConeD said way up at the top). Anyway, Lamé curves are meant to look like curved rectangles when n is even and integral, as n tends to even infinity the curve tends towards a rectangle, for odd values of n the curve tends to infinity in the second and fourth quadrants and is undefined in the third.

What is a superegg? Is it another word for a super-ellipse (n=5/2).

The other thing I wanted to mention is finding polar co-ordinates for Lamé curves. I don't think that it is possible to create a general rational parameterisation of a Lamé curve, mainly due to the close link with Fermat's last theorem. Although you may still be able to find specific parameterisations for specific cases, or curves which are very close to Lamé curves.
dirkdeftly#
Superellipses are 2-lame' curves of n>2. Supereggs are 3-lame' surfaces of n>2. And there's no modulus in that formula, but there is the absolute value sign, which you left out:
|x/a|^n+|y/b|^n=c
And whether N is even, odd, or integral doesn't really matter. When n=inf., the shape is a rectangle, when n=0, it is a cross, when n2, it's a circle, and when n=1, it's a diamond. When 2>n>1, the shape is several circular arcs curving ******d that don't smooth at the corners. When 1>n>0.5, it is several circular arcs curving inward that 'spike' at the corners, and when n>0.5, it is several non-circular arcs curving inward that spike at the corners. Finally, when n>2, it is several non-circular arcs that smooth out at the corners.

What do you mean, 'mainly due to the close link with Fermat's last theorem?' You're being extremely vague, Jheriko
jheriko#
Okay. Modulus x in maths = |x| = absolute value in computers.. I forgot about that for a moment, sorry for the confusion. BTW it is good practice in maths to avoid |x|, it is a nasty function, it has no inverse, isn't continuitous and has a point singularity, it also is wrong in this situation, it ruins the 'n=odd' case Lamé curves.

As for my vague statement.. a curve is called rational if it can be expressed by some parameterisation x=x(t), y=y(t) where x(t) and y(t) are rational functions of t. So if you wanted to parameterise a general Lamé curve, even for natural n, you would have trouble because you'd need to solve things involving x^n+y^n, that is very hard (likely impossible due to the difficulty in solving higher degree equations in a finite number of steps). All I meant by my Fermat reference is that Lamé curves and FLT are closely related (for obvious reasons and less obvious reasons) and so it is likely that finding a general rational parameterisation could well be a similar process to finding a Fermat triple.

There is one specific example which can illustrate this:

x^2+y^2=1

We can parameterise this by finding intersection points with a line, an easy example is y=t(x+1) which goes through (0,1). You can cram this into the original equation to give:

x^2+(x+1)^2 * t^2=1

which can be solved for x to give x=-1 or x=(1-t^2)/(1+t^2), since y=t(x+1) we substitute x(t) into that to give y=2t/(1+t^2).

(Note also that if you wanted to do this with x^3+y^3=1 you would need to solve a cubic expression rather than a quadratic one. Which may result in a complex parameterisation.)

Anyway... the point is that this parameterisation can be used to find pythagorean triples and you can find the parameterisation from a formula for pythagorean triples.

If a^2+b^2=c^2 for some natural numbers a,b and c then x=a/c and y=b/c are rational numbers and (x,y) is a point on the circle x^2+y^2=1 (just a simple substitution can verify this). We can get pythagorean triples from this by multiplying x and y by any common denominator (=c). So using our parameterisation. t=y/(x+1) is rational if x and y are rational (which they are) and vice versa, so we can express t as p/q. Plug this into the circle parameterisation and we get:

x=(p^2-q^2)/(p^2+q^2)
y=2pq/(p^2+q^2)

The lowest common denominator is p^2+q^2 so this is our expression for c, so, pythagorean triples are numbers (and multiples of numbers) of the form:

a=p^2-q^2, b=2pq and c=p^2+q^2

for integers p and q.

This suggests to me that in order to find a parameterisation of the general Lamé curve you would need to do something which can equate to finding Fermat triples.

Wow, that was long. Hope it helps to clarify what I meant.

EDIT: Perhaps you now understand why I was so vague.
nixa#
Sorry Atero I dont think its possible to find polar coordinates. If you look at the polar equlation for a simple circle and do...(ill just write the math not describe):
x=sin(t);
y=cos(t);
-------
x^2=sin(t)^2;
y^2=cos(t)^2; }+
-------
x^2+y^2=sin(t)^2+cos(t)^2
-------
x^2+y^2=1;
-------
So my point is x^2=sin(t)^2;y^2=cos(t)^2 does mean that x^2+y^2=1 and x^2+y^2=1 doesnt mean that x^2=sin(t)^2;y^2=cos(t)^2 becouse you cant invers the }+ thing. So if you cant get polar coordinates for a circle you cant get them for a more complex function eather.

Damn my English sucks!
jheriko#
Myabe I'm not understanding you correctly but sin(x)^2+cos(x)^2 = 1 always. You can prove this by drawing a right angled triangle with hypontenuse 1 and an angle x and using the basic trig rules for sin and cos combined with pythagoras theorem. Since they always add up to a constant stuffing that into an SSC should just draw a straight line.
dirkdeftly#
You can also prove that sin^2 x + cos^2 x =1 by putting it in terms of a, b, and c:
(a/c)^2+(b/c)^2=1
a^2/c^2+b^2/c^2=1
(a^2+b^2)/c^2=1
a^2+b^2=c^2 (pythagorean theorem) which can be proved in a number of ways

Me and Jheriko had a chat on mIRC. Basically he's wrong and I'm right. 😛

Actually I think we got the lame' formula business straightened out, and I'm right about it (I am, as usual), but he kind of squashed my hopes about making this into an evenly spaced scope, the bastard. 😉
UnConeD#
Actually you don't need to prove cos^2(x) + sin^2(x) = 1. By definition they are the x and y coordinates of a point lying at angle 'x' on a unit circle (radius one).
nixa#
My point was that you can get normal formula of a curve from its polar formula but you cant get the polar one from a normal one becouse polar formula is actualy 2 formulas x=d*sin(r) y=d*cos(r) and the other one is y=f(x).
But if you got the effect you wanted it doesnt really mater.
jheriko#
Originally posted by Atero
You can also prove that sin^2 x + cos^2 x =1 by putting it in terms of a, b, and c:
(a/c)^2+(b/c)^2=1
a^2/c^2+b^2/c^2=1
(a^2+b^2)/c^2=1
a^2+b^2=c^2 (pythagorean theorem) which can be proved in a number of ways
Thats the same proof as mine in different words, but a clever way to do it none the less.

There probably are parameterisations of Lamé curves. Just not rational ones, and definately not simple ones to derive (like the circle example I gave), you may be able to find some on the net though.

I still disagree with your usage of the absolute value. You don't use it for a circle, or a conic or anything, especially since it ruins the curves if they are undefined in a quadrant or if they are off-centre. Assuming that something is always postive can ruin things, example:

4-6=1-3
4-6+9/4=1-3+9/2
(2-3/2)^2=(1-3/2)^2
2-3/2=1-3/2
2=1

This problem happens when you assume that the square root is always positive, which seems to be the right thing to do. i.e. |x^a| can not always be used in an equality in place of x^a since x^a can be multi-valued.

Also we were discussing n/0, heres a proof that you may like to find the flaw in (it has to do with n/0)

a=1,b=1
a=b
a^2=b^2
a^2-b^2=0
(a-b)(a+b)=0
(a+b)=0/(a-b)
a+b=0
1+1=0

There are loads of examples of division by zero not behaving as a defined value, and even behaving as though it were finite, lots of bizzare proofs, like this one, and lots of calculus and limiting functions that give bizarre results due to divisions by zero.
UnConeD#
4-6=1-3
4-6+9/4=1-3+9/2
(2-3/2)^2=(1-3/2)^2
2-3/2=1-3/2
2=1
Hmm I don't see the equality in the second line.. 🙂

a=1,b=1
a=b
a^2=b^2
a^2-b^2=0
(a-b)(a+b)=0
(a+b)=0/(a-b)
a+b=0
1+1=0
This is easy... because a=b, a-b = 0. So 0/(a-b) is undefined.