我想画一个如下所示的网格。它是一个方形网格。有些区域用蓝色阴影表示,其他区域则带有红色十字。有些边缘是蓝色的,其他边缘是红色的,但红色没有到达顶点,而是刚好到达顶点,露出了下面的细黑色网格。有些顶点是红色的,其他顶点是蓝色的。
我想我可以自己绘制底层网格,要么通过手动输入坐标和指令来通过直边链接顶点,要么使用命令grid
,我想我还应该能够绘制彩色的厚节点来覆盖它们位于其上的任何东西。但是,我不知道如何绘制“阴影”区域。
我想把这幅画添加到我正在打的同伦理论讲义中。人们用网格蓝色部分上的某个固定表达式定义一个函数,并归纳地将其扩展到整个正方形,首先是红色顶点,然后是红色边缘,最后是包含红色十字的面。
感谢您的帮助!
答案1
使用 PSTricks 只是为了好玩!其余繁琐的部分您可以自己轻松添加。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\addtopsstyle{gridstyle}{gridlabels=0pt,strokeopacity=.25}
\begin{document}
\begin{pspicture}[showgrid=top](8,8)
\multips(0,.5)(0,1){8}{%
\multips(.5,0)(1,0){8}{%
\psline[linecolor=red](6pt;-135)(6pt;45)
\psline[linecolor=red](6pt;135)(6pt;-45)}}
\pscustom
[
dimen=middle,
fillstyle=eovlines*,
fillcolor=white,
hatchcolor=blue,
linecolor=blue,
]
{
\psframe(8,8)
\pspolygon
(3,1)
(3,4)
(1,4)
(1,6)
(2,6)
(2,7)
(7,7)
(7,4)
(6,4)
(6,6)
(5,6)
(5,4)
(6,4)
(6,3)
(7,3)
(7,1)
(6,1)
(6,2)
(5,2)
(5,1)
}
\psset{linecolor=blue,nodesep=7pt}
\pscircle*(4,2){2pt}
\pscircle*(4,3){2pt}
\pcline(4,2)(4,3)
\end{pspicture}
\end{document}
更新
以下是我对 Barbara Beeton 的评论的回复:
答案2
MWE
和Asymptote
:
% topo.tex :
%
\documentclass{article}
\usepackage[inline]{asymptote}
\begin{asydef}
import patterns;
struct topoBoxPens{
pen gridPen, borderPen, outlinePen, hatchPen;
pen crossPen, redStrokePen, blueStrokePen;
pen labelPen, bgPen;
void operator init(
pen gridPen=darkblue+0.4bp
,pen borderPen=deepblue+2bp
,pen outlinePen=deepblue+1bp
,pen hatchPen=paleblue+2bp
,pen crossPen=red+1.2bp
,pen redStrokePen= deepred+3bp+opacity(0.7)
,pen blueStrokePen=deepblue+squarecap+3bp+opacity(0.7)
,pen labelPen=olive+fontsize(10pt)
,pen bgPen=paleyellow //white
){
this.gridPen = gridPen ;
this.borderPen = borderPen ;
this.outlinePen = outlinePen ;
this.hatchPen = hatchPen ;
this.crossPen = crossPen ;
this.redStrokePen = redStrokePen ;
this.blueStrokePen = blueStrokePen;
this.labelPen = labelPen ;
this.bgPen = bgPen ;
}
}
struct topoBox{
int n;
real cellWidth;
topoBoxPens Pens;
pair ll, ur;
int[][] mask;
real dc;
pair[] redDots;
pair[] blueDots;
guide[] redStrokes;
guide[] blueStrokes;
void drawGrid(){
for(int i=0;i<n;++i){
draw((0,i)*cellWidth--(n,i)*cellWidth,Pens.gridPen);
draw((i,0)*cellWidth--(i,n)*cellWidth,Pens.gridPen);
}
}
void drawGridLabels(){
for(int i=0;i<n;++i){
label("$"+string(n-i)+"$",(0,i+0.5)*cellWidth,W,Pens.labelPen);
label("$"+string(n-i)+"$",(n,i+0.5)*cellWidth,E,Pens.labelPen);
label("$"+string(i+1)+"$",(i+0.5,0)*cellWidth,S,Pens.labelPen);
label("$"+string(i+1)+"$",(i+0.5,n)*cellWidth,N,Pens.labelPen);
}
}
void drawBorder(){
draw(box(ll,ur),Pens.borderPen);
}
void drawHatch(){
add("hatch",hatch(2mm,Pens.hatchPen));
fill(box(ll,ur),pattern("hatch"));
}
guide[] xcross(transform t){
return t*((-dc,-dc)--(dc,dc))
^^(t*((dc,-dc)--(-dc,dc)));
}
void drawMask(){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
if(mask[i][j]==1){
filldraw(
box((j,n-i-1)*cellWidth,(j+1,n-i)*cellWidth)
,Pens.bgPen,Pens.gridPen
);
}
}
}
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
if(mask[i][j]==1){
draw(xcross(shift(j+0.5,n-i-0.5)),Pens.crossPen);
}
}
}
}
void drawOutline(){
for(int i=1;i<n-1;++i){
for(int j=1;j<n-1;++j){
if(mask[i][j]==1 && mask[i-1][j]==0){
draw((j,n-i)--(j+1,n-i),Pens.outlinePen);
}
if(mask[i][j]==1 && mask[i+1][j]==0){
draw((j,n-i-1)--(j+1,n-i-1),Pens.outlinePen);
}
if(mask[i][j]==1 && mask[i][j-1]==0){
draw((j,n-i)--(j,n-i-1),Pens.outlinePen);
}
if(mask[i][j]==1 && mask[i][j+1]==0){
draw((j+1,n-i)--(j+1,n-i-1),Pens.outlinePen);
}
}
}
}
void drawDots(){
for(int i=0;i<redDots.length;++i){
fill(circle((redDots[i].x,n-redDots[i].y),2dc),Pens.redStrokePen);
}
for(int i=0;i<blueDots.length;++i){
fill(circle((blueDots[i].x,n-blueDots[i].y),2dc),Pens.blueStrokePen);
}
}
void drawStrokes(){
for(int i=0;i<redStrokes.length;++i){
draw(reflect((0,n/2),(n,n/2))*subpath(redStrokes[i],0.2,0.8),Pens.redStrokePen);
}
for(int i=0;i<blueStrokes.length;++i){
draw(reflect((0,n/2),(n,n/2))*subpath(blueStrokes[i],0,1),Pens.blueStrokePen);
}
}
void draw(){
drawGrid();
drawGridLabels();
drawHatch();
drawMask();
drawDots();
drawStrokes();
drawOutline();
drawBorder();
}
void copyMask(int[][]mask){
for(int i=0;i<n;++i){
if(mask.initialized(i)){
for(int j=0;j<n;++j){
if(mask[i].initialized(j)){
this.mask[i][j]=mask[i][j];
}
}
}
}
}
void operator init(
int n=8
,int[][] mask
,pair[] redDots
,pair[] blueDots
,guide[] redStrokes
,guide[] blueStrokes
,real cellWidth=1
,topoBoxPens Pens=topoBoxPens()
){
assert(n>1);
this.n=n;
this.mask=array(n,array(n,0));
copyMask(mask);
this.redDots = copy(redDots );
this.blueDots = copy(blueDots);
this.redStrokes = copy(redStrokes);
this.blueStrokes = copy(blueStrokes);
this.Pens=Pens;
this.cellWidth=cellWidth;
this.ll=(0,0);
this.ur=(n,n)*cellWidth;
this.dc=0.0618cellWidth;
}
}
\end{asydef}
%
\usepackage{lmodern}
\begin{document}
\begin{figure}
\begin{asy}
settings.outformat="pdf";
size(200);
topoBox tb=topoBox(
mask=new int[][]{
array(8,0),
new int[]{0,0,1,1,1,1,1,},
new int[]{0,1,1,1,1,0,1,},
new int[]{0,1,1,1,1,0,1,},
new int[]{0,0,0,1,1,1,},
new int[]{0,0,0,1,1,1,1,},
new int[]{0,0,0,1,1,0,1,},
}
,redDots=new pair[]{(3,2),(4,3),(4,4),(5,5)}
,blueDots=new pair[]{(2,3),(3,3),(4,2),(4,5),(4,6)}
,redStrokes=new guide[]{
(2,2)--(3,2)
,(3,2)--(4,2)
,(4,2)--(5,2)
,(6,2)--(7,2)
,(1,3)--(2,3)
,(3,3)--(4,3)
,(4,3)--(5,3)
,(6,3)--(7,3)
,(3,4)--(4,4)
,(4,4)--(5,4)
,(4,5)--(5,5)
,(5,5)--(6,5)
,(6,6)--(7,6)
,(2,2)--(2,3)
,(2,3)--(2,4)
,(3,1)--(3,2)
,(3,2)--(3,3)
,(3,3)--(3,4)
,(4,2)--(4,3)
,(4,3)--(4,4)
,(4,4)--(4,5)
,(4,6)--(4,7)
,(5,1)--(5,2)
,(5,4)--(5,5)
,(5,5)--(5,6)
,(6,1)--(6,2)
,(6,5)--(6,6)
}
,blueStrokes=new guide[]{
(4,1)--(4,2)
,(4,5)--(4,6)
,(2,3)--(3,3)
,(3,5)--(4,5)
,(3,6)--(4,6)
,(4,6)--(5,6)
}
);
tb.draw();
\end{asy}
\end{figure}
\end{document}
%
% Process:
%
% pdflatex topo.tex
% asy topo-*.asy
% pdflatex topo.tex