Tangent Lines Diagram Along Smooth Curve
up vote
6
down vote
favorite
I am trying to replicate a diagram and have a minimal example. I don't know how to add additional tangents between the specified points and preserve smoothness.
documentclass{article}
usepackage{tikz}
usetikzlibrary{calc,intersections}
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}] (a) node [below left] {$a$}
(b) node [above right] {$b$};
end{tikzpicture}
end{document}
Outputs:
My Goal is create the following:
Feel free to make any changes that make the minimal example approach the goal diagram
tikz-pgf intersections
add a comment |
up vote
6
down vote
favorite
I am trying to replicate a diagram and have a minimal example. I don't know how to add additional tangents between the specified points and preserve smoothness.
documentclass{article}
usepackage{tikz}
usetikzlibrary{calc,intersections}
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}] (a) node [below left] {$a$}
(b) node [above right] {$b$};
end{tikzpicture}
end{document}
Outputs:
My Goal is create the following:
Feel free to make any changes that make the minimal example approach the goal diagram
tikz-pgf intersections
I sense without having a concrete equation for the graph above this will be a challenge. Unless there is another programming tool for TiKz?
– MathScholar
Nov 24 at 16:32
Marmot mentions tex.stackexchange.com/questions/25928/…
– MathScholar
Nov 24 at 16:40
add a comment |
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I am trying to replicate a diagram and have a minimal example. I don't know how to add additional tangents between the specified points and preserve smoothness.
documentclass{article}
usepackage{tikz}
usetikzlibrary{calc,intersections}
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}] (a) node [below left] {$a$}
(b) node [above right] {$b$};
end{tikzpicture}
end{document}
Outputs:
My Goal is create the following:
Feel free to make any changes that make the minimal example approach the goal diagram
tikz-pgf intersections
I am trying to replicate a diagram and have a minimal example. I don't know how to add additional tangents between the specified points and preserve smoothness.
documentclass{article}
usepackage{tikz}
usetikzlibrary{calc,intersections}
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}] (a) node [below left] {$a$}
(b) node [above right] {$b$};
end{tikzpicture}
end{document}
Outputs:
My Goal is create the following:
Feel free to make any changes that make the minimal example approach the goal diagram
tikz-pgf intersections
tikz-pgf intersections
asked Nov 24 at 15:53
MathScholar
4658
4658
I sense without having a concrete equation for the graph above this will be a challenge. Unless there is another programming tool for TiKz?
– MathScholar
Nov 24 at 16:32
Marmot mentions tex.stackexchange.com/questions/25928/…
– MathScholar
Nov 24 at 16:40
add a comment |
I sense without having a concrete equation for the graph above this will be a challenge. Unless there is another programming tool for TiKz?
– MathScholar
Nov 24 at 16:32
Marmot mentions tex.stackexchange.com/questions/25928/…
– MathScholar
Nov 24 at 16:40
I sense without having a concrete equation for the graph above this will be a challenge. Unless there is another programming tool for TiKz?
– MathScholar
Nov 24 at 16:32
I sense without having a concrete equation for the graph above this will be a challenge. Unless there is another programming tool for TiKz?
– MathScholar
Nov 24 at 16:32
Marmot mentions tex.stackexchange.com/questions/25928/…
– MathScholar
Nov 24 at 16:40
Marmot mentions tex.stackexchange.com/questions/25928/…
– MathScholar
Nov 24 at 16:40
add a comment |
3 Answers
3
active
oldest
votes
up vote
7
down vote
accepted
You can use a bit of calculus:
The DrawTangent
macro creates two vertical lines around the given x values and computes the intersection of those and the curve. Then, the tangent can be approximated by the secant between those two intersection points.
Code:
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc,intersections}
newcommand*{DeltaX}{0.01}
newcommand*{DrawTangent}[5]{%
% #1 = draw options
% #2 = name of curve
% #3 = ymin
% #4 = ymax
% #5 = x value at which tangent is to be drawn
path[name path=Vertical Line Left] (#5-DeltaX,#3) -- (#5-DeltaX,#4);
path[name path=Vertical Line Right] (#5+DeltaX,#3) -- (#5+DeltaX,#4);
path [name intersections={of=Vertical Line Left and #2}];
coordinate (X0) at (intersection-1);
path [name intersections={of=Vertical Line Right and #2}];
coordinate (X1) at (intersection-1);
draw [shorten <= -1.00cm, shorten >= -1.00cm, #1] (X0) -- (X1);
}%
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}]
(a) node [below left] {$a$}
(b) node [above right] {$b$};
DrawTangent[red, thick]{curve}{-1}{4}{1.5}
DrawTangent[orange, thick]{curve}{-1}{4}{3.5}
end{tikzpicture}
end{document}
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
@MathScholar: You need to usename path=xxxx
to name the curve (xxxx
in this example), and pass that toDrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.
– Peter Grill
Nov 27 at 21:09
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
add a comment |
up vote
6
down vote
A PSTricks solution just for comparison purpose.
documentclass[pstricks]{standalone}
usepackage{pstricks-add,pst-vehicle,tikzducks}
defV{rput(1,1.5){psscalebox{-2 2}{tikz{duck[alien=red]}}}}
defF{2*cos(x)+x/3}
defFp{Derive(1,F)}
deftangent#1#2#3{psplotTangent[linecolor=blue,showpoints]{#1}{.5}{F}uput[#2](*#1 {F}){scriptsize$f'#30$}}
defnormal#1{psplotTangent[linecolor=magenta,Derive={-1/Fp},showpoints]{#1}{.2}{F}}
psset{plotpoints=200}
begin{document}
foreach i in {-0.8,-0.6,...,10.8}{
begin{pspicture}(-2.5,-2)(12.5,6)
psaxes[ticks=none,labels=none,linecolor=gray]{->}(0,0)(-2,-1.5)(11.5,5)[$x$,0][$y$,90]
psplot[linecolor=red]{-1.5}{11}{F}
normal{-1.5}
tangent{-1}{180}{>}
tangent{0.167}{-90}{=}
tangent{1.334}{0}{<}
tangent{2.974}{-90}{=}
tangent{4.7115}{0}{>}
tangent{6.449}{-90}{=}
tangent{7.852}{0}{<}
tangent{9.256}{-90}{=}
tangent{10.5}{0}{>}
normal{11}
psVehicle[vehicle=SelfDefinedVehicle,ownvehicle=V,showSlope=false,frontwheel=SpokesWheelB,backwheel=SpokesWheelA,rB=1.2,rF=0.9,d=3]{.2}{i}{F}
end{pspicture}}
end{document}
1
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
I presume if the "roller coaster" figure here were done instead withtikz
, then the creature riding in the car would be a duck??
– murray
Nov 25 at 15:43
|
show 1 more comment
up vote
4
down vote
This is just for fun and not to "steal" the check mark from Peter Grill, who IMHO should get it. Conceptually it is basically the same as Jake's pioneering answer. This answer comes with two styles: tangent at
and normal at
, which you can pass to the curve, and utilizes decorations.markings
rather than intersections
. If you want to draw several tangents and/or normals, it is advantageous to use /.list
, as in the MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=7mm,
normal length/.store in=NormalLength,
normal length=7mm}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[tangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[normal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
end{tikzpicture}
end{document}
Just if you are wondering: yes, it is possible to draw the tangent at some specific point the curve runs through. One possibility is to use the tricks of this answer, i.e. decompose the path into segments and attach the tangents/normals to the starting or end points of those. If you want to have this spelled out, please ask a new question, this here is really just for fun.
ADDENDUM: As for your request in the comments... (and yes, I am using Jake's answer, as I mention above)....
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings,intersections}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=3.14cm,
normal length/.store in=NormalLength,
normal length=7mm}
newcounter{tangent}
newcounter{normal}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{tangent}
draw[tangent,name path=tangent-thetangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{normal}
draw[normal,name path=normal-thenormal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [name path=curve,thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
fill[name intersections={of=curve and tangent-2,total=t},cyan]
(intersection-t) circle (2pt);
end{tikzpicture}
end{document}
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
@MathScholar I added something. (I guess on the long run one may have to look at the internals of theintersections
andfillbetween
libraries, which internally compute all sorts of of useful quantities likepgfintersectiongetsolutiontimes
, which however did not make it to the manual.)
– marmot
Nov 24 at 21:04
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
|
show 1 more comment
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
You can use a bit of calculus:
The DrawTangent
macro creates two vertical lines around the given x values and computes the intersection of those and the curve. Then, the tangent can be approximated by the secant between those two intersection points.
Code:
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc,intersections}
newcommand*{DeltaX}{0.01}
newcommand*{DrawTangent}[5]{%
% #1 = draw options
% #2 = name of curve
% #3 = ymin
% #4 = ymax
% #5 = x value at which tangent is to be drawn
path[name path=Vertical Line Left] (#5-DeltaX,#3) -- (#5-DeltaX,#4);
path[name path=Vertical Line Right] (#5+DeltaX,#3) -- (#5+DeltaX,#4);
path [name intersections={of=Vertical Line Left and #2}];
coordinate (X0) at (intersection-1);
path [name intersections={of=Vertical Line Right and #2}];
coordinate (X1) at (intersection-1);
draw [shorten <= -1.00cm, shorten >= -1.00cm, #1] (X0) -- (X1);
}%
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}]
(a) node [below left] {$a$}
(b) node [above right] {$b$};
DrawTangent[red, thick]{curve}{-1}{4}{1.5}
DrawTangent[orange, thick]{curve}{-1}{4}{3.5}
end{tikzpicture}
end{document}
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
@MathScholar: You need to usename path=xxxx
to name the curve (xxxx
in this example), and pass that toDrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.
– Peter Grill
Nov 27 at 21:09
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
add a comment |
up vote
7
down vote
accepted
You can use a bit of calculus:
The DrawTangent
macro creates two vertical lines around the given x values and computes the intersection of those and the curve. Then, the tangent can be approximated by the secant between those two intersection points.
Code:
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc,intersections}
newcommand*{DeltaX}{0.01}
newcommand*{DrawTangent}[5]{%
% #1 = draw options
% #2 = name of curve
% #3 = ymin
% #4 = ymax
% #5 = x value at which tangent is to be drawn
path[name path=Vertical Line Left] (#5-DeltaX,#3) -- (#5-DeltaX,#4);
path[name path=Vertical Line Right] (#5+DeltaX,#3) -- (#5+DeltaX,#4);
path [name intersections={of=Vertical Line Left and #2}];
coordinate (X0) at (intersection-1);
path [name intersections={of=Vertical Line Right and #2}];
coordinate (X1) at (intersection-1);
draw [shorten <= -1.00cm, shorten >= -1.00cm, #1] (X0) -- (X1);
}%
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}]
(a) node [below left] {$a$}
(b) node [above right] {$b$};
DrawTangent[red, thick]{curve}{-1}{4}{1.5}
DrawTangent[orange, thick]{curve}{-1}{4}{3.5}
end{tikzpicture}
end{document}
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
@MathScholar: You need to usename path=xxxx
to name the curve (xxxx
in this example), and pass that toDrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.
– Peter Grill
Nov 27 at 21:09
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
You can use a bit of calculus:
The DrawTangent
macro creates two vertical lines around the given x values and computes the intersection of those and the curve. Then, the tangent can be approximated by the secant between those two intersection points.
Code:
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc,intersections}
newcommand*{DeltaX}{0.01}
newcommand*{DrawTangent}[5]{%
% #1 = draw options
% #2 = name of curve
% #3 = ymin
% #4 = ymax
% #5 = x value at which tangent is to be drawn
path[name path=Vertical Line Left] (#5-DeltaX,#3) -- (#5-DeltaX,#4);
path[name path=Vertical Line Right] (#5+DeltaX,#3) -- (#5+DeltaX,#4);
path [name intersections={of=Vertical Line Left and #2}];
coordinate (X0) at (intersection-1);
path [name intersections={of=Vertical Line Right and #2}];
coordinate (X1) at (intersection-1);
draw [shorten <= -1.00cm, shorten >= -1.00cm, #1] (X0) -- (X1);
}%
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}]
(a) node [below left] {$a$}
(b) node [above right] {$b$};
DrawTangent[red, thick]{curve}{-1}{4}{1.5}
DrawTangent[orange, thick]{curve}{-1}{4}{3.5}
end{tikzpicture}
end{document}
You can use a bit of calculus:
The DrawTangent
macro creates two vertical lines around the given x values and computes the intersection of those and the curve. Then, the tangent can be approximated by the secant between those two intersection points.
Code:
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc,intersections}
newcommand*{DeltaX}{0.01}
newcommand*{DrawTangent}[5]{%
% #1 = draw options
% #2 = name of curve
% #3 = ymin
% #4 = ymax
% #5 = x value at which tangent is to be drawn
path[name path=Vertical Line Left] (#5-DeltaX,#3) -- (#5-DeltaX,#4);
path[name path=Vertical Line Right] (#5+DeltaX,#3) -- (#5+DeltaX,#4);
path [name intersections={of=Vertical Line Left and #2}];
coordinate (X0) at (intersection-1);
path [name intersections={of=Vertical Line Right and #2}];
coordinate (X1) at (intersection-1);
draw [shorten <= -1.00cm, shorten >= -1.00cm, #1] (X0) -- (X1);
}%
begin{document}
begin{tikzpicture}
% Axes
draw [->, name path=x] (-1,0) -- (11,0) node [right] {$x$};
draw [->] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
foreach n in {start,c1,c2,c3,end} fill [black] (n)
circle (2pt) node [below] {};
% join the coordinates
draw [thick,name path=curve] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
% add tangets and dashed lines
foreach c in {1,2,3} {
%draw [dashed] let p1=(cc) in (cc) -- (x1,0) node [below] {$c_c$};
draw ($(cc)-(0.75,0)$) -- ($(cc)+(0.75,0)$) node [midway,above=4mm]{$$}; %{$f'(c_c)=0$};
}
% add a and b
path [name intersections={of={x and curve}, by={a,b}}]
(a) node [below left] {$a$}
(b) node [above right] {$b$};
DrawTangent[red, thick]{curve}{-1}{4}{1.5}
DrawTangent[orange, thick]{curve}{-1}{4}{3.5}
end{tikzpicture}
end{document}
answered Nov 24 at 17:09
Peter Grill
163k24432742
163k24432742
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
@MathScholar: You need to usename path=xxxx
to name the curve (xxxx
in this example), and pass that toDrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.
– Peter Grill
Nov 27 at 21:09
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
add a comment |
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
@MathScholar: You need to usename path=xxxx
to name the curve (xxxx
in this example), and pass that toDrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.
– Peter Grill
Nov 27 at 21:09
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
I really like this answer plus the macro. I will allow other some time for others answer as well but this is what I was looking for!
– MathScholar
Nov 24 at 17:31
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
Hi Peter if I were to name the curve by draw[domain=.5:3.25,smooth,variable=x,black,<->,thick] plot ({x},{.5*(x-1.5)*(x-1.5)+1}); how would the syntax change>
– MathScholar
Nov 27 at 19:52
@MathScholar: You need to use
name path=xxxx
to name the curve (xxxx
in this example), and pass that to DrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.– Peter Grill
Nov 27 at 21:09
@MathScholar: You need to use
name path=xxxx
to name the curve (xxxx
in this example), and pass that to DrawTangent[<draw options>]{xxxx}{<ymin>}{<ymax>}{x}
.– Peter Grill
Nov 27 at 21:09
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Yes I did that and got a horizontal line. I ask as a question as well so you can see the result and program. I thought this would be more easy to do! Here: tex.stackexchange.com/questions/462070/…
– MathScholar
Nov 27 at 21:13
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
Sorry Peter I made a mistake! I got it! I deleted he question
– MathScholar
Nov 27 at 21:19
add a comment |
up vote
6
down vote
A PSTricks solution just for comparison purpose.
documentclass[pstricks]{standalone}
usepackage{pstricks-add,pst-vehicle,tikzducks}
defV{rput(1,1.5){psscalebox{-2 2}{tikz{duck[alien=red]}}}}
defF{2*cos(x)+x/3}
defFp{Derive(1,F)}
deftangent#1#2#3{psplotTangent[linecolor=blue,showpoints]{#1}{.5}{F}uput[#2](*#1 {F}){scriptsize$f'#30$}}
defnormal#1{psplotTangent[linecolor=magenta,Derive={-1/Fp},showpoints]{#1}{.2}{F}}
psset{plotpoints=200}
begin{document}
foreach i in {-0.8,-0.6,...,10.8}{
begin{pspicture}(-2.5,-2)(12.5,6)
psaxes[ticks=none,labels=none,linecolor=gray]{->}(0,0)(-2,-1.5)(11.5,5)[$x$,0][$y$,90]
psplot[linecolor=red]{-1.5}{11}{F}
normal{-1.5}
tangent{-1}{180}{>}
tangent{0.167}{-90}{=}
tangent{1.334}{0}{<}
tangent{2.974}{-90}{=}
tangent{4.7115}{0}{>}
tangent{6.449}{-90}{=}
tangent{7.852}{0}{<}
tangent{9.256}{-90}{=}
tangent{10.5}{0}{>}
normal{11}
psVehicle[vehicle=SelfDefinedVehicle,ownvehicle=V,showSlope=false,frontwheel=SpokesWheelB,backwheel=SpokesWheelA,rB=1.2,rF=0.9,d=3]{.2}{i}{F}
end{pspicture}}
end{document}
1
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
I presume if the "roller coaster" figure here were done instead withtikz
, then the creature riding in the car would be a duck??
– murray
Nov 25 at 15:43
|
show 1 more comment
up vote
6
down vote
A PSTricks solution just for comparison purpose.
documentclass[pstricks]{standalone}
usepackage{pstricks-add,pst-vehicle,tikzducks}
defV{rput(1,1.5){psscalebox{-2 2}{tikz{duck[alien=red]}}}}
defF{2*cos(x)+x/3}
defFp{Derive(1,F)}
deftangent#1#2#3{psplotTangent[linecolor=blue,showpoints]{#1}{.5}{F}uput[#2](*#1 {F}){scriptsize$f'#30$}}
defnormal#1{psplotTangent[linecolor=magenta,Derive={-1/Fp},showpoints]{#1}{.2}{F}}
psset{plotpoints=200}
begin{document}
foreach i in {-0.8,-0.6,...,10.8}{
begin{pspicture}(-2.5,-2)(12.5,6)
psaxes[ticks=none,labels=none,linecolor=gray]{->}(0,0)(-2,-1.5)(11.5,5)[$x$,0][$y$,90]
psplot[linecolor=red]{-1.5}{11}{F}
normal{-1.5}
tangent{-1}{180}{>}
tangent{0.167}{-90}{=}
tangent{1.334}{0}{<}
tangent{2.974}{-90}{=}
tangent{4.7115}{0}{>}
tangent{6.449}{-90}{=}
tangent{7.852}{0}{<}
tangent{9.256}{-90}{=}
tangent{10.5}{0}{>}
normal{11}
psVehicle[vehicle=SelfDefinedVehicle,ownvehicle=V,showSlope=false,frontwheel=SpokesWheelB,backwheel=SpokesWheelA,rB=1.2,rF=0.9,d=3]{.2}{i}{F}
end{pspicture}}
end{document}
1
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
I presume if the "roller coaster" figure here were done instead withtikz
, then the creature riding in the car would be a duck??
– murray
Nov 25 at 15:43
|
show 1 more comment
up vote
6
down vote
up vote
6
down vote
A PSTricks solution just for comparison purpose.
documentclass[pstricks]{standalone}
usepackage{pstricks-add,pst-vehicle,tikzducks}
defV{rput(1,1.5){psscalebox{-2 2}{tikz{duck[alien=red]}}}}
defF{2*cos(x)+x/3}
defFp{Derive(1,F)}
deftangent#1#2#3{psplotTangent[linecolor=blue,showpoints]{#1}{.5}{F}uput[#2](*#1 {F}){scriptsize$f'#30$}}
defnormal#1{psplotTangent[linecolor=magenta,Derive={-1/Fp},showpoints]{#1}{.2}{F}}
psset{plotpoints=200}
begin{document}
foreach i in {-0.8,-0.6,...,10.8}{
begin{pspicture}(-2.5,-2)(12.5,6)
psaxes[ticks=none,labels=none,linecolor=gray]{->}(0,0)(-2,-1.5)(11.5,5)[$x$,0][$y$,90]
psplot[linecolor=red]{-1.5}{11}{F}
normal{-1.5}
tangent{-1}{180}{>}
tangent{0.167}{-90}{=}
tangent{1.334}{0}{<}
tangent{2.974}{-90}{=}
tangent{4.7115}{0}{>}
tangent{6.449}{-90}{=}
tangent{7.852}{0}{<}
tangent{9.256}{-90}{=}
tangent{10.5}{0}{>}
normal{11}
psVehicle[vehicle=SelfDefinedVehicle,ownvehicle=V,showSlope=false,frontwheel=SpokesWheelB,backwheel=SpokesWheelA,rB=1.2,rF=0.9,d=3]{.2}{i}{F}
end{pspicture}}
end{document}
A PSTricks solution just for comparison purpose.
documentclass[pstricks]{standalone}
usepackage{pstricks-add,pst-vehicle,tikzducks}
defV{rput(1,1.5){psscalebox{-2 2}{tikz{duck[alien=red]}}}}
defF{2*cos(x)+x/3}
defFp{Derive(1,F)}
deftangent#1#2#3{psplotTangent[linecolor=blue,showpoints]{#1}{.5}{F}uput[#2](*#1 {F}){scriptsize$f'#30$}}
defnormal#1{psplotTangent[linecolor=magenta,Derive={-1/Fp},showpoints]{#1}{.2}{F}}
psset{plotpoints=200}
begin{document}
foreach i in {-0.8,-0.6,...,10.8}{
begin{pspicture}(-2.5,-2)(12.5,6)
psaxes[ticks=none,labels=none,linecolor=gray]{->}(0,0)(-2,-1.5)(11.5,5)[$x$,0][$y$,90]
psplot[linecolor=red]{-1.5}{11}{F}
normal{-1.5}
tangent{-1}{180}{>}
tangent{0.167}{-90}{=}
tangent{1.334}{0}{<}
tangent{2.974}{-90}{=}
tangent{4.7115}{0}{>}
tangent{6.449}{-90}{=}
tangent{7.852}{0}{<}
tangent{9.256}{-90}{=}
tangent{10.5}{0}{>}
normal{11}
psVehicle[vehicle=SelfDefinedVehicle,ownvehicle=V,showSlope=false,frontwheel=SpokesWheelB,backwheel=SpokesWheelA,rB=1.2,rF=0.9,d=3]{.2}{i}{F}
end{pspicture}}
end{document}
edited Nov 25 at 10:54
answered Nov 24 at 16:28
Artificial Stupidity
4,32611037
4,32611037
1
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
I presume if the "roller coaster" figure here were done instead withtikz
, then the creature riding in the car would be a duck??
– murray
Nov 25 at 15:43
|
show 1 more comment
1
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
I presume if the "roller coaster" figure here were done instead withtikz
, then the creature riding in the car would be a duck??
– murray
Nov 25 at 15:43
1
1
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
Many compliments for your answer. +1.
– Sebastiano
Nov 24 at 16:30
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
This looks good but I am searching for an answer using using TiKz. Thanks AS!
– MathScholar
Nov 24 at 16:34
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
Well, this is certainly nice but of course here you have an analytic expression for the curve. If you have this analytic expression, it is well known how to find the local extremal and tangents and all that, see e.g. here. I thought the challenge here was to do that to curves for which the analytic expression is not known. (This is not to criticize you, just to let you know that there exists quite some literature on this topic on this site.)
– marmot
Nov 24 at 19:53
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
@marmot: Analytic expression is no longer as complicated as the previous one.
– Artificial Stupidity
Nov 25 at 11:04
I presume if the "roller coaster" figure here were done instead with
tikz
, then the creature riding in the car would be a duck??– murray
Nov 25 at 15:43
I presume if the "roller coaster" figure here were done instead with
tikz
, then the creature riding in the car would be a duck??– murray
Nov 25 at 15:43
|
show 1 more comment
up vote
4
down vote
This is just for fun and not to "steal" the check mark from Peter Grill, who IMHO should get it. Conceptually it is basically the same as Jake's pioneering answer. This answer comes with two styles: tangent at
and normal at
, which you can pass to the curve, and utilizes decorations.markings
rather than intersections
. If you want to draw several tangents and/or normals, it is advantageous to use /.list
, as in the MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=7mm,
normal length/.store in=NormalLength,
normal length=7mm}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[tangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[normal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
end{tikzpicture}
end{document}
Just if you are wondering: yes, it is possible to draw the tangent at some specific point the curve runs through. One possibility is to use the tricks of this answer, i.e. decompose the path into segments and attach the tangents/normals to the starting or end points of those. If you want to have this spelled out, please ask a new question, this here is really just for fun.
ADDENDUM: As for your request in the comments... (and yes, I am using Jake's answer, as I mention above)....
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings,intersections}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=3.14cm,
normal length/.store in=NormalLength,
normal length=7mm}
newcounter{tangent}
newcounter{normal}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{tangent}
draw[tangent,name path=tangent-thetangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{normal}
draw[normal,name path=normal-thenormal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [name path=curve,thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
fill[name intersections={of=curve and tangent-2,total=t},cyan]
(intersection-t) circle (2pt);
end{tikzpicture}
end{document}
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
@MathScholar I added something. (I guess on the long run one may have to look at the internals of theintersections
andfillbetween
libraries, which internally compute all sorts of of useful quantities likepgfintersectiongetsolutiontimes
, which however did not make it to the manual.)
– marmot
Nov 24 at 21:04
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
|
show 1 more comment
up vote
4
down vote
This is just for fun and not to "steal" the check mark from Peter Grill, who IMHO should get it. Conceptually it is basically the same as Jake's pioneering answer. This answer comes with two styles: tangent at
and normal at
, which you can pass to the curve, and utilizes decorations.markings
rather than intersections
. If you want to draw several tangents and/or normals, it is advantageous to use /.list
, as in the MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=7mm,
normal length/.store in=NormalLength,
normal length=7mm}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[tangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[normal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
end{tikzpicture}
end{document}
Just if you are wondering: yes, it is possible to draw the tangent at some specific point the curve runs through. One possibility is to use the tricks of this answer, i.e. decompose the path into segments and attach the tangents/normals to the starting or end points of those. If you want to have this spelled out, please ask a new question, this here is really just for fun.
ADDENDUM: As for your request in the comments... (and yes, I am using Jake's answer, as I mention above)....
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings,intersections}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=3.14cm,
normal length/.store in=NormalLength,
normal length=7mm}
newcounter{tangent}
newcounter{normal}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{tangent}
draw[tangent,name path=tangent-thetangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{normal}
draw[normal,name path=normal-thenormal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [name path=curve,thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
fill[name intersections={of=curve and tangent-2,total=t},cyan]
(intersection-t) circle (2pt);
end{tikzpicture}
end{document}
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
@MathScholar I added something. (I guess on the long run one may have to look at the internals of theintersections
andfillbetween
libraries, which internally compute all sorts of of useful quantities likepgfintersectiongetsolutiontimes
, which however did not make it to the manual.)
– marmot
Nov 24 at 21:04
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
|
show 1 more comment
up vote
4
down vote
up vote
4
down vote
This is just for fun and not to "steal" the check mark from Peter Grill, who IMHO should get it. Conceptually it is basically the same as Jake's pioneering answer. This answer comes with two styles: tangent at
and normal at
, which you can pass to the curve, and utilizes decorations.markings
rather than intersections
. If you want to draw several tangents and/or normals, it is advantageous to use /.list
, as in the MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=7mm,
normal length/.store in=NormalLength,
normal length=7mm}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[tangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[normal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
end{tikzpicture}
end{document}
Just if you are wondering: yes, it is possible to draw the tangent at some specific point the curve runs through. One possibility is to use the tricks of this answer, i.e. decompose the path into segments and attach the tangents/normals to the starting or end points of those. If you want to have this spelled out, please ask a new question, this here is really just for fun.
ADDENDUM: As for your request in the comments... (and yes, I am using Jake's answer, as I mention above)....
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings,intersections}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=3.14cm,
normal length/.store in=NormalLength,
normal length=7mm}
newcounter{tangent}
newcounter{normal}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{tangent}
draw[tangent,name path=tangent-thetangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{normal}
draw[normal,name path=normal-thenormal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [name path=curve,thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
fill[name intersections={of=curve and tangent-2,total=t},cyan]
(intersection-t) circle (2pt);
end{tikzpicture}
end{document}
This is just for fun and not to "steal" the check mark from Peter Grill, who IMHO should get it. Conceptually it is basically the same as Jake's pioneering answer. This answer comes with two styles: tangent at
and normal at
, which you can pass to the curve, and utilizes decorations.markings
rather than intersections
. If you want to draw several tangents and/or normals, it is advantageous to use /.list
, as in the MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=7mm,
normal length/.store in=NormalLength,
normal length=7mm}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[tangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {draw[normal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
end{tikzpicture}
end{document}
Just if you are wondering: yes, it is possible to draw the tangent at some specific point the curve runs through. One possibility is to use the tricks of this answer, i.e. decompose the path into segments and attach the tangents/normals to the starting or end points of those. If you want to have this spelled out, please ask a new question, this here is really just for fun.
ADDENDUM: As for your request in the comments... (and yes, I am using Jake's answer, as I mention above)....
documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.markings,intersections}
begin{document}
pgfkeys{tikz/.cd,
tangent length/.store in=TangentLength,
tangent length=3.14cm,
normal length/.store in=NormalLength,
normal length=7mm}
newcounter{tangent}
newcounter{normal}
tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{tangent}
draw[tangent,name path=tangent-thetangent] (-TangentLength,0) -- (TangentLength,0);
fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {stepcounter{normal}
draw[normal,name path=normal-thenormal] (0,-NormalLength) -- (0,NormalLength);
fill[normal] (0,0) circle (2pt);}}}},
}
begin{tikzpicture}
% Axes
draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
node at (0,0) [below left] {$0$};
% Points
coordinate (start) at (1,-0.8);
coordinate (c1) at (3,3);
coordinate (c2) at (5.5,1.5);
coordinate (c3) at (8,4);
coordinate (end) at (10.5,-0.8);
% show the points
% foreach n in {start,c1,c2,c3,end} fill [black] (n)
% circle (2pt) node [below] {};
% join the coordinates
draw [name path=curve,thick,tangent at/.list={0.15,0.3,...,0.75},
normal at/.list={0.25,0.4,...,0.7}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
fill[name intersections={of=curve and tangent-2,total=t},cyan]
(intersection-t) circle (2pt);
end{tikzpicture}
end{document}
edited Nov 24 at 20:59
answered Nov 24 at 19:49
marmot
80.4k491172
80.4k491172
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
@MathScholar I added something. (I guess on the long run one may have to look at the internals of theintersections
andfillbetween
libraries, which internally compute all sorts of of useful quantities likepgfintersectiongetsolutiontimes
, which however did not make it to the manual.)
– marmot
Nov 24 at 21:04
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
|
show 1 more comment
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
@MathScholar I added something. (I guess on the long run one may have to look at the internals of theintersections
andfillbetween
libraries, which internally compute all sorts of of useful quantities likepgfintersectiongetsolutiontimes
, which however did not make it to the manual.)
– marmot
Nov 24 at 21:04
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
this looks fantastic as well and uses methods from tex.stackexchange.com/questions/25928/… I believe. How can I extend the second tangent starting from the left and use the intersection, calc package to show where it intersects the curve further towards the right?
– MathScholar
Nov 24 at 20:50
@MathScholar I added something. (I guess on the long run one may have to look at the internals of the
intersections
and fillbetween
libraries, which internally compute all sorts of of useful quantities like pgfintersectiongetsolutiontimes
, which however did not make it to the manual.)– marmot
Nov 24 at 21:04
@MathScholar I added something. (I guess on the long run one may have to look at the internals of the
intersections
and fillbetween
libraries, which internally compute all sorts of of useful quantities like pgfintersectiongetsolutiontimes
, which however did not make it to the manual.)– marmot
Nov 24 at 21:04
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
per your request I will give the check to Peter. Both posts are extremely helpful. Thanks Marmot!
– MathScholar
Nov 24 at 22:17
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@MathScholar Thanks! (I generally do not like if a question that has already an answer that is to the point gets a second answer, which is not to the point or just merely a repetition, like e.g. here. This brings unnecessary tension between the users IMHO, and the last thing I want to do is to step others on the feet.)
– marmot
Nov 24 at 22:32
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
@Hi Marmot, if I continue to extend the tangent to the right and fix the left side, there will be another intersection of the curve and tangent. Why does the intersection not get detected by the program?
– MathScholar
Nov 24 at 23:46
|
show 1 more 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f461573%2ftangent-lines-diagram-along-smooth-curve%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
I sense without having a concrete equation for the graph above this will be a challenge. Unless there is another programming tool for TiKz?
– MathScholar
Nov 24 at 16:32
Marmot mentions tex.stackexchange.com/questions/25928/…
– MathScholar
Nov 24 at 16:40