Specifying line length in TikZ
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
(I apologise if this question has been asked before, it's hard to believe it hasn't, but I can't find any material on it.) I want to draw a line passing through two points where I can specify the width. The line should go from the first given point in the direction of the second point, then continue until the given length is up. I want to be able to type something like draw[length=5] (0,0)--(1,2);
to accomplish this.
Here's what I have so far:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
draw (0,0)--(1,2);
endtikzpicture
enddocument
Again, the problem with this is that it draws a line terminating at the two given points, but I only want it to terminate at one point (the first) but continue until the length specified has been used up at the other end. I know that this can be accomplished by always manually calculating the coordinates using some math, but that is ridiculously tedious and there must be a better way to do it! Thanks in advance.
tikz-pgf draw
add a comment |Â
up vote
1
down vote
favorite
(I apologise if this question has been asked before, it's hard to believe it hasn't, but I can't find any material on it.) I want to draw a line passing through two points where I can specify the width. The line should go from the first given point in the direction of the second point, then continue until the given length is up. I want to be able to type something like draw[length=5] (0,0)--(1,2);
to accomplish this.
Here's what I have so far:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
draw (0,0)--(1,2);
endtikzpicture
enddocument
Again, the problem with this is that it draws a line terminating at the two given points, but I only want it to terminate at one point (the first) but continue until the length specified has been used up at the other end. I know that this can be accomplished by always manually calculating the coordinates using some math, but that is ridiculously tedious and there must be a better way to do it! Thanks in advance.
tikz-pgf draw
see if polar coordinate can be of help. using it you need to determine angle of line (withatan
function, for example):draw (0,0) -- (<angle>:5cm);
– Zarko
2 hours ago
Is that the best way? It can be a bit tedious especially when one of those points isn't at the origin...
– Teyyf
2 hours ago
Why? You could dodraw (10,20) -- (angle:5cm)
. For the calculation, you can assume the point you start the origin if you want.
– TeXnician
2 hours ago
How will I find the angle given any two arbitrary points? Do I need to do something like type it into a calculator?
– Teyyf
2 hours ago
@Teyyf, well, you need some basic knowledge from geometry (how calculate angle from given catheterizes of triangle) :-)
– Zarko
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
(I apologise if this question has been asked before, it's hard to believe it hasn't, but I can't find any material on it.) I want to draw a line passing through two points where I can specify the width. The line should go from the first given point in the direction of the second point, then continue until the given length is up. I want to be able to type something like draw[length=5] (0,0)--(1,2);
to accomplish this.
Here's what I have so far:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
draw (0,0)--(1,2);
endtikzpicture
enddocument
Again, the problem with this is that it draws a line terminating at the two given points, but I only want it to terminate at one point (the first) but continue until the length specified has been used up at the other end. I know that this can be accomplished by always manually calculating the coordinates using some math, but that is ridiculously tedious and there must be a better way to do it! Thanks in advance.
tikz-pgf draw
(I apologise if this question has been asked before, it's hard to believe it hasn't, but I can't find any material on it.) I want to draw a line passing through two points where I can specify the width. The line should go from the first given point in the direction of the second point, then continue until the given length is up. I want to be able to type something like draw[length=5] (0,0)--(1,2);
to accomplish this.
Here's what I have so far:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
draw (0,0)--(1,2);
endtikzpicture
enddocument
Again, the problem with this is that it draws a line terminating at the two given points, but I only want it to terminate at one point (the first) but continue until the length specified has been used up at the other end. I know that this can be accomplished by always manually calculating the coordinates using some math, but that is ridiculously tedious and there must be a better way to do it! Thanks in advance.
tikz-pgf draw
tikz-pgf draw
asked 2 hours ago


Teyyf
946
946
see if polar coordinate can be of help. using it you need to determine angle of line (withatan
function, for example):draw (0,0) -- (<angle>:5cm);
– Zarko
2 hours ago
Is that the best way? It can be a bit tedious especially when one of those points isn't at the origin...
– Teyyf
2 hours ago
Why? You could dodraw (10,20) -- (angle:5cm)
. For the calculation, you can assume the point you start the origin if you want.
– TeXnician
2 hours ago
How will I find the angle given any two arbitrary points? Do I need to do something like type it into a calculator?
– Teyyf
2 hours ago
@Teyyf, well, you need some basic knowledge from geometry (how calculate angle from given catheterizes of triangle) :-)
– Zarko
1 hour ago
add a comment |Â
see if polar coordinate can be of help. using it you need to determine angle of line (withatan
function, for example):draw (0,0) -- (<angle>:5cm);
– Zarko
2 hours ago
Is that the best way? It can be a bit tedious especially when one of those points isn't at the origin...
– Teyyf
2 hours ago
Why? You could dodraw (10,20) -- (angle:5cm)
. For the calculation, you can assume the point you start the origin if you want.
– TeXnician
2 hours ago
How will I find the angle given any two arbitrary points? Do I need to do something like type it into a calculator?
– Teyyf
2 hours ago
@Teyyf, well, you need some basic knowledge from geometry (how calculate angle from given catheterizes of triangle) :-)
– Zarko
1 hour ago
see if polar coordinate can be of help. using it you need to determine angle of line (with
atan
function, for example): draw (0,0) -- (<angle>:5cm);
– Zarko
2 hours ago
see if polar coordinate can be of help. using it you need to determine angle of line (with
atan
function, for example): draw (0,0) -- (<angle>:5cm);
– Zarko
2 hours ago
Is that the best way? It can be a bit tedious especially when one of those points isn't at the origin...
– Teyyf
2 hours ago
Is that the best way? It can be a bit tedious especially when one of those points isn't at the origin...
– Teyyf
2 hours ago
Why? You could do
draw (10,20) -- (angle:5cm)
. For the calculation, you can assume the point you start the origin if you want.– TeXnician
2 hours ago
Why? You could do
draw (10,20) -- (angle:5cm)
. For the calculation, you can assume the point you start the origin if you want.– TeXnician
2 hours ago
How will I find the angle given any two arbitrary points? Do I need to do something like type it into a calculator?
– Teyyf
2 hours ago
How will I find the angle given any two arbitrary points? Do I need to do something like type it into a calculator?
– Teyyf
2 hours ago
@Teyyf, well, you need some basic knowledge from geometry (how calculate angle from given catheterizes of triangle) :-)
– Zarko
1 hour ago
@Teyyf, well, you need some basic knowledge from geometry (how calculate angle from given catheterizes of triangle) :-)
– Zarko
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
If you know the angle, then you can use relative polar coodinates, e.g. draw (1,1) -- +(30:2cm);
. The +
before the polar coordinate indicates that the previous coordinate ((1,1)
) should be used as the origin. If you use ++(30:2cm)
, the current point is also updated, so if you add another relative coordinate to the path, the origin of that will be the end point of the first segment.
If you have two points, you can use the features of the calc
library. ($(a)!3cm!(b)$)
is the coordinate that is 3cm away from a
, at the line passing through a
and b
. Hence, draw (a) -- ($(a)!3cm!(b)$);
draws a line from a
to that point.
documentclass[border=5mm]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
draw (0,0) grid (4,3);
node[inner sep=1pt,fill, label=above left:a] (a) at (1,1) ;
node[inner sep=1pt,fill, label=above left:b] (b) at (3,2) ;
draw [red] (a) -- +(30:2cm);
draw [blue] (a) -- ($(a)!3cm!(b)$);
endtikzpicture
enddocument
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
If you know the angle, then you can use relative polar coodinates, e.g. draw (1,1) -- +(30:2cm);
. The +
before the polar coordinate indicates that the previous coordinate ((1,1)
) should be used as the origin. If you use ++(30:2cm)
, the current point is also updated, so if you add another relative coordinate to the path, the origin of that will be the end point of the first segment.
If you have two points, you can use the features of the calc
library. ($(a)!3cm!(b)$)
is the coordinate that is 3cm away from a
, at the line passing through a
and b
. Hence, draw (a) -- ($(a)!3cm!(b)$);
draws a line from a
to that point.
documentclass[border=5mm]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
draw (0,0) grid (4,3);
node[inner sep=1pt,fill, label=above left:a] (a) at (1,1) ;
node[inner sep=1pt,fill, label=above left:b] (b) at (3,2) ;
draw [red] (a) -- +(30:2cm);
draw [blue] (a) -- ($(a)!3cm!(b)$);
endtikzpicture
enddocument
add a comment |Â
up vote
2
down vote
If you know the angle, then you can use relative polar coodinates, e.g. draw (1,1) -- +(30:2cm);
. The +
before the polar coordinate indicates that the previous coordinate ((1,1)
) should be used as the origin. If you use ++(30:2cm)
, the current point is also updated, so if you add another relative coordinate to the path, the origin of that will be the end point of the first segment.
If you have two points, you can use the features of the calc
library. ($(a)!3cm!(b)$)
is the coordinate that is 3cm away from a
, at the line passing through a
and b
. Hence, draw (a) -- ($(a)!3cm!(b)$);
draws a line from a
to that point.
documentclass[border=5mm]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
draw (0,0) grid (4,3);
node[inner sep=1pt,fill, label=above left:a] (a) at (1,1) ;
node[inner sep=1pt,fill, label=above left:b] (b) at (3,2) ;
draw [red] (a) -- +(30:2cm);
draw [blue] (a) -- ($(a)!3cm!(b)$);
endtikzpicture
enddocument
add a comment |Â
up vote
2
down vote
up vote
2
down vote
If you know the angle, then you can use relative polar coodinates, e.g. draw (1,1) -- +(30:2cm);
. The +
before the polar coordinate indicates that the previous coordinate ((1,1)
) should be used as the origin. If you use ++(30:2cm)
, the current point is also updated, so if you add another relative coordinate to the path, the origin of that will be the end point of the first segment.
If you have two points, you can use the features of the calc
library. ($(a)!3cm!(b)$)
is the coordinate that is 3cm away from a
, at the line passing through a
and b
. Hence, draw (a) -- ($(a)!3cm!(b)$);
draws a line from a
to that point.
documentclass[border=5mm]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
draw (0,0) grid (4,3);
node[inner sep=1pt,fill, label=above left:a] (a) at (1,1) ;
node[inner sep=1pt,fill, label=above left:b] (b) at (3,2) ;
draw [red] (a) -- +(30:2cm);
draw [blue] (a) -- ($(a)!3cm!(b)$);
endtikzpicture
enddocument
If you know the angle, then you can use relative polar coodinates, e.g. draw (1,1) -- +(30:2cm);
. The +
before the polar coordinate indicates that the previous coordinate ((1,1)
) should be used as the origin. If you use ++(30:2cm)
, the current point is also updated, so if you add another relative coordinate to the path, the origin of that will be the end point of the first segment.
If you have two points, you can use the features of the calc
library. ($(a)!3cm!(b)$)
is the coordinate that is 3cm away from a
, at the line passing through a
and b
. Hence, draw (a) -- ($(a)!3cm!(b)$);
draws a line from a
to that point.
documentclass[border=5mm]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
draw (0,0) grid (4,3);
node[inner sep=1pt,fill, label=above left:a] (a) at (1,1) ;
node[inner sep=1pt,fill, label=above left:b] (b) at (3,2) ;
draw [red] (a) -- +(30:2cm);
draw [blue] (a) -- ($(a)!3cm!(b)$);
endtikzpicture
enddocument
answered 43 mins ago
Torbjørn T.
151k13243424
151k13243424
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f452060%2fspecifying-line-length-in-tikz%23new-answer', 'question_page');
);
Post as a guest
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
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
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
see if polar coordinate can be of help. using it you need to determine angle of line (with
atan
function, for example):draw (0,0) -- (<angle>:5cm);
– Zarko
2 hours ago
Is that the best way? It can be a bit tedious especially when one of those points isn't at the origin...
– Teyyf
2 hours ago
Why? You could do
draw (10,20) -- (angle:5cm)
. For the calculation, you can assume the point you start the origin if you want.– TeXnician
2 hours ago
How will I find the angle given any two arbitrary points? Do I need to do something like type it into a calculator?
– Teyyf
2 hours ago
@Teyyf, well, you need some basic knowledge from geometry (how calculate angle from given catheterizes of triangle) :-)
– Zarko
1 hour ago