Naming intersection points of a grid
Clash Royale CLAN TAG#URR8PPP
Is it possible to automatically give names to all intersection points of a grid, so that I can draw from a specific intersection to another.
In my example, I manually gave names to the coordinates of some intersection points to illustrate my point.
So I want to draw from intersection a to intersection b, not from position (1,1) to (2,2); and from intersection x to intersection z, not from position (3,3) to (4,3)
Can this be done without using an extra package, because I can not install new packages (on my workplace computer) for security reasons.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
draw[step=.5cm,color=gray] (0,0) grid (8,8);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)(a)a;
node at (2,2)(b)b;
node at (3,3)(x)x;
node at (4,3)(z)z;
endtikzpicture
endcenter
endframe
enddocument
tikz-pgf
add a comment |
Is it possible to automatically give names to all intersection points of a grid, so that I can draw from a specific intersection to another.
In my example, I manually gave names to the coordinates of some intersection points to illustrate my point.
So I want to draw from intersection a to intersection b, not from position (1,1) to (2,2); and from intersection x to intersection z, not from position (3,3) to (4,3)
Can this be done without using an extra package, because I can not install new packages (on my workplace computer) for security reasons.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
draw[step=.5cm,color=gray] (0,0) grid (8,8);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)(a)a;
node at (2,2)(b)b;
node at (3,3)(x)x;
node at (4,3)(z)z;
endtikzpicture
endcenter
endframe
enddocument
tikz-pgf
@marmot Thank you for your comment, but I do not want to change the x/y scaling. This is an MWE not the whole drawing. There are other drawings in other intersections.
– Hany
Jan 15 at 8:15
add a comment |
Is it possible to automatically give names to all intersection points of a grid, so that I can draw from a specific intersection to another.
In my example, I manually gave names to the coordinates of some intersection points to illustrate my point.
So I want to draw from intersection a to intersection b, not from position (1,1) to (2,2); and from intersection x to intersection z, not from position (3,3) to (4,3)
Can this be done without using an extra package, because I can not install new packages (on my workplace computer) for security reasons.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
draw[step=.5cm,color=gray] (0,0) grid (8,8);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)(a)a;
node at (2,2)(b)b;
node at (3,3)(x)x;
node at (4,3)(z)z;
endtikzpicture
endcenter
endframe
enddocument
tikz-pgf
Is it possible to automatically give names to all intersection points of a grid, so that I can draw from a specific intersection to another.
In my example, I manually gave names to the coordinates of some intersection points to illustrate my point.
So I want to draw from intersection a to intersection b, not from position (1,1) to (2,2); and from intersection x to intersection z, not from position (3,3) to (4,3)
Can this be done without using an extra package, because I can not install new packages (on my workplace computer) for security reasons.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
draw[step=.5cm,color=gray] (0,0) grid (8,8);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)(a)a;
node at (2,2)(b)b;
node at (3,3)(x)x;
node at (4,3)(z)z;
endtikzpicture
endcenter
endframe
enddocument
tikz-pgf
tikz-pgf
edited Jan 15 at 13:53
Hany
asked Jan 15 at 8:04
HanyHany
1,146416
1,146416
@marmot Thank you for your comment, but I do not want to change the x/y scaling. This is an MWE not the whole drawing. There are other drawings in other intersections.
– Hany
Jan 15 at 8:15
add a comment |
@marmot Thank you for your comment, but I do not want to change the x/y scaling. This is an MWE not the whole drawing. There are other drawings in other intersections.
– Hany
Jan 15 at 8:15
@marmot Thank you for your comment, but I do not want to change the x/y scaling. This is an MWE not the whole drawing. There are other drawings in other intersections.
– Hany
Jan 15 at 8:15
@marmot Thank you for your comment, but I do not want to change the x/y scaling. This is an MWE not the whole drawing. There are other drawings in other intersections.
– Hany
Jan 15 at 8:15
add a comment |
3 Answers
3
active
oldest
votes
Second try at it. I hope I understood you: what I am doing here is building the grid by hand, and automatically naming the intersections. You can change the grid parameters (x and y step) and let everything else untouched; the intersections are called g-<column>-<row>
.
Another possibility is to use a TikZ matrix of nodes
for this.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
% draw[step=.5cm,color=gray] (0,0) grid (8,8);
defmystepx0.8cm
defmystepy0.5cm
foreach x in 0,...,8
% draw rows and columns
draw [red] (x*mystepx, 0) -- (x*mystepx,8*mystepy);
draw [blue] (0,x*mystepy) -- (8*mystepx,x*mystepy);
foreach y in 0,...,8
coordinate (g-x-y) at (x*mystepx,y*mystepy);
%
node at (g-1-1)a;
node at (g-2-2)b;
node at (g-3-3)x;
node at (g-4-3)z;
draw<2->[ultra thick, green, -latex] (g-1-1) -- (g-2-2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (g-3-3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (g-4-3);
endtikzpicture
endcenter
endframe
enddocument
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
Trying again...
– Rmano
Jan 15 at 16:43
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
add a comment |
If you remove the units from the steps and do, say, begintikzpicture[x=2cm,y=2cm]
this will increase the step of the grid while keeping the same intersections (or lattice nodes) connected.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture[x=2cm,y=2cm]
draw[step=.5,color=gray] (0,0) grid (5,4);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)a;
node at (2,2)b;
node at (3,3)x;
node at (4,3)z;
endtikzpicture
endcenter
endframe
enddocument
add a comment |
Here is an example of to path
style that name all intersections of a grid. When you set named grid=test
the intersections will be named as test-1-1
, test-1-2
, ... and so on.
documentclass[tikz,border=7pt]standalone
usetikzlibrarycalc
% The x-step and the y-step lengths
newlengthdxsetlengthdx1cm
newlengthdysetlengthdy1cm
% recover the steps
makeatletter
letpgf@pathgrid@originalpgf@pathgrid
defpgf@pathgrid[#1]#2#3%
pgfset#1%
pgfmathsetlengthdxpgfkeysvalueof/pgf/stepx%
globaldx=dx
pgfmathsetlengthdypgfkeysvalueof/pgf/stepy%
globaldy=dy
pgf@pathgrid@original[#1]#2#3
makeatother
% define the `named grid` style
tikzset
named grid/.style=
to path=
(tikztostart) grid (tikztotarget)
let p1=(tikztostart), p2=(tikztotarget),
n1=min(x1,x2),n2=max(x1,x2),
n3=ceil(n1/dx),n4=n3+1,n5=int(n2/dx),
n6=min(y1,y2),n7=max(y1,y2),
n8=ceil(n6/dy),n9=n8+1,n10=int(n7/dy)
in
foreach[count=nx from 0] x in n3,n4,...,n5
foreach[count=ny from 0] y in n8,n9,...,n10
(x*dx,y*dy) coordinate (#1-nx-ny) % <- name the intersections
,
named grid/.default=grid
begindocument
begintikzpicture
draw[rotate=35,xstep=.7,ystep=.35] (-.5,-1.5) to[named grid=test] (3.5,1.5)
(test-1-1) edge[-latex,red,thick] (test-5-7)
(test-0-0) circle(3pt) (test-5-8) circle(3pt);
endtikzpicture
enddocument
Notes :
- This code is note very stable : it doesn't work well with non linear transforms.
- In a strange way, the most difficult part for me was to recover the steps.
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f470195%2fnaming-intersection-points-of-a-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Second try at it. I hope I understood you: what I am doing here is building the grid by hand, and automatically naming the intersections. You can change the grid parameters (x and y step) and let everything else untouched; the intersections are called g-<column>-<row>
.
Another possibility is to use a TikZ matrix of nodes
for this.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
% draw[step=.5cm,color=gray] (0,0) grid (8,8);
defmystepx0.8cm
defmystepy0.5cm
foreach x in 0,...,8
% draw rows and columns
draw [red] (x*mystepx, 0) -- (x*mystepx,8*mystepy);
draw [blue] (0,x*mystepy) -- (8*mystepx,x*mystepy);
foreach y in 0,...,8
coordinate (g-x-y) at (x*mystepx,y*mystepy);
%
node at (g-1-1)a;
node at (g-2-2)b;
node at (g-3-3)x;
node at (g-4-3)z;
draw<2->[ultra thick, green, -latex] (g-1-1) -- (g-2-2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (g-3-3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (g-4-3);
endtikzpicture
endcenter
endframe
enddocument
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
Trying again...
– Rmano
Jan 15 at 16:43
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
add a comment |
Second try at it. I hope I understood you: what I am doing here is building the grid by hand, and automatically naming the intersections. You can change the grid parameters (x and y step) and let everything else untouched; the intersections are called g-<column>-<row>
.
Another possibility is to use a TikZ matrix of nodes
for this.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
% draw[step=.5cm,color=gray] (0,0) grid (8,8);
defmystepx0.8cm
defmystepy0.5cm
foreach x in 0,...,8
% draw rows and columns
draw [red] (x*mystepx, 0) -- (x*mystepx,8*mystepy);
draw [blue] (0,x*mystepy) -- (8*mystepx,x*mystepy);
foreach y in 0,...,8
coordinate (g-x-y) at (x*mystepx,y*mystepy);
%
node at (g-1-1)a;
node at (g-2-2)b;
node at (g-3-3)x;
node at (g-4-3)z;
draw<2->[ultra thick, green, -latex] (g-1-1) -- (g-2-2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (g-3-3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (g-4-3);
endtikzpicture
endcenter
endframe
enddocument
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
Trying again...
– Rmano
Jan 15 at 16:43
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
add a comment |
Second try at it. I hope I understood you: what I am doing here is building the grid by hand, and automatically naming the intersections. You can change the grid parameters (x and y step) and let everything else untouched; the intersections are called g-<column>-<row>
.
Another possibility is to use a TikZ matrix of nodes
for this.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
% draw[step=.5cm,color=gray] (0,0) grid (8,8);
defmystepx0.8cm
defmystepy0.5cm
foreach x in 0,...,8
% draw rows and columns
draw [red] (x*mystepx, 0) -- (x*mystepx,8*mystepy);
draw [blue] (0,x*mystepy) -- (8*mystepx,x*mystepy);
foreach y in 0,...,8
coordinate (g-x-y) at (x*mystepx,y*mystepy);
%
node at (g-1-1)a;
node at (g-2-2)b;
node at (g-3-3)x;
node at (g-4-3)z;
draw<2->[ultra thick, green, -latex] (g-1-1) -- (g-2-2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (g-3-3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (g-4-3);
endtikzpicture
endcenter
endframe
enddocument
Second try at it. I hope I understood you: what I am doing here is building the grid by hand, and automatically naming the intersections. You can change the grid parameters (x and y step) and let everything else untouched; the intersections are called g-<column>-<row>
.
Another possibility is to use a TikZ matrix of nodes
for this.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture
% draw[step=.5cm,color=gray] (0,0) grid (8,8);
defmystepx0.8cm
defmystepy0.5cm
foreach x in 0,...,8
% draw rows and columns
draw [red] (x*mystepx, 0) -- (x*mystepx,8*mystepy);
draw [blue] (0,x*mystepy) -- (8*mystepx,x*mystepy);
foreach y in 0,...,8
coordinate (g-x-y) at (x*mystepx,y*mystepy);
%
node at (g-1-1)a;
node at (g-2-2)b;
node at (g-3-3)x;
node at (g-4-3)z;
draw<2->[ultra thick, green, -latex] (g-1-1) -- (g-2-2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (g-3-3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (g-4-3);
endtikzpicture
endcenter
endframe
enddocument
edited Jan 15 at 16:43
answered Jan 15 at 10:48
RmanoRmano
7,98221647
7,98221647
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
Trying again...
– Rmano
Jan 15 at 16:43
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
add a comment |
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
Trying again...
– Rmano
Jan 15 at 16:43
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
Thank you for your answer. What you suggested is what I used in my example. As the title of my question says, my point is to name the intersection points of the grid and use them as nodes, not to use the absolute coordinates.
– Hany
Jan 15 at 13:13
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
I edited my post to clarify my point and explain what I need.
– Hany
Jan 15 at 13:58
Trying again...
– Rmano
Jan 15 at 16:43
Trying again...
– Rmano
Jan 15 at 16:43
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
Thank you very much for your answer. I am sorry for the delay of my comment
– Hany
Jan 17 at 5:20
add a comment |
If you remove the units from the steps and do, say, begintikzpicture[x=2cm,y=2cm]
this will increase the step of the grid while keeping the same intersections (or lattice nodes) connected.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture[x=2cm,y=2cm]
draw[step=.5,color=gray] (0,0) grid (5,4);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)a;
node at (2,2)b;
node at (3,3)x;
node at (4,3)z;
endtikzpicture
endcenter
endframe
enddocument
add a comment |
If you remove the units from the steps and do, say, begintikzpicture[x=2cm,y=2cm]
this will increase the step of the grid while keeping the same intersections (or lattice nodes) connected.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture[x=2cm,y=2cm]
draw[step=.5,color=gray] (0,0) grid (5,4);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)a;
node at (2,2)b;
node at (3,3)x;
node at (4,3)z;
endtikzpicture
endcenter
endframe
enddocument
add a comment |
If you remove the units from the steps and do, say, begintikzpicture[x=2cm,y=2cm]
this will increase the step of the grid while keeping the same intersections (or lattice nodes) connected.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture[x=2cm,y=2cm]
draw[step=.5,color=gray] (0,0) grid (5,4);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)a;
node at (2,2)b;
node at (3,3)x;
node at (4,3)z;
endtikzpicture
endcenter
endframe
enddocument
If you remove the units from the steps and do, say, begintikzpicture[x=2cm,y=2cm]
this will increase the step of the grid while keeping the same intersections (or lattice nodes) connected.
documentclassbeamer
setbeamertemplatenavigation symbols
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitleN
begincenter
begintikzpicture[x=2cm,y=2cm]
draw[step=.5,color=gray] (0,0) grid (5,4);
draw<2->[ultra thick, green, -latex] (1,1) -- (2,2);
draw[blue!40!black, thick, fill=blue!40!white, opacity=.5] (3,3) circle (.2cm) node (c);
draw<3->[ultra thick, red, -latex] (c.center) -- (4,3);
node at (1,1)a;
node at (2,2)b;
node at (3,3)x;
node at (4,3)z;
endtikzpicture
endcenter
endframe
enddocument
answered Jan 15 at 8:16
marmotmarmot
96.1k4111212
96.1k4111212
add a comment |
add a comment |
Here is an example of to path
style that name all intersections of a grid. When you set named grid=test
the intersections will be named as test-1-1
, test-1-2
, ... and so on.
documentclass[tikz,border=7pt]standalone
usetikzlibrarycalc
% The x-step and the y-step lengths
newlengthdxsetlengthdx1cm
newlengthdysetlengthdy1cm
% recover the steps
makeatletter
letpgf@pathgrid@originalpgf@pathgrid
defpgf@pathgrid[#1]#2#3%
pgfset#1%
pgfmathsetlengthdxpgfkeysvalueof/pgf/stepx%
globaldx=dx
pgfmathsetlengthdypgfkeysvalueof/pgf/stepy%
globaldy=dy
pgf@pathgrid@original[#1]#2#3
makeatother
% define the `named grid` style
tikzset
named grid/.style=
to path=
(tikztostart) grid (tikztotarget)
let p1=(tikztostart), p2=(tikztotarget),
n1=min(x1,x2),n2=max(x1,x2),
n3=ceil(n1/dx),n4=n3+1,n5=int(n2/dx),
n6=min(y1,y2),n7=max(y1,y2),
n8=ceil(n6/dy),n9=n8+1,n10=int(n7/dy)
in
foreach[count=nx from 0] x in n3,n4,...,n5
foreach[count=ny from 0] y in n8,n9,...,n10
(x*dx,y*dy) coordinate (#1-nx-ny) % <- name the intersections
,
named grid/.default=grid
begindocument
begintikzpicture
draw[rotate=35,xstep=.7,ystep=.35] (-.5,-1.5) to[named grid=test] (3.5,1.5)
(test-1-1) edge[-latex,red,thick] (test-5-7)
(test-0-0) circle(3pt) (test-5-8) circle(3pt);
endtikzpicture
enddocument
Notes :
- This code is note very stable : it doesn't work well with non linear transforms.
- In a strange way, the most difficult part for me was to recover the steps.
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
add a comment |
Here is an example of to path
style that name all intersections of a grid. When you set named grid=test
the intersections will be named as test-1-1
, test-1-2
, ... and so on.
documentclass[tikz,border=7pt]standalone
usetikzlibrarycalc
% The x-step and the y-step lengths
newlengthdxsetlengthdx1cm
newlengthdysetlengthdy1cm
% recover the steps
makeatletter
letpgf@pathgrid@originalpgf@pathgrid
defpgf@pathgrid[#1]#2#3%
pgfset#1%
pgfmathsetlengthdxpgfkeysvalueof/pgf/stepx%
globaldx=dx
pgfmathsetlengthdypgfkeysvalueof/pgf/stepy%
globaldy=dy
pgf@pathgrid@original[#1]#2#3
makeatother
% define the `named grid` style
tikzset
named grid/.style=
to path=
(tikztostart) grid (tikztotarget)
let p1=(tikztostart), p2=(tikztotarget),
n1=min(x1,x2),n2=max(x1,x2),
n3=ceil(n1/dx),n4=n3+1,n5=int(n2/dx),
n6=min(y1,y2),n7=max(y1,y2),
n8=ceil(n6/dy),n9=n8+1,n10=int(n7/dy)
in
foreach[count=nx from 0] x in n3,n4,...,n5
foreach[count=ny from 0] y in n8,n9,...,n10
(x*dx,y*dy) coordinate (#1-nx-ny) % <- name the intersections
,
named grid/.default=grid
begindocument
begintikzpicture
draw[rotate=35,xstep=.7,ystep=.35] (-.5,-1.5) to[named grid=test] (3.5,1.5)
(test-1-1) edge[-latex,red,thick] (test-5-7)
(test-0-0) circle(3pt) (test-5-8) circle(3pt);
endtikzpicture
enddocument
Notes :
- This code is note very stable : it doesn't work well with non linear transforms.
- In a strange way, the most difficult part for me was to recover the steps.
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
add a comment |
Here is an example of to path
style that name all intersections of a grid. When you set named grid=test
the intersections will be named as test-1-1
, test-1-2
, ... and so on.
documentclass[tikz,border=7pt]standalone
usetikzlibrarycalc
% The x-step and the y-step lengths
newlengthdxsetlengthdx1cm
newlengthdysetlengthdy1cm
% recover the steps
makeatletter
letpgf@pathgrid@originalpgf@pathgrid
defpgf@pathgrid[#1]#2#3%
pgfset#1%
pgfmathsetlengthdxpgfkeysvalueof/pgf/stepx%
globaldx=dx
pgfmathsetlengthdypgfkeysvalueof/pgf/stepy%
globaldy=dy
pgf@pathgrid@original[#1]#2#3
makeatother
% define the `named grid` style
tikzset
named grid/.style=
to path=
(tikztostart) grid (tikztotarget)
let p1=(tikztostart), p2=(tikztotarget),
n1=min(x1,x2),n2=max(x1,x2),
n3=ceil(n1/dx),n4=n3+1,n5=int(n2/dx),
n6=min(y1,y2),n7=max(y1,y2),
n8=ceil(n6/dy),n9=n8+1,n10=int(n7/dy)
in
foreach[count=nx from 0] x in n3,n4,...,n5
foreach[count=ny from 0] y in n8,n9,...,n10
(x*dx,y*dy) coordinate (#1-nx-ny) % <- name the intersections
,
named grid/.default=grid
begindocument
begintikzpicture
draw[rotate=35,xstep=.7,ystep=.35] (-.5,-1.5) to[named grid=test] (3.5,1.5)
(test-1-1) edge[-latex,red,thick] (test-5-7)
(test-0-0) circle(3pt) (test-5-8) circle(3pt);
endtikzpicture
enddocument
Notes :
- This code is note very stable : it doesn't work well with non linear transforms.
- In a strange way, the most difficult part for me was to recover the steps.
Here is an example of to path
style that name all intersections of a grid. When you set named grid=test
the intersections will be named as test-1-1
, test-1-2
, ... and so on.
documentclass[tikz,border=7pt]standalone
usetikzlibrarycalc
% The x-step and the y-step lengths
newlengthdxsetlengthdx1cm
newlengthdysetlengthdy1cm
% recover the steps
makeatletter
letpgf@pathgrid@originalpgf@pathgrid
defpgf@pathgrid[#1]#2#3%
pgfset#1%
pgfmathsetlengthdxpgfkeysvalueof/pgf/stepx%
globaldx=dx
pgfmathsetlengthdypgfkeysvalueof/pgf/stepy%
globaldy=dy
pgf@pathgrid@original[#1]#2#3
makeatother
% define the `named grid` style
tikzset
named grid/.style=
to path=
(tikztostart) grid (tikztotarget)
let p1=(tikztostart), p2=(tikztotarget),
n1=min(x1,x2),n2=max(x1,x2),
n3=ceil(n1/dx),n4=n3+1,n5=int(n2/dx),
n6=min(y1,y2),n7=max(y1,y2),
n8=ceil(n6/dy),n9=n8+1,n10=int(n7/dy)
in
foreach[count=nx from 0] x in n3,n4,...,n5
foreach[count=ny from 0] y in n8,n9,...,n10
(x*dx,y*dy) coordinate (#1-nx-ny) % <- name the intersections
,
named grid/.default=grid
begindocument
begintikzpicture
draw[rotate=35,xstep=.7,ystep=.35] (-.5,-1.5) to[named grid=test] (3.5,1.5)
(test-1-1) edge[-latex,red,thick] (test-5-7)
(test-0-0) circle(3pt) (test-5-8) circle(3pt);
endtikzpicture
enddocument
Notes :
- This code is note very stable : it doesn't work well with non linear transforms.
- In a strange way, the most difficult part for me was to recover the steps.
answered Jan 15 at 21:01
KpymKpym
16k23987
16k23987
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
add a comment |
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
Thank you for your answer. As you said it is not very stable.
– Hany
Jan 17 at 5:24
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f470195%2fnaming-intersection-points-of-a-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@marmot Thank you for your comment, but I do not want to change the x/y scaling. This is an MWE not the whole drawing. There are other drawings in other intersections.
– Hany
Jan 15 at 8:15