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}
tikz-pgf angle
|
show 6 more comments
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}
tikz-pgf angle
3
Did you try something?
– Sebastiano
Nov 14 at 19:54
lookangle
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 theangles
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 includingdocumentclass
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
|
show 6 more comments
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}
tikz-pgf angle
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
tikz-pgf angle
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
lookangle
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 theangles
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 includingdocumentclass
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
|
show 6 more comments
3
Did you try something?
– Sebastiano
Nov 14 at 19:54
lookangle
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 theangles
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 includingdocumentclass
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
|
show 6 more comments
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}
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
add a comment |
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}
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
add a comment |
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}
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
add a comment |
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}
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}
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
add a comment |
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
add a comment |
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%2f460006%2fangle-and-distance-between-two-points-in-tikz%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
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