Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to define a point when I have two paths such as:

beginfig(1);
  u := 1cm;
  path p[];
  p0 := (1u,3u)--(2u,2u);
  p1 := (2u,0)--(3u,2u);
  for i=p0,p1: draw i; endfor;
endfig;
end

so that if continuing p0 to the p1, the wanted point would be there.

enter image description here

I've tried the dir* commands, but all the examples I've found seem to either be overly complex for my understanding, or use them in curve definitions.

share|improve this question
    
Where should the point be? Can you be more precise? Did you see the direction operator? Section 9.2 of the Metapost manual. –  egreg Jan 14 '13 at 18:13
    
@egreg: yes, that was actually exactly the part I was referring to with "overly complex for me"; I tried to use the example z[i]-(x[i+1],0) = whatever*direction t[i] of fun; as a basis: z0 = whatever*direction p0 of p1;, but that gave me Not implemented: postcontrol(path)of(path).. The manual says that the first argument should be numeric, but I don't know how to extract the direction of the path as a numeric. –  morbusg Jan 14 '13 at 19:29
add comment

2 Answers

up vote 5 down vote accepted

Is this what you're after? The whatever command represents an arbitrary point along the line that connects the two points given as args so that z5 = whatever[z1,z2]=whatever[z3,z4]; solves the resulting equations and produces the point where the lines would intersect.

enter image description here

beginfig(1);
  u := 1cm;
  z1=(1u,3u);
  z2=(2u,2u);
  z3=(2u,0);
  z4=(3u,2u);
  draw z1--z2;
  draw z3--z4;
  z5 = whatever[z1,z2]=whatever[z3,z4];
  dotlabel.lrt("z5",z5);
endfig;
end
share|improve this answer
    
Yes! This works nicely as well, thank you! I was hoping something to which I could give paths, but I think I can work around that. –  morbusg Jan 14 '13 at 19:31
    
Ah, sorry looks like I didn't read the title very well. I don't know Metapost very well so I'm not sure if there's an analogous construction for paths. –  Scott H. Jan 14 '13 at 20:25
    
It looks like using your answer as a def works on paths just fine: secondarydef p on q = whatever[point 0 of p,point 1 of p]=whatever[point 0 of q,point 1 of q] enddef; , after which z5 = p0 on p1; yields the point. Nice, thanks again! :-) –  morbusg Jan 14 '13 at 21:03
add comment
beginfig(1);
  u := 1cm;
  path p[];
  p0 := (1u,3u)..(.5u,2u)..(u,u);
  p1 := (2u,0)--(3u,2u);
  for i=p0,p1: draw i; endfor;
  z1-(u,u)=100*direction infinity of p0;
  z2-(u,u)=-100*direction infinity of p0;
  p2 := z1--z2;
  pickup pencircle scaled 4pt;
  drawdot p1 intersectionpoint p2;
endfig;
end

direction requires a "time"; since p0 is an open path, the point at time infinity is the terminal point. So I compute two points on the tangent line and define the tangent as a path, finding where it intersects the path p1.

enter image description here

Here is your original picture:

beginfig(1);
  u := 1cm;
  path p[];
  p0 := (1u,3u)--(2u,2u);
  p1 := (2u,0)--(3u,2u);
  for i=p0,p1: draw i; endfor;
  z1-(2u,2u)=100*direction infinity of p0;
  z2-(2u,2u)=-100*direction infinity of p0;
  p2 := z1--z2;
  pickup pencircle scaled 4pt;
  drawdot p1 intersectionpoint p2;
endfig;
end

enter image description here

share|improve this answer
    
Thanks, this is nice since it works on curves. Could you tell me what is the multiplier 100 for the direction? –  morbusg Jan 15 '13 at 10:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.