ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Metapost - Seems like weird behavior. Is it a bug?
@ 2009-11-25  4:45 Curiouslearn
  2009-11-25  7:13 ` luigi scarso
  0 siblings, 1 reply; 6+ messages in thread
From: Curiouslearn @ 2009-11-25  4:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

The code below shows a cyclic path that I am interested in creating
(it is in red if you run the code). The example works fine as long as
I have, u:=1cm, as in the code below. But if I replace it by ,
u:=0.6cm, there is no output. There is an error saying that paths 4
and 3 do not intersect. Is this a bug?

Thanks for your help.

\setuppapersize[letter][letter]
\setuplayout[leftedge=0in,leftmargin=1in,leftmargindistance=0in,rightmargin=1in,rightmargindistance=0in,rightedge=0in,leftedgedistance=0in,rightedgedistance=0in,topspace=0.5in,width=6.5in,height=10in]

\setupcolors[state=start]


\starttext

\startuseMPgraphic{buildS22}
	numeric u;
	u := 1cm;
	w:= 2pt;
	path xaxis; path yaxis;
	xaxis := (0,0)--(12,0) scaled u;
	yaxis := (0,0)--(0,12) scaled u;
	path stLine;
	path Curve;
	stLine :=
			function (1,"x","10-x",0,10,1) scaled u;
	Curve :=
			function(1,"x","2+8/x",1,10,0.1) scaled u;
	drawarrow xaxis withpen pencircle scaled w;
	drawarrow yaxis	withpen pencircle scaled w;	
	draw stLine withpen pencircle scaled w withcolor 0.5red;
	draw Curve withpen pencircle scaled w withcolor 0.5green;
	pair Lint[];
	Lint[1]:=yaxis intersectionpoint stLine;
	Lint[2]:=stLine intersectionpoint Curve;
	Lint[3]:=reverse stLine intersectionpoint Curve;
	Lint[4]:=stLine intersectionpoint xaxis;
	path cyclicPath;
	cyclicPath := buildcycle(Lint[1]--Lint[2],Curve,Lint[3]--Lint[4],reverse
xaxis,yaxis);
	draw cyclicPath withpen pencircle scaled 5pt withcolor red;
\stopuseMPgraphic
\useMPgraphic{buildS22}

\stoptext
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost - Seems like weird behavior. Is it a bug?
  2009-11-25  4:45 Metapost - Seems like weird behavior. Is it a bug? Curiouslearn
@ 2009-11-25  7:13 ` luigi scarso
  2009-11-25  7:41   ` Taco Hoekwater
  0 siblings, 1 reply; 6+ messages in thread
From: luigi scarso @ 2009-11-25  7:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Wed, Nov 25, 2009 at 5:45 AM, Curiouslearn <curiouslearn@gmail.com> wrote:
> The code below shows a cyclic path that I am interested in creating
> (it is in red if you run the code). The example works fine as long as
> I have, u:=1cm, as in the code below. But if I replace it by ,
> u:=0.6cm, there is no output. There is an error saying that paths 4
> and 3 do not intersect. Is this a bug?
>
> Thanks for your help.
>
> \setuppapersize[letter][letter]
> \setuplayout[leftedge=0in,leftmargin=1in,leftmargindistance=0in,rightmargin=1in,rightmargindistance=0in,rightedge=0in,leftedgedistance=0in,rightedgedistance=0in,topspace=0.5in,width=6.5in,height=10in]
>
> \setupcolors[state=start]
>
>
> \starttext
>
> \startuseMPgraphic{buildS22}
>        numeric u;
>        u := 1cm;
>        w:= 2pt;
>        path xaxis; path yaxis;
>        xaxis := (0,0)--(12,0) scaled u;
>        yaxis := (0,0)--(0,12) scaled u;
>        path stLine;
>        path Curve;
>        stLine :=
>                        function (1,"x","10-x",0,10,1) scaled u;
>        Curve :=
>                        function(1,"x","2+8/x",1,10,0.1) scaled u;
>        drawarrow xaxis withpen pencircle scaled w;
>        drawarrow yaxis withpen pencircle scaled w;
>        draw stLine withpen pencircle scaled w withcolor 0.5red;
>        draw Curve withpen pencircle scaled w withcolor 0.5green;
>        pair Lint[];
>        Lint[1]:=yaxis intersectionpoint stLine;
>        Lint[2]:=stLine intersectionpoint Curve;
>        Lint[3]:=reverse stLine intersectionpoint Curve;
>        Lint[4]:=stLine intersectionpoint xaxis;
>        path cyclicPath;
>        cyclicPath := buildcycle(Lint[1]--Lint[2],Curve,Lint[3]--Lint[4],reverse
> xaxis,yaxis);
>        draw cyclicPath withpen pencircle scaled 5pt withcolor red;
> \stopuseMPgraphic
> \useMPgraphic{buildS22}
>
> \stoptext
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>
hm..
can you try  with
  tracingall;
  cyclicPath :=
buildcycle(Lint[1]--Lint[2],Curve,Lint[3]--Lint[4],reverse
xaxis,yaxis);

?
-- 
luigi
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost - Seems like weird behavior. Is it a bug?
  2009-11-25  7:13 ` luigi scarso
@ 2009-11-25  7:41   ` Taco Hoekwater
  2009-11-25  7:47     ` Taco Hoekwater
  0 siblings, 1 reply; 6+ messages in thread
From: Taco Hoekwater @ 2009-11-25  7:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users

luigi scarso wrote:
> On Wed, Nov 25, 2009 at 5:45 AM, Curiouslearn <curiouslearn@gmail.com> wrote:
>> The code below shows a cyclic path that I am interested in creating
>> (it is in red if you run the code). The example works fine as long as
>> I have, u:=1cm, as in the code below. But if I replace it by ,
>> u:=0.6cm, there is no output. There is an error saying that paths 4
>> and 3 do not intersect. Is this a bug?

More a 'known limitation': intersection point calculations are not
perfect because of the fixed precision calculus.

Lint[4] is the culprit. With u=0.6cm it has these coordinates:
(170.07976,0.00014). Notice how the y coordinate is not actually
on the xaxis? That is because the actual intersection between
stLine and xaxis does not fit nicely into a scaled pair, so
metapost takes the 'closest approximation', which in this case
is slightly off both lines.

The solution is to add an explicit fix to Lint[4] just after its
current assignment:

	Lint[4]:=(xpart Lint[4], 0);

This is not pretty, and one of the problems we hope to solve
with metapost 2.0.

Best wishes,
Taco
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost - Seems like weird behavior. Is it a bug?
  2009-11-25  7:41   ` Taco Hoekwater
@ 2009-11-25  7:47     ` Taco Hoekwater
  2009-11-25 16:24       ` Curiouslearn
  0 siblings, 1 reply; 6+ messages in thread
From: Taco Hoekwater @ 2009-11-25  7:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Taco Hoekwater wrote:
> 
> The solution is to add an explicit fix to Lint[4] just after its
> current assignment:
> 
>     Lint[4]:=(xpart Lint[4], 0);

Even better is to not use intersectionpoint at all: use
intersectiontimes instead. With that, you can select a point
that is guaranteed to be on one of the two paths.

Best wishes,
Taco
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost - Seems like weird behavior. Is it a bug?
  2009-11-25  7:47     ` Taco Hoekwater
@ 2009-11-25 16:24       ` Curiouslearn
  2009-11-25 16:58         ` Taco Hoekwater
  0 siblings, 1 reply; 6+ messages in thread
From: Curiouslearn @ 2009-11-25 16:24 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Taco, thanks for the suggestions. I will try using intersectiontimes.
It would be great if, as you said, this is solved with Metapost 2.0.

Any idea when that version is coming out?

Thanks.

On Wed, Nov 25, 2009 at 2:47 AM, Taco Hoekwater <taco@elvenkind.com> wrote:
> Taco Hoekwater wrote:
>>
>> The solution is to add an explicit fix to Lint[4] just after its
>> current assignment:
>>
>>    Lint[4]:=(xpart Lint[4], 0);
>
> Even better is to not use intersectionpoint at all: use
> intersectiontimes instead. With that, you can select a point
> that is guaranteed to be on one of the two paths.
>
> Best wishes,
> Taco
> ___________________________________________________________________________________
> 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost - Seems like weird behavior. Is it a bug?
  2009-11-25 16:24       ` Curiouslearn
@ 2009-11-25 16:58         ` Taco Hoekwater
  0 siblings, 0 replies; 6+ messages in thread
From: Taco Hoekwater @ 2009-11-25 16:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Curiouslearn wrote:
> Taco, thanks for the suggestions. I will try using intersectiontimes.
> It would be great if, as you said, this is solved with Metapost 2.0.
> 
> Any idea when that version is coming out?

Next summer
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-11-25 16:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-25  4:45 Metapost - Seems like weird behavior. Is it a bug? Curiouslearn
2009-11-25  7:13 ` luigi scarso
2009-11-25  7:41   ` Taco Hoekwater
2009-11-25  7:47     ` Taco Hoekwater
2009-11-25 16:24       ` Curiouslearn
2009-11-25 16:58         ` Taco Hoekwater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).