Built In Functions - maxkatzmann/hydra GitHub Wiki

In the following we list all built-in functions that are supported in Hydra, in alphabetical order. A function is described as function(parameter1:(Type1), parameter2:(Type2), ...).


circle

circle(center:(Pol), radius:(Number))

Draws a hyperbolic circle with the passed radius, centered at the specified polar coordinate.

var r = 10
var point = Pol(r: 7.0, phi: M_PI / 8)
circle(center: point, radius: r)

clear

clear()

Removes all objects from the canvas.


cos

cos(x:(Number))

Evaluates the cosine function at the passed value.

var a = cos(x: M_PI) // a = -1

cosh

cosh(x:(Number))

Evaluates the hyperbolic cosine function at the passed value.

var a = cosh(x: 0) // a = 1

curve_angle

curve_angle(from:(Pol), to:(Pol), angle:(Number)) {_p:(Pol)}

Draws a curve containing the points that have an angular distance of angle to the line between the points from and to.

The parameters from and to are polar coordinates that are required to have the same angular coordinate and the radius of from must be smaller than the radius of to.

The angle parameter needs to evaluate to a number. It is the only parameter that may contain the hidden variable _p. Basically curve_angle draws the curve by walking from point from to point to, and evaluating angle at each point _p.

var R = 10.0
var start = Pol(r: R / 2.0, phi: 0.0)
var end = Pol(r: R, phi: 0.0)
curve_angle(from: start, to: end, angle: theta(r1: _p.r, r2: _p.r, R: R))

curve_distance

curve_distance(from:(Pol), to:(Pol), distance:(Number)) {_p:(Pol)}

Draws a curve containing the points that have a distance of distance perpendicular to the line containing the points from and to.

The parameters from and to are polar coordinates.

The distance parameter needs to evaluate to a number. It is the only parameter that may contain the hidden variable _p. Basically curve_distance draws the curve by walking from point from to point to, and evaluating distance at each point _p.

If the distance parameter is negative the curve is drawn on the other side of the line containing from and to, than it would be if distance was positive.

var R = 10.0
var start = Pol(r: R / 2.0, phi: 0.0)
var end = Pol(r: R, phi: 0.0)

// Draw the hypercycle of radius 3.0 around the line segment from start to end
curve_distance(from: start, to: end, distance: 3.0)

distance

distance(from:(Pol), to:(Pol))

Returns the hyperbolic distance between the points from and to.

The parameters from and to are polar coordinates.


exp

exp(x:(Number))

Evaluates the exponential function at the passed value.

var a = exp(x: 1) // a = 2.71828...

line

line(from:(Pol), to:(Pol))

Draws a hyperbolic line between the polar coordinates from and to.

var start = Pol(r: 7.0, phi: 0.0)
var end = Pol(r: 3.0, phi: M_PI / 4.0)
line(from: start, to: end)

line_euc

line_euc(from:(Pol), to:(Pol))

Draws a Euclidean line between the polar coordinates from and to.

var start = Pol(r: 7.0, phi: 0.0)
var end = Pol(r: 3.0, phi: M_PI / 4.0)
line_euc(from: start, to: end)

log

log(x:(Number))

Evaluates the natural logarithm at the passed value.

var a = log(x: exp(x: 1)) // a = 1

mark

mark(center:(Pol), radius:(double))

Draws a filled (Euclidean) circle of the passed radius centered at the passed center.

var p = Pol(r: 3.0, phi: M_PI / 4.0)
mark(center: p, radius: 3.0)

random

random(from:(Number), to:(Number))

Returns a random number that is uniformly distributed between from and to. The lower bound from has to be smaller than the upper bound to.

var a = random(from: M_PI, to: 2.0 * M_PI) // a in [M_PI, 2 * M_PI]

rotate

rotate(point:(Pol), by:(Number))

Returns a Pol object that is obtained by rotating the point around the origin by an angle of by.


save

save(file:(String))

Saves the current canvas to a file at the path defined by file. The file may contain escape sequences indicated by \( ). The currently supported output formats are .ipe for Ipe files and .svg for SVG files.

var a = 1
save(file: "empty_\(a).ipe") // Canvas is saved to "empty_1.ipe"

set_resolution

set_resolution(x:(Number))

Sets the resolution of the canvas to x which must be a positive number. As a result, objects that are added to the canvas after the resolution update are drawn using the specified resolution. (Objects drawn before the call are not affected)

All objects in Hydra are drawn by walking along the outline of the object in a step-wise manner and connecting the obtained positions with straight lines. The higher the resolution, the smaller these steps.

The default value is 100.0.

set_resolution(x: 200.0) // Double the default resolution.

sin

sin(x:(Number))

Evaluates the sine function at the passed value.

var a = sin(x: M_P / 2.0) // a = 1

sinh

sinh(x:(Number))

Evaluates the hyperbolic sine function at the passed value.

var a = sinh(x: 0) // a = 0

theta

theta(r1:(Number), r2:(Number), R:(Number))

This function represents hyperbolic law of cosines, rearranged to determine the angle between r1 and r2, to the opposite of R. The parameters are the lengths of the sides of the triangle.

var a = theta(r1: 5.0, r2: 7.0, R: 10.0)

translate

translate(point:(Pol), by:(Number))

Returns a Pol object that represents a point which is obtained by applying the following translation to the passed point. The translation moves a point p on the origin to the point p' whose radius is the absolute value of by. If by is negative the angular coordinate of p' is π, otherwise it is 0. An example of the application of the translate function.