From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/56603 Path: news.gmane.org!not-for-mail From: James Fisher Newsgroups: gmane.comp.tex.context Subject: Re: METAPOST's superellipse with superness<0.5 does not give a superellipse Date: Mon, 1 Mar 2010 17:57:11 +0000 Message-ID: <771da05a1003010957k30a4c4c0tc4a494dbe5188618@mail.gmail.com> References: <771da05a1003010754x6638a08dnb898df3c6766cc8@mail.gmail.com> <771da05a1003010804i409db847tdfe45c7626dea6c8@mail.gmail.com> <9db72ac71003010820s7e6f8545ta7399b2c8c4e4f6b@mail.gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0105027772==" X-Trace: dough.gmane.org 1267466333 14117 80.91.229.12 (1 Mar 2010 17:58:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 1 Mar 2010 17:58:53 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Mar 01 18:58:48 2010 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from [195.12.62.10] (helo=balder.ntg.nl) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Nm9s3-0004Zi-0t for gctc-ntg-context-518@m.gmane.org; Mon, 01 Mar 2010 18:57:31 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 517D1C9DA9; Mon, 1 Mar 2010 18:57:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id pJntlqWpKVJj; Mon, 1 Mar 2010 18:57:27 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1711DC9DD5; Mon, 1 Mar 2010 18:57:27 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id A58AEC9DD5 for ; Mon, 1 Mar 2010 18:57:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id fqkk7uatfmqo for ; Mon, 1 Mar 2010 18:57:22 +0100 (CET) Original-Received: from mail-ew0-f227.google.com (mail-ew0-f227.google.com [209.85.219.227]) by balder.ntg.nl (Postfix) with ESMTP id AA85FC9DA9 for ; Mon, 1 Mar 2010 18:57:22 +0100 (CET) Original-Received: by ewy27 with SMTP id 27so150204ewy.34 for ; Mon, 01 Mar 2010 09:57:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=0+LiB0ynIIZOzJkN1P3dhI7KMcFhsZZzUaLWjSwMDBo=; b=dcvoHGEmshXRgM1rNgWnmHR5n+yUtjqcaiIu5cuQNrQ4K2I61w4SMeak0rA22VRe+d RMx+8m5ZetlCYGwcezLes/D7YNzhhXNs9iW7jCfF33R21sra7hPXmdvukTK0q6/GpG76 GqtbQXKEPVPNcgvy13ctNiO9tttJ/ZxxKoIAw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=XOBm5B6uNR1tTtfaj7F39IvoW1A5NSAKOmVGe9sbTFdx09BuqR7M5ynxCQqHbYbOXy J3TRlY6bzY05wDG3qbPWvcHQ7uJPGo5lyuRMSK+092C7NYRWErxyAm3RUjnmSaofqKNl fOR257CfC4HYhdDiswtF4tCgEBkT+fD4U7sGw= Original-Received: by 10.213.102.202 with SMTP id h10mr3282389ebo.94.1267466231808; Mon, 01 Mar 2010 09:57:11 -0800 (PST) In-Reply-To: <9db72ac71003010820s7e6f8545ta7399b2c8c4e4f6b@mail.gmail.com> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:56603 Archived-At: --===============0105027772== Content-Type: multipart/alternative; boundary=00504502ca808302380480c0fa2e --00504502ca808302380480c0fa2e Content-Type: text/plain; charset=ISO-8859-1 I've come up with a crude function that's doing more like what I want. I have two problems with it: 1. The most important: I need to differentiate the equations that generate a superellipse, in order to find the tangent at the defined vertices. I have failed to do this and so use a crude arbitrary power function. 2. Less important: what is the equivalent in METAFONT of the 'return' keyword? I just want superellipse() to return the shape, rather than draw it. James def superellipse(expr r,t,l,b,s)= pair tr, tl, bl, br; tr = (s[xpart t,xpart r],s[ypart r,ypart t]); tl = (s[xpart t,xpart l],s[ypart l,ypart t]); bl = (s[xpart b,xpart l],s[ypart l,ypart b]); br = (s[xpart b,xpart r],s[ypart r,ypart b]); numeric theta; if s > 0.5: % Behave as in the normal superellipse function theta = 0; else: % This is a crude mockup of the kind of function that is required % to generate shapes with s<0.5 (apparently called astroids). % This satisfies: % % s = 0.5, theta = 0.5 % s = 0, theta = 90 % % But to find the actual function, % we need to differentiate, at an endpoint, % the equation that would produce one quadrant of the shape. theta = 90 - (s*s*s*7.11378661); fi fill r{dir(90+theta)} ... tr{t-r} ... {dir(180-theta)}t & t{dir(180+theta)} ... tl{l-t} ... {dir(270-theta)}l & l{dir(270+theta)} ... bl{b-l} ... {dir(-theta)}b & b{dir(theta)} ... br{r-b} ... {dir(90-theta)}r & cycle; enddef; beginfig(0); superellipse( ( 100, 50 ), ( 50, 100 ), ( 0, 50 ), ( 50, 0 ), 0.6 ); endfig; end; On Mon, Mar 1, 2010 at 4:20 PM, Rory Molinari wrote: > James's explanation appears to be right. > > On p 126 of the METAFONTbook Knuth says that the "superness should be > between 0.5 (when you get a diamond) and 1.0 (when you get a square)". > > Exercise 14.6 asks the reader to "Try superellimpse with superness > values less than 0.5 or greater than 1.0; explain why you get weird > shapes in such cases." The answer is "There are inflection points, > because there are no bounding triangles for the '...' operations in > the superellipse macro ... unless 0.5 \leq s \leq 1." > > Cheers, > Rory > > On Mon, Mar 1, 2010 at 8:04 AM, James Fisher > wrote: > > I should say that the vertices of the superellipse are calculated > > correctly. The problem, it seems, is that for the vertices at right, > top, > > left, and bottom, the angles of entry and exit need to be explicitly > > defined, rather than just relying on the '...' which coincidentally works > > for s>=0.5. > > > > I should say at this point that I am no maths whiz. But, sticking with > the > > 'right ... topright ... top' line, the angle calculation needs to > satisfy, > > for the exit angle of the first vertex: > > > > For s=0, angle = 180 degrees (vector to the left) > > For s = 0.5, angle = 135 degrees (45 degrees to the top left, producing a > > straight line to create the diamond shape) > > For s>0.5, angle = 90 degrees (vector vertically upwards) > > > > Suffice to say that I don't know how to produce that elegantly. > > > > > > > > James > > > > > > On Mon, Mar 1, 2010 at 3:54 PM, James Fisher > wrote: > >> > >> Hi again, > >> > >> > >> Another METAPOST problem. For the sake of curiosity, I've been looking > at > >> and playing with the superellipse() function in plain METAPOST. This is > all > >> fine and dandy until I try values of 'superness' less than 0.5, in which > >> case it generates shapes that are seemingly not superellipses. At > s=0.5, > >> the function generates a diamond shape -- which, AFAIK, is correct. > >> However, s<0.5, the points of the diamond immediately turn to curves. > (My > >> knowledge of superellipses here is just from > >> http://en.wikipedia.org/wiki/Superellipse -- try the image at > >> http://en.wikipedia.org/wiki/File:Lame_anima.gif to see how I expect > the > >> shape to change with varying values of superness). > >> > >> Some code follows -- perhaps someone could run it and tell me if, for > >> starters, they get the same as me. (See > http://i49.tinypic.com/2ijqatl.jpg > >> for superellipse() with s=0.3). > >> > >> > >> Best, > >> > >> > >> James > >> > >> > >> > >> % The following is a superellipse function at > >> < > http://lists.foundry.supelec.fr/pipermail/metapost-commits/2008-June/000340.html > >; > >> % I think it's the superellipse function in my copy of METAPOST; it at > >> least has the same behaviour. > >> % It seems to calculate the vertices correctly, but not the way they > join > >> (try changing all ... to --). > >> % > >> %def superellipse(expr r,t,l,b,s)= > >> % r ... (s[xpart t,xpart r],s[ypart r,ypart t]){t-r} ... > >> % t ... (s[xpart t,xpart l],s[ypart l,ypart t]){l-t} ... > >> % l ... (s[xpart b,xpart l],s[ypart l,ypart b]){b-l} ... > >> % b ... (s[xpart b,xpart r],s[ypart r,ypart b]){r-b} ... cycle > >> %enddef; > >> > >> def supertest expr s = > >> superellipse( > >> ( 100, 50 ), > >> ( 50, 100 ), > >> ( 0, 50 ), > >> ( 50, 0 ), > >> s > >> ); > >> enddef; > >> > >> % These >0 supernesses are fine, I think ... > >> > >> beginfig(0); > >> draw supertest 2; > >> endfig; > >> > >> beginfig(1); > >> draw supertest 1.01; > >> endfig; > >> > >> % The following, 0.5>=superness<=1, > >> % are from visual reference definitely right > >> > >> beginfig(2); > >> draw supertest 1; > >> endfig; > >> > >> beginfig(3); > >> draw supertest 0.99; > >> endfig; > >> > >> beginfig(4); > >> draw supertest 0.7; > >> endfig; > >> > >> beginfig(5); > >> draw supertest 0.51; > >> endfig; > >> > >> beginfig(6); > >> draw supertest 0.5; > >> endfig; > >> > >> % Now, for <0.5, > >> % things get problematic -- > >> % the points in the shape generated by s=0.5 > >> % should stay 'pointy' > >> > >> beginfig(7); > >> draw supertest 0.49; > >> endfig; > >> > >> beginfig(8); > >> draw supertest 0.3; > >> endfig; > >> > >> beginfig(9); > >> draw supertest 0.01; > >> endfig; > >> > >> beginfig(10); > >> draw supertest 0; > >> endfig; > >> > >> end; > >> > > > > > > > ___________________________________________________________________________________ > > If your question is of interest to others as well, please add an entry to > > the Wiki! > > > > maillist : ntg-context@ntg.nl / > > http://www.ntg.nl/mailman/listinfo/ntg-context > > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > > archive : http://foundry.supelec.fr/projects/contextrev/ > > wiki : http://contextgarden.net > > > ___________________________________________________________________________________ > > > > > > ___________________________________________________________________________________ > If your question is of interest to others as well, please add an entry to > the Wiki! > > maillist : ntg-context@ntg.nl / > http://www.ntg.nl/mailman/listinfo/ntg-context > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : http://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > > ___________________________________________________________________________________ > --00504502ca808302380480c0fa2e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I've come up with a crude function that's doing more like what I wa= nt.=A0 I have two problems with it:

1. The most important: I need to= differentiate the equations that generate a superellipse, in order to find= the tangent at the defined vertices.=A0 I have failed to do this and so us= e a crude arbitrary power function.
2. Less important: what is the equivalent in METAFONT of the 'return= 9; keyword?=A0 I just want superellipse() to return the shape, rather than = draw it.

James

def superellipse(expr r,t,l,b,s)=3D
=A0 pai= r tr, tl, bl, br;
=A0 tr =3D (s[xpart t,xpart r],s[ypart r,ypart t]);
=A0 tl =3D (s[xpart = t,xpart l],s[ypart l,ypart t]);
=A0 bl =3D (s[xpart b,xpart l],s[ypart l= ,ypart b]);
=A0 br =3D (s[xpart b,xpart r],s[ypart r,ypart b]);
=A0 <= br>=A0 numeric theta;
=A0
=A0
=A0 if s > 0.5:
=A0=A0=A0 % Behave as in the normal s= uperellipse function
=A0=A0=A0 theta =3D 0;
=A0 else:
=A0=A0=A0 % = This is a crude mockup of the kind of function that is required
=A0=A0= =A0 % to generate shapes with s<0.5 (apparently called astroids).
=A0=A0=A0 % This satisfies:
=A0=A0=A0 %
=A0=A0=A0 %=A0=A0 s =3D 0.5,= =A0 theta =3D 0.5
=A0=A0=A0 %=A0=A0 s =3D 0,=A0=A0=A0 theta =3D 90
= =A0=A0=A0 %
=A0=A0=A0 % But to find the actual function,
=A0=A0=A0 %= we need to differentiate, at an endpoint,
=A0=A0=A0 % the equation that= would produce one quadrant of the shape.
=A0=A0=A0
=A0=A0=A0 theta =3D 90 - (s*s*s*7.11378661);
=A0 fi
=A0=
=A0 fill=A0 r{dir(90+theta)} ... tr{t-r} ... {dir(180-theta)}t &=A0=A0=A0=A0=A0=A0=A0 t{dir(180+theta)} ... tl{l-t} ... {dir(270-theta)}l= &
=A0=A0=A0=A0=A0=A0=A0 l{dir(270+theta)} ... bl{b-l} ... {dir(-the= ta)}b &
=A0=A0=A0=A0=A0=A0=A0 b{dir(theta)} ... br{r-b} ... {dir(90-theta)}r &<= br>=A0=A0=A0=A0=A0=A0=A0 cycle;
enddef;

beginfig(0);
=A0 super= ellipse(
=A0=A0=A0 ( 100, 50=A0 ),
=A0=A0=A0 ( 50,=A0 100 ),
=A0= =A0=A0 ( 0,=A0=A0 50=A0 ),
=A0=A0=A0 ( 50,=A0 0=A0=A0 ),
=A0=A0=A0 0.= 6
=A0=A0=A0 );
endfig;

end;


O= n Mon, Mar 1, 2010 at 4:20 PM, Rory Molinari <quokka@gmail.com> wrote:
James's explanation appears to be right.

On p 126 of the METAFONTbook Knuth says that the "superness should be<= br> between 0.5 (when you get a diamond) and 1.0 (when you get a square)".=

Exercise 14.6 asks the reader to "Try superellimpse with superness
values less than 0.5 or greater than 1.0; explain why you get weird
shapes in such cases." =A0The answer is "There are inflection poi= nts,
because there are no bounding triangles for the '...' operations in=
the superellipse macro ... unless 0.5 \leq s \leq 1."

Cheers,
Rory

On Mon, Mar 1, 2010 at 8:04 AM, James Fisher <jameshfisher@gmail.com> wrote:
> I should say that the vertices of the superellipse are calculated
> correctly.=A0 The problem, it seems, is that for the vertices at right= , top,
> left, and bottom, the angles of entry and exit need to be explicitly > defined, rather than just relying on the '...' which coinciden= tally works
> for s>=3D0.5.
>
> I should say at this point that I am no maths whiz.=A0 But, sticking w= ith the
> 'right ... topright ... top' line, the angle calculation needs= to satisfy,
> for the exit angle of the first vertex:
>
> For s=3D0, angle =3D 180 degrees (vector to the left)
> For s =3D 0.5, angle =3D 135 degrees (45 degrees to the top left, prod= ucing a
> straight line to create the diamond shape)
> For s>0.5, angle =3D 90 degrees (vector vertically upwards)
>
> Suffice to say that I don't know how to produce that elegantly. >
>
>
> James
>
>
> On Mon, Mar 1, 2010 at 3:54 PM, James Fisher <jameshfisher@gmail.com> wrote= :
>>
>> Hi again,
>>
>>
>> Another METAPOST problem.=A0 For the sake of curiosity, I've b= een looking at
>> and playing with the superellipse() function in plain METAPOST.=A0= This is all
>> fine and dandy until I try values of 'superness' less than= 0.5, in which
>> case it generates shapes that are seemingly not superellipses.=A0 = At s=3D0.5,
>> the function generates a diamond shape -- which, AFAIK, is correct= .
>> However, s<0.5, the points of the diamond immediately turn to c= urves.=A0 (My
>> knowledge of superellipses here is just from
>> http://en.wikipedia.org/wiki/Superellipse -- try the image at
>> http://en.wikipedia.org/wiki/File:Lame_anima.gif to see ho= w I expect the
>> shape to change with varying values of superness).
>>
>> Some code follows -- perhaps someone could run it and tell me if, = for
>> starters, they get the same as me.=A0 (See http://i49.tinypic.com/2ijqatl.jp= g
>> for superellipse() with s=3D0.3).
>>
>>
>> Best,
>>
>>
>> James
>>
>>
>>
>> % The following is a superellipse function at
>> <http://lists.foundry.supel= ec.fr/pipermail/metapost-commits/2008-June/000340.html>;
>> % I think it's the superellipse function in my copy of METAPOS= T; it at
>> least has the same behaviour.
>> % It seems to calculate the vertices correctly, but not the way th= ey join
>> (try changing all ... to --).
>> %
>> %def superellipse(expr r,t,l,b,s)=3D
>> %=A0 r ... (s[xpart t,xpart r],s[ypart r,ypart t]){t-r} ...
>> %=A0 t ... (s[xpart t,xpart l],s[ypart l,ypart t]){l-t} ...
>> %=A0 l ... (s[xpart b,xpart l],s[ypart l,ypart b]){b-l} ...
>> %=A0 b ... (s[xpart b,xpart r],s[ypart r,ypart b]){r-b} ... cycle<= br> >> %enddef;
>>
>> def supertest expr s =3D
>> =A0 superellipse(
>> =A0=A0=A0 ( 100, 50=A0 ),
>> =A0=A0=A0 ( 50,=A0 100 ),
>> =A0=A0=A0 ( 0,=A0=A0 50=A0 ),
>> =A0=A0=A0 ( 50,=A0 0=A0=A0 ),
>> =A0=A0=A0 s
>> =A0=A0=A0 );
>> enddef;
>>
>> % These >0 supernesses are fine, I think ...
>>
>> beginfig(0);
>> =A0 draw supertest 2;
>> endfig;
>>
>> beginfig(1);
>> =A0 draw supertest 1.01;
>> endfig;
>>
>> % The following, 0.5>=3Dsuperness<=3D1,
>> % are from visual reference definitely right
>>
>> beginfig(2);
>> =A0 draw supertest 1;
>> endfig;
>>
>> beginfig(3);
>> =A0 draw supertest 0.99;
>> endfig;
>>
>> beginfig(4);
>> =A0 draw supertest 0.7;
>> endfig;
>>
>> beginfig(5);
>> =A0 draw supertest 0.51;
>> endfig;
>>
>> beginfig(6);
>> =A0 draw supertest 0.5;
>> endfig;
>>
>> % Now, for <0.5,
>> % things get problematic --
>> % the points in the shape generated by s=3D0.5
>> % should stay 'pointy'
>>
>> beginfig(7);
>> =A0 draw supertest 0.49;
>> endfig;
>>
>> beginfig(8);
>> =A0 draw supertest 0.3;
>> endfig;
>>
>> beginfig(9);
>> =A0 draw supertest 0.01;
>> endfig;
>>
>> beginfig(10);
>> =A0 draw supertest 0;
>> endfig;
>>
>> end;
>>
>
>
> _____________________________________= ______________________________________________
> If your question is of interest to others as well, please add an entry= to
> the Wiki!
>
> maillist : ntg= -context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage =A0: ht= tp://www.pragma-ade.nl / http://tex.aanhet.net
> archive =A0: http://foundry.supelec.fr/projects/contextrev/
> wiki =A0 =A0 : = http://contextgarden.net
> ______________________________________________________________________= _____________
>
>
___________________________________________________________________________= ________
If your question is of interest to others as well, please add an entry to t= he Wiki!

maillist : ntg-cont= ext@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage =A0: http://= www.pragma-ade.nl / http://tex.aanhet.net
archive =A0: http://foundry.supelec.fr/projects/contextrev/
wiki =A0 =A0 : http:= //contextgarden.net
___________________________________________________________________________= ________

--00504502ca808302380480c0fa2e-- --===============0105027772== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --===============0105027772==--