Draw tangent of an arbitrary curve at intersections












5















I have this picture:




enter image description here




and I want to draw a tangent line at each of the marked intersections. I have found some answers (and examples in the TikZ manual) using the decorations.markings library. The thing is that (from what I understood) this library only knows the tangent of a curve given the position, from 0 to 1, so I'd have to guess where, in the length of the curve, the intersection is, but I'd rather do that automagically :)



I thought about mapping the coordinate of the intersection to a normalised [0, 1] value, but I couldn't figure out how to do that either.



Code for the picture:



documentclass[tikz]{standalone}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
end{tikzpicture}
end{document}


I think that this problem is fairly common, but I browsed plenty of intersections/tangents/markings questions but couldn't find what I'm trying to do, so sorry if it is a duplicate.










share|improve this question


















  • 1





    Like tex.stackexchange.com/a/432541/121799 ?

    – marmot
    Feb 28 at 19:20






  • 1





    Have you seen this question and its answers? tex.stackexchange.com/q/461573/138900

    – AndréC
    Feb 28 at 19:21






  • 3





    Additionally maybe helpful: Tangent Lines Diagram Along Smooth Curve

    – AndréC
    Feb 28 at 20:00


















5















I have this picture:




enter image description here




and I want to draw a tangent line at each of the marked intersections. I have found some answers (and examples in the TikZ manual) using the decorations.markings library. The thing is that (from what I understood) this library only knows the tangent of a curve given the position, from 0 to 1, so I'd have to guess where, in the length of the curve, the intersection is, but I'd rather do that automagically :)



I thought about mapping the coordinate of the intersection to a normalised [0, 1] value, but I couldn't figure out how to do that either.



Code for the picture:



documentclass[tikz]{standalone}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
end{tikzpicture}
end{document}


I think that this problem is fairly common, but I browsed plenty of intersections/tangents/markings questions but couldn't find what I'm trying to do, so sorry if it is a duplicate.










share|improve this question


















  • 1





    Like tex.stackexchange.com/a/432541/121799 ?

    – marmot
    Feb 28 at 19:20






  • 1





    Have you seen this question and its answers? tex.stackexchange.com/q/461573/138900

    – AndréC
    Feb 28 at 19:21






  • 3





    Additionally maybe helpful: Tangent Lines Diagram Along Smooth Curve

    – AndréC
    Feb 28 at 20:00
















5












5








5








I have this picture:




enter image description here




and I want to draw a tangent line at each of the marked intersections. I have found some answers (and examples in the TikZ manual) using the decorations.markings library. The thing is that (from what I understood) this library only knows the tangent of a curve given the position, from 0 to 1, so I'd have to guess where, in the length of the curve, the intersection is, but I'd rather do that automagically :)



I thought about mapping the coordinate of the intersection to a normalised [0, 1] value, but I couldn't figure out how to do that either.



Code for the picture:



documentclass[tikz]{standalone}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
end{tikzpicture}
end{document}


I think that this problem is fairly common, but I browsed plenty of intersections/tangents/markings questions but couldn't find what I'm trying to do, so sorry if it is a duplicate.










share|improve this question














I have this picture:




enter image description here




and I want to draw a tangent line at each of the marked intersections. I have found some answers (and examples in the TikZ manual) using the decorations.markings library. The thing is that (from what I understood) this library only knows the tangent of a curve given the position, from 0 to 1, so I'd have to guess where, in the length of the curve, the intersection is, but I'd rather do that automagically :)



I thought about mapping the coordinate of the intersection to a normalised [0, 1] value, but I couldn't figure out how to do that either.



Code for the picture:



documentclass[tikz]{standalone}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
end{tikzpicture}
end{document}


I think that this problem is fairly common, but I browsed plenty of intersections/tangents/markings questions but couldn't find what I'm trying to do, so sorry if it is a duplicate.







tikz-pgf intersections






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 28 at 19:17









Phelype OleinikPhelype Oleinik

24k54688




24k54688








  • 1





    Like tex.stackexchange.com/a/432541/121799 ?

    – marmot
    Feb 28 at 19:20






  • 1





    Have you seen this question and its answers? tex.stackexchange.com/q/461573/138900

    – AndréC
    Feb 28 at 19:21






  • 3





    Additionally maybe helpful: Tangent Lines Diagram Along Smooth Curve

    – AndréC
    Feb 28 at 20:00
















  • 1





    Like tex.stackexchange.com/a/432541/121799 ?

    – marmot
    Feb 28 at 19:20






  • 1





    Have you seen this question and its answers? tex.stackexchange.com/q/461573/138900

    – AndréC
    Feb 28 at 19:21






  • 3





    Additionally maybe helpful: Tangent Lines Diagram Along Smooth Curve

    – AndréC
    Feb 28 at 20:00










1




1





Like tex.stackexchange.com/a/432541/121799 ?

– marmot
Feb 28 at 19:20





Like tex.stackexchange.com/a/432541/121799 ?

– marmot
Feb 28 at 19:20




1




1





Have you seen this question and its answers? tex.stackexchange.com/q/461573/138900

– AndréC
Feb 28 at 19:21





Have you seen this question and its answers? tex.stackexchange.com/q/461573/138900

– AndréC
Feb 28 at 19:21




3




3





Additionally maybe helpful: Tangent Lines Diagram Along Smooth Curve

– AndréC
Feb 28 at 20:00







Additionally maybe helpful: Tangent Lines Diagram Along Smooth Curve

– AndréC
Feb 28 at 20:00












1 Answer
1






active

oldest

votes


















7














This is a possible way. If you do not want to load pgfplots, I am afraid it will be considerably more effort.



How does this proposal work?




  1. The pgplots (!) library fillbetween allows us to decompose paths into intersection segments. These are called A1 and A2 in the examples below, and can be reversed, if needed.

  2. Once we have such an intersection segment, the problem boils down to attaching tangents at the ends of these segments, which is a long-solved problem, see this answer.


These codes illustrate this.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,blue,
name path=middle arc,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
end{tikzpicture}
end{document}


enter image description here



You can do that with more intersections, too. You only need to add the tangents at the appropriate intersection segments.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
path [%draw,green,thick,
intersection segments={
of=eta and eta0,
sequence={A2}
},
postaction={tangent at/.list={1}}];
end{tikzpicture}
end{document}


enter image description here



Of course, this can be automatized.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t},
/utils/exec={xdefNumIntersection{t}}]
foreach s in {1,...,t}{
(intersection-s) circle (1pt) };
foreach X [count=Y starting from 0] in {1,...,NumIntersection}
{
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={AY}
},
postaction={tangent at=1}];
}
end{tikzpicture}
end{document}


(Same result as above.)






share|improve this answer





















  • 1





    Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

    – Phelype Oleinik
    Feb 28 at 19:44











  • @PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

    – marmot
    Feb 28 at 19:54






  • 1





    Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

    – Phelype Oleinik
    Feb 28 at 20:42






  • 1





    @PhelypeOleinik I added a slightly more automatized version.

    – marmot
    Feb 28 at 20:58











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477206%2fdraw-tangent-of-an-arbitrary-curve-at-intersections%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














This is a possible way. If you do not want to load pgfplots, I am afraid it will be considerably more effort.



How does this proposal work?




  1. The pgplots (!) library fillbetween allows us to decompose paths into intersection segments. These are called A1 and A2 in the examples below, and can be reversed, if needed.

  2. Once we have such an intersection segment, the problem boils down to attaching tangents at the ends of these segments, which is a long-solved problem, see this answer.


These codes illustrate this.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,blue,
name path=middle arc,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
end{tikzpicture}
end{document}


enter image description here



You can do that with more intersections, too. You only need to add the tangents at the appropriate intersection segments.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
path [%draw,green,thick,
intersection segments={
of=eta and eta0,
sequence={A2}
},
postaction={tangent at/.list={1}}];
end{tikzpicture}
end{document}


enter image description here



Of course, this can be automatized.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t},
/utils/exec={xdefNumIntersection{t}}]
foreach s in {1,...,t}{
(intersection-s) circle (1pt) };
foreach X [count=Y starting from 0] in {1,...,NumIntersection}
{
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={AY}
},
postaction={tangent at=1}];
}
end{tikzpicture}
end{document}


(Same result as above.)






share|improve this answer





















  • 1





    Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

    – Phelype Oleinik
    Feb 28 at 19:44











  • @PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

    – marmot
    Feb 28 at 19:54






  • 1





    Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

    – Phelype Oleinik
    Feb 28 at 20:42






  • 1





    @PhelypeOleinik I added a slightly more automatized version.

    – marmot
    Feb 28 at 20:58
















7














This is a possible way. If you do not want to load pgfplots, I am afraid it will be considerably more effort.



How does this proposal work?




  1. The pgplots (!) library fillbetween allows us to decompose paths into intersection segments. These are called A1 and A2 in the examples below, and can be reversed, if needed.

  2. Once we have such an intersection segment, the problem boils down to attaching tangents at the ends of these segments, which is a long-solved problem, see this answer.


These codes illustrate this.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,blue,
name path=middle arc,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
end{tikzpicture}
end{document}


enter image description here



You can do that with more intersections, too. You only need to add the tangents at the appropriate intersection segments.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
path [%draw,green,thick,
intersection segments={
of=eta and eta0,
sequence={A2}
},
postaction={tangent at/.list={1}}];
end{tikzpicture}
end{document}


enter image description here



Of course, this can be automatized.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t},
/utils/exec={xdefNumIntersection{t}}]
foreach s in {1,...,t}{
(intersection-s) circle (1pt) };
foreach X [count=Y starting from 0] in {1,...,NumIntersection}
{
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={AY}
},
postaction={tangent at=1}];
}
end{tikzpicture}
end{document}


(Same result as above.)






share|improve this answer





















  • 1





    Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

    – Phelype Oleinik
    Feb 28 at 19:44











  • @PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

    – marmot
    Feb 28 at 19:54






  • 1





    Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

    – Phelype Oleinik
    Feb 28 at 20:42






  • 1





    @PhelypeOleinik I added a slightly more automatized version.

    – marmot
    Feb 28 at 20:58














7












7








7







This is a possible way. If you do not want to load pgfplots, I am afraid it will be considerably more effort.



How does this proposal work?




  1. The pgplots (!) library fillbetween allows us to decompose paths into intersection segments. These are called A1 and A2 in the examples below, and can be reversed, if needed.

  2. Once we have such an intersection segment, the problem boils down to attaching tangents at the ends of these segments, which is a long-solved problem, see this answer.


These codes illustrate this.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,blue,
name path=middle arc,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
end{tikzpicture}
end{document}


enter image description here



You can do that with more intersections, too. You only need to add the tangents at the appropriate intersection segments.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
path [%draw,green,thick,
intersection segments={
of=eta and eta0,
sequence={A2}
},
postaction={tangent at/.list={1}}];
end{tikzpicture}
end{document}


enter image description here



Of course, this can be automatized.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t},
/utils/exec={xdefNumIntersection{t}}]
foreach s in {1,...,t}{
(intersection-s) circle (1pt) };
foreach X [count=Y starting from 0] in {1,...,NumIntersection}
{
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={AY}
},
postaction={tangent at=1}];
}
end{tikzpicture}
end{document}


(Same result as above.)






share|improve this answer















This is a possible way. If you do not want to load pgfplots, I am afraid it will be considerably more effort.



How does this proposal work?




  1. The pgplots (!) library fillbetween allows us to decompose paths into intersection segments. These are called A1 and A2 in the examples below, and can be reversed, if needed.

  2. Once we have such an intersection segment, the problem boils down to attaching tangents at the ends of these segments, which is a long-solved problem, see this answer.


These codes illustrate this.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2) coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,blue,
name path=middle arc,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
end{tikzpicture}
end{document}


enter image description here



You can do that with more intersections, too. You only need to add the tangents at the appropriate intersection segments.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t}]
foreach s in {1,...,t}{ (intersection-s) circle (1pt) };
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={A1}
},
postaction={tangent at/.list={0,1}}];
path [%draw,green,thick,
intersection segments={
of=eta and eta0,
sequence={A2}
},
postaction={tangent at/.list={1}}];
end{tikzpicture}
end{document}


enter image description here



Of course, this can be automatized.



documentclass[tikz]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{decorations.markings}
begin{document}
begin{tikzpicture}[tangent at/.style={% cf. https://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz/25940#25940
decoration={ markings,
mark =at position #1 with {draw[purple,-latex](0,0) -- (0.5,0);},
}, decorate
}]

draw (0, 0.2) .. controls ++(0.5,0.75) and ++(-0.5,-0.75) .. (1,0.2)
coordinate (LP1);
draw [xshift=1cm, blue, name path=eta]
(0, 0.3) .. controls ++(0.5,0.75) and ++(-0.5,0) .. (1.0,-0.4)
.. controls ++(0.3,0) and ++(-0.3,0) .. (1.6, 0.3)
.. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) coordinate (LP2);
draw [gray, name path=eta0] (LP1) -- (LP1-|LP2);
draw [red, name intersections={of=eta and eta0,total=t},
/utils/exec={xdefNumIntersection{t}}]
foreach s in {1,...,t}{
(intersection-s) circle (1pt) };
foreach X [count=Y starting from 0] in {1,...,NumIntersection}
{
path [%draw,red,thick,
intersection segments={
of=eta and eta0,
sequence={AY}
},
postaction={tangent at=1}];
}
end{tikzpicture}
end{document}


(Same result as above.)







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 28 at 20:57

























answered Feb 28 at 19:32









marmotmarmot

106k5129243




106k5129243








  • 1





    Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

    – Phelype Oleinik
    Feb 28 at 19:44











  • @PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

    – marmot
    Feb 28 at 19:54






  • 1





    Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

    – Phelype Oleinik
    Feb 28 at 20:42






  • 1





    @PhelypeOleinik I added a slightly more automatized version.

    – marmot
    Feb 28 at 20:58














  • 1





    Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

    – Phelype Oleinik
    Feb 28 at 19:44











  • @PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

    – marmot
    Feb 28 at 19:54






  • 1





    Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

    – Phelype Oleinik
    Feb 28 at 20:42






  • 1





    @PhelypeOleinik I added a slightly more automatized version.

    – marmot
    Feb 28 at 20:58








1




1





Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

– Phelype Oleinik
Feb 28 at 19:44





Excellent! I was trying (and failing) to understand the link you posted in the comments when you answered. pgfplots won't be a problem at all. I hate to be the “just do this one more thing” user but, how do I add the intersection to an arbitrary number of intersections? For example, if I add .. controls ++(0.6,0) and ++(-0.6,0) .. (2.8,-0.3) to the end of the blue curve (before coordinate). I tried the tangent at/.list thingy, but apparently it doesn't do what I thought it did :/

– Phelype Oleinik
Feb 28 at 19:44













@PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

– marmot
Feb 28 at 19:54





@PhelypeOleinik No problem! I added an explanation (which I should have done right away...), and added the example you suggested.

– marmot
Feb 28 at 19:54




1




1





Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

– Phelype Oleinik
Feb 28 at 20:42





Ooh, now I got it. I completely overlooked the sequence thing. Thanks a lot :D

– Phelype Oleinik
Feb 28 at 20:42




1




1





@PhelypeOleinik I added a slightly more automatized version.

– marmot
Feb 28 at 20:58





@PhelypeOleinik I added a slightly more automatized version.

– marmot
Feb 28 at 20:58


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477206%2fdraw-tangent-of-an-arbitrary-curve-at-intersections%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?