Skip to content

Commit

Permalink
add function plotter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gewi413 committed Jul 10, 2023
1 parent 4eab66d commit 9ccebd7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions plotst/util/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@
} else {
range(min, max, step: step)
}
}

/// This function generates `(x, y)` data based on a function to use in other equations.
/// - equation (function): A function that accepts the `x` value of the data and returns the proper `y` value.
/// - start (integer, float): The first `x` value that should be generated.
/// - end (integer, float): The last `x` value that should be generated.
/// - precision (integer): How many lines should be plotted between the `start` and `end` value. The higher the value, the more precise the data will get.
#let function_plotter(equation, start, end, precision: 100) = {
let points = ()
for step in float_range(start, end, step: (end - start) / precision) {
points.push((step, equation(step)))
}
points.push((end, equation(end)))
return points
}

0 comments on commit 9ccebd7

Please sign in to comment.