1
\documentclass[border=10pt,pstricks,12pt]{standalone}
\begin{document}
    \begin{pspicture}[showgrid](0,0)(3,3)
    \pscircle*[linecolor=gray!20](1.5,1.5){1.5}
    \pscircle[fillstyle=crosshatch*](1,2){1}
    \pscircle[hatchcolor=gray,hatchsep=5pt,hatchwidth=.5pt,fillstyle=dots*](2,1){1}
    \end{pspicture}
\end{document}

enter image description here

TikZ has option named crosshatch dots, Asymptote has the same as TikZ, hatch(1.5mm,dotted+...). It means that dotted in line

As I see, the output image is not very good! So, how can I do to add dotted in line for vlines,hlines,crosshatch,... in PSTricks?

I am drawing this picture with Asymptote but I have the mistake as follow:

// asy -f pdf <name>.asy
import math;
import patterns;

unitsize(1cm);
defaultpen(1);
pair C1=(-3,0),C2=(2.5,0);
real r=4;
path EllipseA=scale(.75,.55)*circle(C1,r);
path EllipseB=scale(.5,.35)*circle(C2,r);

add("fillA",hatch(1.5mm,red));
add("AinterB",crosshatch(2mm,green));
add("fillB",hatch(1.5mm,dotted+blue+1.5bp));//

fill(EllipseA,pattern("fillA"));
fill(EllipseB,pattern("fillB"));

picture AinterB;
fill(AinterB,EllipseA,white);
fill(AinterB,EllipseA,pattern("AinterB"));
clip(AinterB,EllipseB);
add(AinterB);

draw(EllipseA^^EllipseB); 
label("$C$",C1,dir(180),UnFill);
label("$D$",C2,UnFill);
label("$E$",(0,0),UnFill);

pair A=point(EllipseA,1.25),B=point(EllipseB,.5);
label("$A$",A,6N);
label("$B$",shift(.2,0)*B,6N);
label("$G$",(0,2),9N); // dot((0,1));

draw(A--shift(0,.6)*A);
draw(B--shift(.2,.7)*B);
draw(shift(-2.5,.75)*(0,1)--shift(-.5,2)*(0,1));
draw(shift(.2,0)*(0,1)--shift(0,2)*(0,1));
draw(shift(1.5,0)*(0,1)--shift(.5,2)*(0,1));

add(shift(-6,-3)*grid(10,7,1bp+dotted));
shipout(bbox(5mm,white));

enter image description here

See add("fillB",hatch(1.5mm,dotted+blue+1.5bp));//, if I replace 1.5mm by 1.2, I get the same output; if I replace 1.5mm by 1.75mm or 2mm, I have the true output as follow:

enter image description here

So, why are they different? It is the function in Asymptote or ...

3 Answers 3

2

About the strange behavior of Asymptote

It seems that there is a bug with Asymptote. I think it is a periodicity problem under some conditions between the parameter of hatch and dotted. The behavior is to clip a dotted line and then by tiling and clipping to add the pattern. But I do not know why such a problem does not occur with simple line pattern. Here a workaround. It is sufficient to define a new pen like dotted pen but with adding an offset : pen mdotted=linetype(new real[] {0,4},offset=.5);

import math;
import patterns;

unitsize(1cm);
defaultpen(1);
pair C1=(-3,0),C2=(2.5,0);
real r=4;
path EllipseA=scale(.75,.55)*circle(C1,r);
path EllipseB=scale(.5,.35)*circle(C2,r);

add("fillA",hatch(1.5mm,red));
add("AinterB",crosshatch(2mm,green));
pen mdotted=linetype(new real[] {0,4},offset=.5);
add("fillB",hatch(1.5mm,mdotted+blue+1.5bp));//

fill(EllipseA,pattern("fillA"));
fill(EllipseB,pattern("fillB"));

picture AinterB;
fill(AinterB,EllipseA,white);
fill(AinterB,EllipseA,pattern("AinterB"));
clip(AinterB,EllipseB);
add(AinterB);

draw(EllipseA^^EllipseB); 
label("$C$",C1,dir(180),UnFill);
label("$D$",C2,UnFill);
label("$E$",(0,0),UnFill);

pair A=point(EllipseA,1.25),B=point(EllipseB,.5);
label("$A$",A,6N);
label("$B$",shift(.2,0)*B,6N);
label("$G$",(0,2),9N); // dot((0,1));

draw(A--shift(0,.6)*A);
draw(B--shift(.2,.7)*B);
draw(shift(-2.5,.75)*(0,1)--shift(-.5,2)*(0,1));
draw(shift(.2,0)*(0,1)--shift(0,2)*(0,1));
draw(shift(1.5,0)*(0,1)--shift(.5,2)*(0,1));

add(shift(-6,-3)*grid(10,7,1bp+dotted));
shipout(bbox(5mm,white));

and the result

enter image description here

I add an issue https://github.com/vectorgraphics/asymptote/issues/133

2
  • While waiting for ..., your answer is accepted. Asymptote is my main problem. Thanks.
    – user197952
    Dec 12, 2019 at 12:55
  • @justonly : thanks for finding this bug
    – O.G.
    Dec 12, 2019 at 14:42
3

To use a dotted pen in a PostScript fill pattern, one needs to disable Asymptote's automatic scaling to the pen width and its line length adjustment:

import patterns;
unitsize(1cm); 
pen dotted=linetype(new real[] {0,4},offset=1,scale=false,adjust=false);

add("fillA",hatch(1.5mm,red+1.5bp+opacity(0.5)));
add("fillB",hatch(1.5mm,blue+1.5bp+dotted));

fill(unitcircle,pattern("fillA"));
fill(unitcircle,pattern("fillB"));

enter image description here

2

I cannot see any problem with PSTricks. Up-to-date TeXLive:

enter image description here

It looks like a problem with your viewer. Do you view the dvi output?

4
  • Yes, it looks like a problem with my TexStudio. I run it by TexStudio (latex-dvips-ps2pdf -dNOSAFER <name>.ps <name>.pdf) and the output of it as displayed. However, the pdf file is no problem. Thanks.
    – user197952
    Dec 10, 2019 at 3:19
  • You used the internal viewer of TeXstudio? If yes, then change the configuration to use an external viewer.
    – user187802
    Dec 10, 2019 at 8:08
  • Oh, I see ah. Done!
    – user197952
    Dec 10, 2019 at 8:21
  • For Windows you should use Sumatra PDF for the external viewer. It is much more faster than Adobe
    – user187802
    Dec 10, 2019 at 9:45

You must log in to answer this question.