Skip to content

Arbitrary hyperbolic functions #190

Description

@yerlotic

Currently its not possible to properly plot a y = tan(x)

The plot will have either extra lines

Image

or become even more hyperbolic:

Image

Although it is possible to plot a simple hyperbola, it seems like it's impossible to accurately plot a slightly more complicated function

Image

even though desmos can do it without issues:

Image
Source code
#import "@preview/cetz:0.5.2": canvas, draw
#import "@preview/cetz-plot:0.1.4": plot

#let samples = 200
#canvas({
  import draw: *
  
  // Set-up a thin axis style
  set-style(
    axes: (stroke: .5pt, tick: (stroke: .5pt)),
    legend: (stroke: white, orientation: ttb, item: (spacing: .3), scale: 80%),
  )
  plot.plot(
    size: (10, 7),
    y-min: -4,
    y-max: 4,
    x-tick-step: 1,
    y-tick-step: 1,
    axis-style: "school-book",
    {
      let domain = (-4, 4)
      
      plot.add-contour(
        (x, y) => x * y,
        y-domain: domain,
        x-domain: domain,
        y-samples: samples,
        x-samples: samples,
        label: $x y = 1$,
      )
      plot.add(
        x => 1 / x,
        domain: domain,
        samples: samples,
        label: $y=1/x$,
        style: (stroke: (dash: "dashed", paint: red)),
      )
      
      plot.add-contour(
        (x, y) => y / calc.tan(x),
        y-domain: domain,
        x-domain: domain,
        y-samples: samples,
        x-samples: samples,
        label: $y/(tan x) = 1$,
      )
      plot.add(
        x => calc.tan(x),
        domain: domain,
        samples: samples,
        label: $y=tan x$,
        style: (stroke: (dash: "dashed", paint: purple)),
      )
      
      // problematic function
      plot.add(
        x => ((x + 2) * (x - 1)) / ((x + 3) * (x - 2)),
        domain: domain,
        samples: samples,
        label: $y=((x + 2)(x - 1)) / ((x - 2)(x + 3))$,
        style: (stroke: black),
      )
    },
  )
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions