9

I'm new to luadraw and I'm trying to recreate the diagram below:

target image, a tetrahedron with vertices at the origin, (8,0,0), (0,6,0), and (0,0,4)

Here is my code so far, and the result:

% !TEX TS-program = LuaLaTeX
\documentclass{standalone}
\usepackage[3d]{luadraw}
\begin{document}
\begin{luadraw}{name=wedge}
    local a, b, c = 8, 6, 4
    local xmax, ymax, zmax = a+1, b+1, c+1
    local g = graph3d:new{
      window3d = {0,xmax,0,ymax,0,zmax},
      viewdir = {30,60},
      size={10,10,0}
    }
    local xIntcpt, yIntcpt, zIntcpt = M(a,0,0), M(0,b,0), M(0,0,c)
    local P = M(4,0,0)
    local Q = interDD({P,vecJ},{xIntcpt,yIntcpt-xIntcpt})
    local R = interDD({P,vecK},{xIntcpt,zIntcpt-xIntcpt})
    g:Dscene3d(
      g:addPolyline({
        {Origin,xmax*vecI},
        {Origin,ymax*vecJ},
        {Origin,zmax*vecK},
      }),
      g:addPolyline(
        {xIntcpt,yIntcpt,zIntcpt},
        {close=true,color="cyan"}),
      g:addFacet(
        {P,Q,R},
        {color="cyan",opacity=0.5}
      ), 
      g:addPolyline(
            {P,Q,R},
                    {close=true,color="cyan",style="dashed"}
                ),
      g:addLabel(
        "\\(x\\)",P,{pos="NW",dist=0.1},
        a,xIntcpt,{pos="NW",dist=0.1},
        b,yIntcpt,{pos="N",dist=0.1},
        c,zIntcpt,{pos="NW",dist=0.1}
      )
    )
    g:Show()
\end{luadraw}
\end{document}

sample code output

The issue, as you can see, is that the point (0,6,0) is out of frame. I tried increasing ymax, that seems to have no effect. I tried changing the width in the size option, but that only stretches the diagram horizontally. I have tried different viewdir options, but they all cut the diagram off at one edge.

I'm sure it's something basic that I'm missing, but I'm too much of a novice to notice. Any clues?

0

2 Answers 2

9

If you want finer control over the composition, you can specify window manually instead of using adjust2d=true; for example, window = {-6,8,-6,7}, though the exact bounds may need some tuning.

\documentclass{standalone}
\usepackage[3d]{luadraw}
\begin{document}
\begin{luadraw}{name=wedge}
    local a, b, c = 8, 6, 4
    local xmax, ymax, zmax = a+1, b+1, c+1
    local g = graph3d:new{          
      window = {-6,8,-6,7},  
      viewdir = {30,60},
      size={10,10,0}
    }
    local xIntcpt, yIntcpt, zIntcpt = M(a,0,0), M(0,b,0), M(0,0,c)
    local P = M(4,0,0)
    local Q = interDD({P,vecJ},{xIntcpt,yIntcpt-xIntcpt})
    local R = interDD({P,vecK},{xIntcpt,zIntcpt-xIntcpt})
    g:Dscene3d(
      g:addPolyline({
        {Origin,xmax*vecI},
        {Origin,ymax*vecJ},
        {Origin,zmax*vecK},
      }),
      g:addPolyline(
        {xIntcpt,yIntcpt,zIntcpt},
        {close=true,color="cyan"}),
      g:addFacet(
        {P,Q,R},
        {color="cyan",opacity=0.5}
      ), 
      g:addPolyline(
            {P,Q,R},
                    {close=true,color="cyan",style="dashed"}
                ),
      g:addLabel(
        "\\(x\\)",P,{pos="NW",dist=0.1},
        a,xIntcpt,{pos="NW",dist=0.1},
        b,yIntcpt,{pos="N",dist=0.1},
        c,zIntcpt,{pos="NW",dist=0.1}
      )
    )
    g:Show()
\end{luadraw}
\end{document}

enter image description here

P.S. The window is specified as window = {xmin, xmax, ymin, ymax}.

11

The default 2D window isn't large enough here. Another unrelated point: you don't actually need g:Dscene3d() because there are no facet intersections to manage.

% Source - https://tex.stackexchange.com/q/761108
% Posted by Matthew Leingang
% Retrieved 2026-03-21, License - CC BY-SA 4.0

% !TEX TS-program = LuaLaTeX
\documentclass[5pt]{standalone}
\usepackage[3d]{luadraw}
\begin{document}
\begin{luadraw}{name=wedge}
    local a, b, c = 8, 6, 4
    local xmax, ymax, zmax = a+1, b+1, c+1
    local g = graph3d:new{
      window3d = {0,xmax,0,ymax,0,zmax},
      adjust2d = true,  -- adjust 2D window
      viewdir = {30,60},
      size={10,10,0},
      bbox = false
    }
    local xIntcpt, yIntcpt, zIntcpt = M(a,0,0), M(0,b,0), M(0,0,c)
    local P = M(4,0,0)
    local Q = interDD({P,vecJ},{xIntcpt,yIntcpt-xIntcpt})
    local R = interDD({P,vecK},{xIntcpt,zIntcpt-xIntcpt})
    g:Dpolyline3d({
        {Origin,xmax*vecI},
        {Origin,ymax*vecJ},
        {Origin,zmax*vecK},
      })
    g:Dpolyline3d({xIntcpt,yIntcpt,zIntcpt},true,"cyan")
    g:Dfacet(
        {P,Q,R},
        {color="cyan",opacity=0.5, edgecolor="cyan", edgestyle="dashed"}
      )
    g:Dlabel3d(
        "\\(x\\)",P,{pos="NW",dist=0.1},
        c,zIntcpt,{}, -- options unchanged
        a,xIntcpt,{}, -- options unchanged
        b,yIntcpt,{pos="N"} -- pos has changed but not dist
      )
    g:Show()
\end{luadraw}
\end{document}

enter image description here

EDIT When you compile the document with the option adjust2d=true, you will see the following message appear in the console:

enter image description here

it indicates an automatically calculated 2D window, this then allows you to choose a better 2D window with the option window={xmin,xmax,ymin,ymax} as Kabenyuk very rightly says in his answer.

3
  • I see. So if I don't specify window or adjust3d explicitly for a graph3d object, I just get the default value of {-5.5,-5.5,1,1}? Commented Mar 22 at 10:01
  • I chose to use g:Dscene3d() because the docs say “This method should therefore be reserved for very simple scenes.” I thought this was pretty simple. But now I understand that it's almost too simple because there is only one facet. Commented Mar 22 at 10:05
  • 1
    @MatthewLeingang Yes, if you don't specify a 2D window or the adjust2d=true option, the default 2D window will indeed be window={-5,5,-5,5} (the other two parameters are optional). Similarly, if you don't specify a 3D window, its default value will be window3d={-5,5,-5,5,-5,5}. When you can manually manage the display order of 3D elements, it's not necessary to use g:Dscene3d(). Commented Mar 22 at 10:26

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.