13

I need to draw lines that are parallel to a curve starting at a point.

The curve could be a curve drawn using 3 point as my example below did, but alternatively could be a curve drawn using the \draw () .. controls () and () .. () command. Preferably it would work either way.

This is the picture of what I am after:

enter image description here

Explanation

I have to curves, u_0 and u_1, and a point I_0. I want to find the line that goes from this point (I_0) and is tangent to the first curve (u_0), and the line that goes from (I_0) and is tangent to the second curve (u_1).

Then, I want to find a line that is parallel to the line tangent to (u_1), and this line needs to be tangent to (u_0). If the line can start and stop at the axis without using the shorten commands even better.

For now, I found the tangents and the start and finish points of the parallel line with trial and error, but I have dozens of such pictures to drawn and I need a better way of doing this.

Here is my code:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
    % axes
    \coordinate (origin) at (0,0);
    \draw (origin) -- (0,6.5) node[left]{$x_{2}$};
    \draw (origin) -- (9.5,0) node[below]{$x_{1}$};
    % u_0
    \node (e) at (2.2,4.9) {};
    \node (f) at (3,3) {};
    \node (g) at (5,2.3) {};
    \draw[thick] plot[smooth,tension=0.9] coordinates {(e) (f) (g)} node[right]{$u_{0}$};
    % u_1
    \node (h) at (1.5,4.2) {};
    \node (b) at (2.4,2.3) {};
    \node (j) at (4.4,1.6) {};
    \draw[thick] plot[smooth,tension=0.9] coordinates {(h) (b) (j)} node[right]{$u_{1}$};
    % first budget line (I_0 to p_0)
    \coordinate[label=left:{\scriptsize$I_{0}$}] (i0) at (0,4.65);
    \draw (i0) -- (8.1,0); 
    % second budget line (I_0 to p_1)
    \coordinate (d) at (4.67,0) {};
    \draw (i0) -- (d);
    % dashed line
    \draw[densely dashed,style={shorten >=2.8cm,shorten <=-4.64cm}] (2.68,3.3)   -- +($(i0)-(d)$);
\end{tikzpicture}
\end{document}
Vivi
  • 26,953
  • 31
  • 77
  • 79
  • @PeterGrill but wouldn't I have to specify the point in the curve the tangent line has to go through? (let me know if I misunderstood it). I tried that, but it is not really what I want. I want to specify a point outside of the curve (I_0), and I want a line tangent to the curve, and I don't care where in the curve the tangent point is (what I care about is the point outside of the curve, I_0) – Vivi Mar 15 '12 at 02:29
  • Ok, that makes sense. I guess it comes down to figuring out the math to compute the tangent... – Peter Grill Mar 15 '12 at 02:34
  • You can try using the tkz-fct package. It can compute the tangent of a curve. It uses Gnuplot. – Frédéric Mar 15 '12 at 02:35
  • One way of doing this (but extremely inefficient) would be to take samples points on the curve, and iterate over the tangents to the curve at that point, and find all the points on the curve with the minimum (within some threshold) distance from the tangent line to the given point (there may be more than one), and then draw those lines. But, there must be an easier way. – Peter Grill Mar 15 '12 at 02:47
  • tkz-fct can not do anything in this situation. It needs an explicit formula. Certain conditions are required for the existence of tangents. I think it's difficult to avoid trial and error. – Alain Matthes Mar 15 '12 at 06:44
  • @PeterGrill yes, I think I really should try and use math, starting with the drawing of the curves. The theory I am trying to show in the pictures is all backed up by math. If I took the time to find the equation for the utility curves (the u_0 and u_1 curves) everything else would follow pretty easily. The problem for me was getting the equation of the curve that looked right and fitted in the axes the way I wanted. It seems like I should just do that... – Vivi Mar 15 '12 at 09:10
  • @Altermundus Perhaps I could avoid trial and error if I draw the u curves using an equation rather than plot or controls? – Vivi Mar 15 '12 at 09:11
  • @Vivi yes it's better using equations. Perhaps I can find a solution with fp. Logically the equations are function polynomial of degree 2 or 3 and in this case it's relatively easy with a paper and a pencil, with TeX, it's more difficult :) First you need to find a tangent at a curve from an extern point to get a slope; then you need to find the point of another curve where a tangent has the last slope. – Alain Matthes Mar 15 '12 at 10:14
  • @Altermundus The u functions would be something like u = ln(x1) + ln(x2) (they need to have the first derivatives positive and second derivatives negative -> more of one good gives you more utility, but the more of one good you have, the less extra utility you get for more of that good). Then the curves are drawn for a given utility, that is for u = k with k a constant. It is not too difficult, I just couldn't get a curve that would fit in the axes. But from what I can see, even though there is a big fixed cost to getting the right function, in the long run I will save time if I just do it... – Vivi Mar 15 '12 at 10:40
  • Once I get this function it will be piece of cake getting the tangents... Maybe it is a good excuse to finally learn microeconomics (I was never good at it...) – Vivi Mar 15 '12 at 10:40
  • piece of cake ? If you like cakes with a lot of cream and chocolate ! seriously, it depends of the functions – Alain Matthes Mar 15 '12 at 10:48
  • @Altermundus uh-oh... OK, maybe I shouldn't get too excited. I will work on this in the next few days, and make sure I let you know if I am successful (I will probably post one or two more questions on that anyway). Thanks heaps for the help :) – Vivi Mar 15 '12 at 10:53
  • Ok I have time to clean my answer ! – Alain Matthes Mar 15 '12 at 10:59
  • I think an automated approach as I suggested above would work, but might take some time to run. Before I attempt that, for your case is there always only one line tangent to the curve and through the point? – Peter Grill Mar 15 '12 at 15:54
  • Ok, after some more thought I think it is possible to automate this without requiring a equation for the curve. But, before I attempt to write this code have two questions: 1. Will there ever be the case where there are two tangents of the curve that go thru the point? 2. Would you be ok if it required you to provide some guess as to the range where the tangent would be? You could of course just give the domain as the guess of the range but that might take longer -- so this may not be an issue, but thought I would ask first. – Peter Grill Mar 16 '12 at 00:46
  • two distinct tangents that go through the same point in a curve? No. This is what I am trying to avoid: I want to show very clearly that the tangents points change when the budget constraint changes. 2. You mean the range in a general way, for example, the numbers between 0 and 6, or do you want the exact y coordinate? If the former, no problem; if the latter, it wouldn't help, I think (since if I knew the y number, I could easily figure out the x number).
  • – Vivi Mar 16 '12 at 02:43