Skip to main content
edited title
Link
Jasper
  • 12k
  • 2
  • 12
  • 49

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve using pgfmath or Lua?

added 75 characters in body; edited tags
Source Link
Jasper
  • 12k
  • 2
  • 12
  • 49

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

My goal is to avoid using an approach which first tessellates curves into line segments, and tests each line segment pair. That is O(n^2). I want something which can scale.

I think Lua is appropriate for this, based on evidence in the comments.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

My goal is to avoid using an approach which first tessellates curves into line segments, and tests each line segment pair. That is O(n^2). I want something which can scale.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

My goal is to avoid using an approach which first tessellates curves into line segments, and tests each line segment pair. That is O(n^2). I want something which can scale.

I think Lua is appropriate for this, based on evidence in the comments.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

deleted 12 characters in body
Source Link
Jasper
  • 12k
  • 2
  • 12
  • 49

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

I am not interested in fudging it with the intersections library. I wantMy goal is to calculate or iteratively approximate the resultavoid using an approach which first tessellates curves into line segments, and tests each line segment pair.

  That is O(n^2). I want to use pgfmath, and if that's too hard, then Luasomething which can scale.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

I am not interested in fudging it with the intersections library. I want to calculate or iteratively approximate the result.

  I want to use pgfmath, and if that's too hard, then Lua.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

My goal is to avoid using an approach which first tessellates curves into line segments, and tests each line segment pair. That is O(n^2). I want something which can scale.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

Became Hot Network Question
Source Link
Jasper
  • 12k
  • 2
  • 12
  • 49
Loading