1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Math trigonometry

A sine calculates the vertical offset between two points based on the angle. A cosine calculates the horizontal distance.

 

math-trig1

Let's say we have two points, a and b, connected by a line.

math-trig2

Now let's assume a is at the origin (or center) of a circle. The circle has a radius equal to the length of the line connecting a and b.

So b is located somewhere on the circle's circumference.

math-trig3

There is a horizontal and vertical distance between a and b.

We can use sine and cosine to determine those distances.

math-trig4

Each line from a to a point on the circle's circumference (for example, b) has an angle.

Measured counterclockwise, starting from 0°, a circle has a total circumference of 360°. So a line from a going straight up would have an angle of 90°.

In the case of the line between a and b, the angle is 60°.

math-trig5

The cosine function calculates the horizontal distance between a and b based on the angle.

The sine function calculates the vertical distance between a and b.

In the case of an angle of 60°, the sine yields 0.5. So the horizontal distance between a and b is half the length of the line between a and b.

math-trig6

With sine and cosine we can calculate the distance between a and b.

This is useful if we have position coordinates for a and we need to calculate the position of a point b that is orbiting around it.

For 60°, the sine yields 0.5, meaning half the length of the distance between a and b. So the horizontal distance between a and b is 70 * 0.5 = 35.

So b's x equals a's x plus 35.

math-trig7

The command in NodeBox would look like this:

def coordinates(x0, y0, distance, angle):
    from math import radians, sin, cos
    angle = radians(angle)
    x1 = x0 + cos(angle) * distance
    y1 = y0 + sin(angle) * distance
    return x1, y1