Angle and distance between two points in tikz?











up vote
3
down vote

favorite












Given two (A) and (B) 2-D points in tikzpicture environment, I need to collect both angle of the line (A)-(B) with respect to the vector(1,0) and the half of its distance in two variables, say Aab and Dab respectively. SOLVED (see Coordinates A, B: compute |B-A| and angle between +x and (B-A))



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
makeatletter
newcommand{getLengthAndAngle}[2]{%
pgfmathanglebetweenpoints{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
globalletmyanglepgfmathresult % we need a global macro
pgfpointdiff{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
pgf@xa=pgf@x % no need to use a new dimen
pgf@ya=pgf@y
pgfmathparse{veclen(pgf@xa,pgf@ya)/28.45274} % to convert from pt
to cm
globalletmylengthpgfmathresult % we need a global macro}
makeatother

begin{document}
begin{tikzpicture}
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
getLengthAndAngle{A}{B}
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw (A) -- (B)--+(mylength,0);
draw[rotate around={-myangle:(A)}] (A)--+(mylength,0);
end{scope}
draw (B) circle (mylength cm);
end{tikzpicture}
end{document}









share|improve this question




















  • 3




    Did you try something?
    – Sebastiano
    Nov 14 at 19:54










  • look angle library.
    – Zarko
    Nov 14 at 20:06






  • 2




    Related: tex.stackexchange.com/questions/39293/…
    – Torbjørn T.
    Nov 14 at 20:14










  • @Zarko If you mean the angles library that is as you know for drawing an angle symbol between two lines, the OP wants to calculate an angle and a distance.
    – Torbjørn T.
    Nov 14 at 20:16






  • 2




    It would be helpful if you composed a fully compilable MWE including documentclass and the appropriate packages that at least sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This will also serve as a test case and ensure that the solution actually works for you. As it is it is not clear what you mean by "collect".
    – Peter Grill
    Nov 14 at 20:23















up vote
3
down vote

favorite












Given two (A) and (B) 2-D points in tikzpicture environment, I need to collect both angle of the line (A)-(B) with respect to the vector(1,0) and the half of its distance in two variables, say Aab and Dab respectively. SOLVED (see Coordinates A, B: compute |B-A| and angle between +x and (B-A))



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
makeatletter
newcommand{getLengthAndAngle}[2]{%
pgfmathanglebetweenpoints{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
globalletmyanglepgfmathresult % we need a global macro
pgfpointdiff{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
pgf@xa=pgf@x % no need to use a new dimen
pgf@ya=pgf@y
pgfmathparse{veclen(pgf@xa,pgf@ya)/28.45274} % to convert from pt
to cm
globalletmylengthpgfmathresult % we need a global macro}
makeatother

begin{document}
begin{tikzpicture}
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
getLengthAndAngle{A}{B}
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw (A) -- (B)--+(mylength,0);
draw[rotate around={-myangle:(A)}] (A)--+(mylength,0);
end{scope}
draw (B) circle (mylength cm);
end{tikzpicture}
end{document}









share|improve this question




















  • 3




    Did you try something?
    – Sebastiano
    Nov 14 at 19:54










  • look angle library.
    – Zarko
    Nov 14 at 20:06






  • 2




    Related: tex.stackexchange.com/questions/39293/…
    – Torbjørn T.
    Nov 14 at 20:14










  • @Zarko If you mean the angles library that is as you know for drawing an angle symbol between two lines, the OP wants to calculate an angle and a distance.
    – Torbjørn T.
    Nov 14 at 20:16






  • 2




    It would be helpful if you composed a fully compilable MWE including documentclass and the appropriate packages that at least sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This will also serve as a test case and ensure that the solution actually works for you. As it is it is not clear what you mean by "collect".
    – Peter Grill
    Nov 14 at 20:23













up vote
3
down vote

favorite









up vote
3
down vote

favorite











Given two (A) and (B) 2-D points in tikzpicture environment, I need to collect both angle of the line (A)-(B) with respect to the vector(1,0) and the half of its distance in two variables, say Aab and Dab respectively. SOLVED (see Coordinates A, B: compute |B-A| and angle between +x and (B-A))



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
makeatletter
newcommand{getLengthAndAngle}[2]{%
pgfmathanglebetweenpoints{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
globalletmyanglepgfmathresult % we need a global macro
pgfpointdiff{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
pgf@xa=pgf@x % no need to use a new dimen
pgf@ya=pgf@y
pgfmathparse{veclen(pgf@xa,pgf@ya)/28.45274} % to convert from pt
to cm
globalletmylengthpgfmathresult % we need a global macro}
makeatother

begin{document}
begin{tikzpicture}
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
getLengthAndAngle{A}{B}
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw (A) -- (B)--+(mylength,0);
draw[rotate around={-myangle:(A)}] (A)--+(mylength,0);
end{scope}
draw (B) circle (mylength cm);
end{tikzpicture}
end{document}









share|improve this question















Given two (A) and (B) 2-D points in tikzpicture environment, I need to collect both angle of the line (A)-(B) with respect to the vector(1,0) and the half of its distance in two variables, say Aab and Dab respectively. SOLVED (see Coordinates A, B: compute |B-A| and angle between +x and (B-A))



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
makeatletter
newcommand{getLengthAndAngle}[2]{%
pgfmathanglebetweenpoints{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
globalletmyanglepgfmathresult % we need a global macro
pgfpointdiff{pgfpointanchor{#1}{center}}
{pgfpointanchor{#2}{center}}
pgf@xa=pgf@x % no need to use a new dimen
pgf@ya=pgf@y
pgfmathparse{veclen(pgf@xa,pgf@ya)/28.45274} % to convert from pt
to cm
globalletmylengthpgfmathresult % we need a global macro}
makeatother

begin{document}
begin{tikzpicture}
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
getLengthAndAngle{A}{B}
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw (A) -- (B)--+(mylength,0);
draw[rotate around={-myangle:(A)}] (A)--+(mylength,0);
end{scope}
draw (B) circle (mylength cm);
end{tikzpicture}
end{document}






tikz-pgf angle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 21:16

























asked Nov 14 at 19:52









JOM

948




948








  • 3




    Did you try something?
    – Sebastiano
    Nov 14 at 19:54










  • look angle library.
    – Zarko
    Nov 14 at 20:06






  • 2




    Related: tex.stackexchange.com/questions/39293/…
    – Torbjørn T.
    Nov 14 at 20:14










  • @Zarko If you mean the angles library that is as you know for drawing an angle symbol between two lines, the OP wants to calculate an angle and a distance.
    – Torbjørn T.
    Nov 14 at 20:16






  • 2




    It would be helpful if you composed a fully compilable MWE including documentclass and the appropriate packages that at least sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This will also serve as a test case and ensure that the solution actually works for you. As it is it is not clear what you mean by "collect".
    – Peter Grill
    Nov 14 at 20:23














  • 3




    Did you try something?
    – Sebastiano
    Nov 14 at 19:54










  • look angle library.
    – Zarko
    Nov 14 at 20:06






  • 2




    Related: tex.stackexchange.com/questions/39293/…
    – Torbjørn T.
    Nov 14 at 20:14










  • @Zarko If you mean the angles library that is as you know for drawing an angle symbol between two lines, the OP wants to calculate an angle and a distance.
    – Torbjørn T.
    Nov 14 at 20:16






  • 2




    It would be helpful if you composed a fully compilable MWE including documentclass and the appropriate packages that at least sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This will also serve as a test case and ensure that the solution actually works for you. As it is it is not clear what you mean by "collect".
    – Peter Grill
    Nov 14 at 20:23








3




3




Did you try something?
– Sebastiano
Nov 14 at 19:54




Did you try something?
– Sebastiano
Nov 14 at 19:54












look angle library.
– Zarko
Nov 14 at 20:06




look angle library.
– Zarko
Nov 14 at 20:06




2




2




Related: tex.stackexchange.com/questions/39293/…
– Torbjørn T.
Nov 14 at 20:14




Related: tex.stackexchange.com/questions/39293/…
– Torbjørn T.
Nov 14 at 20:14












@Zarko If you mean the angles library that is as you know for drawing an angle symbol between two lines, the OP wants to calculate an angle and a distance.
– Torbjørn T.
Nov 14 at 20:16




@Zarko If you mean the angles library that is as you know for drawing an angle symbol between two lines, the OP wants to calculate an angle and a distance.
– Torbjørn T.
Nov 14 at 20:16




2




2




It would be helpful if you composed a fully compilable MWE including documentclass and the appropriate packages that at least sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This will also serve as a test case and ensure that the solution actually works for you. As it is it is not clear what you mean by "collect".
– Peter Grill
Nov 14 at 20:23




It would be helpful if you composed a fully compilable MWE including documentclass and the appropriate packages that at least sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This will also serve as a test case and ensure that the solution actually works for you. As it is it is not clear what you mean by "collect".
– Peter Grill
Nov 14 at 20:23










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Here is an alternative solely based on calc, i.e. not using extra macros, and with a little helper that allows you to "export" the length outside the path (and scope).



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[globalize/.code n args={2}{xdef#2{#1}}]
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)}
in [globalize={n2}{mylength}] (A) -- (B)--+(n2,0)
[rotate around={-n1:(A)}] (A)--+(n2,0);
end{scope}
draw (B) circle (mylength);
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





















  • n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
    – JOM
    Nov 14 at 22:31










  • @JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
    – marmot
    Nov 15 at 0:03











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',
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460006%2fangle-and-distance-between-two-points-in-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Here is an alternative solely based on calc, i.e. not using extra macros, and with a little helper that allows you to "export" the length outside the path (and scope).



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[globalize/.code n args={2}{xdef#2{#1}}]
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)}
in [globalize={n2}{mylength}] (A) -- (B)--+(n2,0)
[rotate around={-n1:(A)}] (A)--+(n2,0);
end{scope}
draw (B) circle (mylength);
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





















  • n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
    – JOM
    Nov 14 at 22:31










  • @JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
    – marmot
    Nov 15 at 0:03















up vote
2
down vote



accepted










Here is an alternative solely based on calc, i.e. not using extra macros, and with a little helper that allows you to "export" the length outside the path (and scope).



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[globalize/.code n args={2}{xdef#2{#1}}]
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)}
in [globalize={n2}{mylength}] (A) -- (B)--+(n2,0)
[rotate around={-n1:(A)}] (A)--+(n2,0);
end{scope}
draw (B) circle (mylength);
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





















  • n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
    – JOM
    Nov 14 at 22:31










  • @JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
    – marmot
    Nov 15 at 0:03













up vote
2
down vote



accepted







up vote
2
down vote



accepted






Here is an alternative solely based on calc, i.e. not using extra macros, and with a little helper that allows you to "export" the length outside the path (and scope).



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[globalize/.code n args={2}{xdef#2{#1}}]
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)}
in [globalize={n2}{mylength}] (A) -- (B)--+(n2,0)
[rotate around={-n1:(A)}] (A)--+(n2,0);
end{scope}
draw (B) circle (mylength);
end{tikzpicture}
end{document}


enter image description here






share|improve this answer












Here is an alternative solely based on calc, i.e. not using extra macros, and with a little helper that allows you to "export" the length outside the path (and scope).



documentclass{article}
usepackage{pgf,tikz}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[globalize/.code n args={2}{xdef#2{#1}}]
clip (0,4) rectangle (7,-5);
coordinate (A) at (1,1);
coordinate (B) at (3,4);
draw[help lines,gray] (0,-3) grid (5,5);
begin{scope}[blue, thick]
draw let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)}
in [globalize={n2}{mylength}] (A) -- (B)--+(n2,0)
[rotate around={-n1:(A)}] (A)--+(n2,0);
end{scope}
draw (B) circle (mylength);
end{tikzpicture}
end{document}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 at 22:01









marmot

76.6k487161




76.6k487161












  • n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
    – JOM
    Nov 14 at 22:31










  • @JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
    – marmot
    Nov 15 at 0:03


















  • n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
    – JOM
    Nov 14 at 22:31










  • @JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
    – marmot
    Nov 15 at 0:03
















n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
– JOM
Nov 14 at 22:31




n1={atan2(y1,x1)}. Can we globalize both variables... and no drawing at all?
– JOM
Nov 14 at 22:31












@JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
– marmot
Nov 15 at 0:03




@JOM Sure: path let p1=($(B)-(A)$), n1={veclen(y1,x1)}, n2={veclen(y1,x1)} in [globalize={n2}{mylength},globalize={n1}{myangle}];. Just watch out for globalization critics! ;-)
– marmot
Nov 15 at 0:03


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460006%2fangle-and-distance-between-two-points-in-tikz%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents