混合切割{后,前}保持全圆的线条

混合切割{后,前}保持全圆的线条

我有一个非常简单的代码来从由三个点组成的两个向量中获取角度,使用cutaftercutbefore

vardef arc(expr o,a,b) = 
  path c, d, e ;
  c = fullcircle scaled u shifted o ;
  d = c cutafter  (b -- o) -- o -- cycle ;
  e = d cutbefore (a -- o) -- o -- cycle ;
  e
enddef ;

它几乎可以完成以下工作:

在此处输入图片描述

正如您在上一张图片中看到的,有一个小问题。宏中使用的origin和之间point 0的彩色线条。fullcircle

我怎样才能摆脱它?

这是 mwe,按照 mickep 的要求,

path c ;
c = fullcircle scaled u xscaled 2 yscaled 2 ;
draw c withcolor lightgray ;
z[0] = point 1 of c;
z[1] = point 2 of c;
z[2] = point 4 of c;
z[3] = point -2 of c;

path arcs[] ;
arcs[0] = arc(origin,z0,z3) ;
arcs[1] = arc(origin,z0,z2) ;
arcs[2] = arc(origin,z0,z1) ;

fill arcs[0] scaled  1 withcolor .50[white,blue]  withpen pencircle scaled 0pt;
draw arcs[0] scaled  1 withcolor .75[white,blue]  withpen pencircle scaled .25pt ;
fill arcs[1] scaled .8 withcolor .50[white,green] withpen pencircle scaled 0pt;
draw arcs[1] scaled .8 withcolor .75[white,green] withpen pencircle scaled .25pt ;
fill arcs[2] scaled .6 withcolor .50[white,red]   withpen pencircle scaled 0pt;
draw arcs[2] scaled .6 withcolor .75[white,red]   withpen pencircle scaled .25pt ;

draw (origin -- z[0]) ;
draw (origin -- z[1]) ;
draw (origin -- z[2]) ;
draw (origin -- z[3]) ;

其结果如下:

在此处输入图片描述

答案1

我认为您想要做的是同时剪切前后两个图。我在下面的示例中绘制了临时图表来展示它们的外观。在我看来,您想要的是f(蓝色的)而不是e(黄色的),但我可能误解了您的问题。

\startMPpage[offset=1dk]
u:=4cm ;

vardef arc(expr o,a,b) = 
  save c, d, e, f ;
  path c, d, e, f ;
  c = fullcircle scaled u shifted o ;
  draw c withpen pencircle scaled 7 withcolor red ;
  d = c cutafter  (b -- o) -- o -- cycle ;
  draw d withpen pencircle scaled 5 withcolor green ;
  e = d cutbefore (a -- o) -- o -- cycle ;
  draw e withpen pencircle scaled 3 withcolor yellow ;
  f = (c cutafter (b -- o) cutbefore (a -- o)) -- o --cycle ;
  draw f withpen pencircle scaled 1 withcolor blue ;
  f
enddef ;

path c ;
c = fullcircle scaled 2u ;% xscaled 2 yscaled 2 ;
z[0] = point 1 of c;
z[3] = point -2 of c;

draw arc(origin,z0,z3) withpen pencircle scaled 0.5 withcolor 0.5[blue,white] ;

\stopMPpage

圆的部分

答案2

这是一个更简单的版本,arc(o, a, b)它可以避免任何局部变量,并使用旋转来避免cutbefore

vardef arc(expr o, a, b) =  % arc from a to b (produced) centred at o
  (fullcircle rotated angle (a-o) 
              cutafter (origin -- unitvector(b-o))
  ) scaled 2 length (a-o) shifted o
  enddef;

相关内容