5

I was giving luadraw my first attempt, with extreme hard-working in French documentation(Non-naive English and French language speaker...)😭....

Now I want to draw the tangent line of "x=0.5" in the following example:

\documentclass{standalone}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{name=implicit_function}
    local g = graph:new{window={-3,3,-3,3},size={10,10}}
    g:Linecap("round")
    local F = function(x,y) return x^2+y^2+x*y-1 end
    g:Dimplicit(F,{draw_options="thick"})
    g:Dgradbox(
        {Z(-2,-2),Z(2,2),1,1},{grid=true,title="\\textbf{Implicit Function Plot}"}
    )
    -- g:Dtangent(F,0.5,3) -- This doesn't work...
    g:Show()
\end{luadraw}
\end{document}

result

But in the documentation, I only found:

  • g:Dtangent(p, t0, long, draw_options)
  • g:DtangentC(f, x0, long, draw_options)

which seemed not easy to handle the implicit funtion like above. Is there exist elegant solution with luadraw?

1 Answer 1

7

Note: in Lua the comment symbol is -- and not %. There is no (yet) predefined function for tangents to implicit curves, but one can be written:

\documentclass{standalone}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{name=implicit_function}
    local g = graph:new{window={-3,3,-3,3},size={10,10}}
    g:Linecap("round")
    
    local DtangentI = function(f,x0,y0,len,draw_options) -- f:(x,y()) -> f(x,y)
        -- We assume that f(x0,y0)=0! 
        local h = 1e-6
        local A = Z(x0,y0)
        local a,b = (f(x0+h,y0)-f(x0-h,y0))/(2*h), (f(x0,y0+h)-f(x0,y0-h))/(2*h)
        local v = Z(-b,a)
        if len == nil then 
            g:Dline({A,v},draw_options)
        else
            local u = len*v/cpx.abs(v)/2
            g:Dseg({A-u,A+u},draw_options) -- on renvoie un segment
        end
    end
    
    local F = function(x,y) return x^2+y^2+x*y-1 end
    g:Dimplicit(F,{draw_options="thick"})
    g:Dgradbox(
        {Z(-2,-2),Z(2,2),1,1},{grid=true,title="\\textbf{Implicit Function Plot}"}
    )
    local x0 = 1/math.sqrt(3) 
    local L = solve(function(t) return F(x0,t) end,-2,2)
    for _, y in ipairs(L) do
        DtangentI(F,x0,y,2,"thick,red") -- This work!!
    end
    g:Show()
\end{luadraw}
\end{document}

enter image description here

Note 2: There are actually several questions in your question, because you also want the points of the implicit curve with abscissa 0.5...

3
  • Sorry, (i)the comment line is the last I added with vscode's "ctrl+/", but LaTeXWorkshop now is still not recognized it, and I copy it here without checking twice, and now edited. (ii) yep, it actually consisted not only-one question like "want the points of the implicit curve with abscissa 0.5...", but I origianally think that luadraw have built-in function to do so(but I didn't find it...) I would keep my question to focus only one point on this site as possible, thanks to your remind! This is a very good learning material for me! Many thanks! Commented Aug 31, 2025 at 11:43
  • I also found the father of DtangentI at here. I hope that, if possible, this could be absorded into powerful luadraw. Thank! Commented Aug 31, 2025 at 12:04
  • 1
    You should draw the gradbox first. Commented Aug 31, 2025 at 15:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.