Loading editor...

Getting started

Loading commands, almost done…

Welcome to the interactive Geometry explainer!

Here we go through some of the basic commands to get started with Geomatic. Every command has one of these two formats:

  1. output = \function-name arg1 arg2 ...
  2. \function-name arg1 arg2 ...: If an output variable is not provided, one is assigned automatically.

The environment already comes loaded with a few geometric objects. One of them is the point at origin. It has the variable name p0. You can run to highlight it.

Highlighting a geometric object (or a node) adds a temporary animation to it to draw attention to it. You will get a warning if you try to highlight a non-existent object like .

  • Let's draw the point p1. This can be done by using the point function. This is as simple as .
  • Now we can draw a line joining p0 and p1: . To see the name assigned to the line, you can hover above it (in this case, you should see the name line0).
  • Let's try to draw a circle with center at p1 and radius equal to the distance between p0 and p1. This can be done in two steps:
    • Calculate the distance: .
    • Draw the circle: .

Reactive updates

You can clear the slate and start over by running . Now let's create a line with points a and b, calculate its midpoint, and draw a circle with center at the midpoint and radius equal to the distance between a and b.

  • Create line: : Note how it automatically creates input points a and b randomly when they don't exist.
  • Calculate midpoint: .
  • Calculate radius: .
  • Draw circle: .

Here comes the fun part - changing the position of a or b will automatically update all of the other components that depend on them. In this case, these components are the midpoint m and the radius r.

  • Set a to be at position (2, 2): .
  • Set b to be at position (2, -2): .

Note how both the midpoint and the radius are updated automatically. You can also translate one of the points by , and the geometry updates accordingly.

Finally, removing point m will also remove the circle, since it depends on m: . Similarly removing point a will also remove the line: .

Reactivity is maintained throughout. Note that some operations like translate will break reactivity. For example, translating the point m will make it not depend on a and b anymore.


Broadcasting

We start with an empty canvas by running . Here are a bunch of commands to get a feel for broadcasting:

  • Create uniformly spaced points on x-axis: .
  • Create points on x-axis: : Note how we used the same command point but for an array of scalars instead of a single scalar.

This idea can be extended further:

  • Highlight all the points: .
  • Create circles centered at these points: .

You can modify any individual object if needed:

  • Move p3: . The circle also moves with it due to reactivity.

Autograd

The API for autograd is similar to PyTorch. As of now, one can only register scalars or points as parameters. The usual way to use automatic differentiation is to register the parameters, define a scalar valued loss function, backpropagate the gradients, and update the parameters using gradient descent.

  • Clear the canvas: .
  • Define a scalar r: .
  • Create a circle centered at p0 with radius r: .
  • Register the radius as a parameter to optimize: .
  • Calculate the loss function, in this case the area of the circle: .
  • Backpropagate: .
  • Perform gradient descent: : the learning rate here is based on the value of the in-built variable learning-rate.

You will notice the circle get a bit smaller.