Loading commands, almost done…
The Fermat point of a triangle is the point that minimizes the total distance to all three vertices. For triangles with all angles less than 120°, this point is unique and has the special property that the lines from it to each vertex form 120° angles.
Here we use gradient descent to find this point by iteratively minimizing the sum of distances to the triangle's vertices.
\point 0 3\point 5 0t = \triangle p0 p1 p2 - p2 is auto-generated to complete the triangleThese commands set up the trainable point and parameters without changing the visualization:
p = \point 2 -1 - this is our initial guess for the Fermat point\param p - this tells the system that point p is trainablepoints = \array p0 p1 p2learning-rate = \scalar 0.5\line p points - visualize the connectionsdists = \distance p pointsloss = \reduce-sum dists - this is what we want to minimize\backprop loss\gradient-descent-stepClick the command multiple times to continue training and watch point p converge towards the Fermat point. Run the \fermat-point-of-a-triangle command in the geomatic editor to set up the initial state, then repeatedly run \fermat-train-step to optimize.