Programming Lesson: Distance Between Two Points

Assignment: Write a program to find the distance between two points.

To find the distance (c) between two points (x1, y1) and (x2, y2) you use the equation:

  c = \sqrt{a^2 + b^2}

where a and b are:

  a = x_2 - x_1
  b = y_2 - y_1

So, let’s find the distance between the points (1,7) and (5, 2) using python:

# define inputs
x1 = 1
y1 = 7
x2 = 5
y2 = 2

# calculate distance
a = x2 - x1
b = y2 - y1

c = (a**2 + b**2)**0.5   

# output the result
print("Distance between two points.")
print("Point 1:", x1, y1)
print("Point 2:", x2, y2)
print("Distance:", c)

The result should look like:

Distance between two points.
Point 1: 1 7
Point 2: 5 2
Distance: 6.40312

Coatis

Coati at the Pocosol Research Station in the Children's Eternal Rainforest , Costa Rica.
Coati at the Pocosol Research Station in the Children’s Eternal Rainforest , Costa Rica.

White-nosed Coatis (Nasua narica) are diurnal and, unusually for most Central America carnivores, highly social. They seem to fill a similar niche to raccoons. Ran into this one wandering around the Pocotal Research Station in the Bosque Eterno de los Niños, Costa Rica. It did not seem too perturbed that we were within 10 meters of each other.

Trophic Cascade: The Effect of Wolves on Yellowstone

The reintroduction of wolves to Yellowstone National Park resulted in enormous changes to the ecology: more plants and animals as the wolves reduced the deer population and changed the deers’ behavior. The change in vegetation resulted in stabilization of the rivers, so the wolves changed the geomorphology of the park as well.

Headless Pi Zero

Pi Zero‘s are even cheaper versions of the Raspberry Pi. The price you pay is that they’re harder to connect to since all the ports are small (micro-USB’s and mini-HDMI’s), so you need adapters to connect to keyboards, mice, and monitors. However, if you have the wireless version (Pi Zero W) you can set it up to automatically connect to the WiFi network, and work on it through there using the command line. This is a brief summary of how to do this (it’s called a “headless” setup) based on Taron Foxworth’s instructions. It should work for the full Raspberry Pi as well.

Set up the Operating System

You can install the Raspbian Stretch (or Raspbian Lite which does not include the desktop GUI that you will not use) on a SD card (I used 8 or 16 Gb cards).

  • Download Raspbian.
  • SD Card Formatter to format the SD Card. It’s pretty quick, just follow the instructions.
  • Etcher: to install the operating system on the SD Card

Set up automatic connection to WiFi

You may have to remove and reinsert the SD Card to get it to show up on the file system, but once you have you can set it up to automatically connect to WiFi by:

  • Go into the /boot partition (it usually shows up as the base of the SD Card on your file manager) and create a file named “ssh”.
  • Create a text file called “wpa_supplicant.conf” in the /boot folder, and put the following into it, assuming that the wifi router you’re connecting to is called “myWifi” and the password is “myPassword”.
  • country=US
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
     ssid="myWifi"
     scan_ssid=1
     psk="myPassword"
     key_mgmt=WPA-PSK
    }
    

Now put the SD Card into the Pi and plug in the power.

Find the IP address

First you have to find the Pi on the local network. On Windows I use Cygwin to get something that looks and acts a bit like a unix terminal (on Mac you can use Terminal, or any shell window on Linux).

To find the ip address of your local network use:

on Windows:

> ipconfig

look for the “IPv4 Address”.

Mac (and Linux?)

> ifconfig

look under “en1:”

Connecting

To connect you use ssh on the command line (Mac or Linux) or something like Putty

Static IP

Without a static IP address it is possible that the Pi’s IP address will change occasionally. I followed the instructions on Circuit Basics and MODMYPI, but basically you have to:

  • Identify your network information:
    • Find your Gateway:
    • > route -ne
      
    • Find your Domain Server:
    • > cat /etc/resolv.conf
      
  • Add the information to the end of your /etc/dhcpcd.conf file (here the wlan0 means you’re doing this to the wireless interface (WiFi) and the static ip is 10.0.0.99, the static router the gateway ip you found above, and the domain_name_servers takes the domain server ip):
  • interface wlan0
    static ip_address=10.0.0.99
    static routers=10.0.0.1
    static domain_name_servers=75.75.75.75
    
  • Now reboot and you should be able to ssh or sftp into the new static IP.

A Web Server

Adding a webserver (apache with php) is pretty easy as well, just run the commands (from the Raspberry Pi Foundation)

Apache web server:

sudo apt-get install apache2 -y

PHP for server-side scripting

sudo apt-get install php libapache2-mod-php -y

Now your can find the webpage by going to the ip address (e.g. http://10.0.0.1).

The actual file that you’re seeing is located on the Pi at:

/var/www/html/index.html

You will probably need to change the ownership of the file in order to edit it by running:

> sudo chown pi: index.html

The Wall (Mural)

Our seniors wanted to leave a mark, so after their initial application to paint the outside wall of the gym was turned down, they went with a mural on the inside–in our Makerspace.

For this project, we wanted to create a mural on the basementnasium wall. First, we measured the wall and went to Home Depot to get enough paint, paint brushes, drop cloths, and tape. Then, after cleaning the wall with a damp cloth, we covered the wall with tape in a triangular pattern similar to one we found online. After that, we used pencil to mark each triangle with a letter corresponding to one of the six colors that we bought. It took us the majority of the project to paint 3-4 coats on each triangle, and on the last day we pulled it the tape and touched up any mistakes with white paint.

Throughout this project, we found out that some people know how to paint, some people learned, and others didn’t learn. BUT IT WAS SO MUCH FUN!

-Team: Elliott, Abby, John, Zoe, Mary, Annemarie, and Josiah

-Abby R.

Longboard

Longboard built during the interim.
Longboard built during the interim.
Finishing came afterwards.

For my makerspace project I made a longboard. What went well with the board was the wheels and trucks, it was a simple hole in the wood and screwing the trucks almost no measuring on my part. What didn’t go so well was the measuring and cutting of the board, it took me a full day to get all the measurements exact and even then they didn’t come out so good. What I would do next time is get a cnc machine so it does the measuring and gets the cuts exact every time. We could mass produce longboards with ease. If i did it again without a cnc machine i would get the measurements beforehand and then it would make measuring a lot easier.

– Isaac L.