Package turtle

Class TurtleSoup

java.lang.Object
turtle.TurtleSoup

public class TurtleSoup
extends Object
  • Method Summary

    Modifier and Type Method Description
    static double chordLength​(double radius, double angle)
    Determine the length of a chord of a circle.
    static double distance​(Point p1, Point p2)
    Calculate the distance between two points.
    static void drawApproximateCircle​(Turtle turtle, double radius, int numSides)
    Approximate a circle by drawing a many-sided regular polygon, using only right-hand turns, and restoring the turtle's original heading and position after the drawing is complete.
    static void drawPersonalArt​(Turtle turtle)
    Draw your personal, custom art.
    static void drawSquare​(Turtle turtle, int sideLength)
    Draw a square.
    static List<Point> findShortestPath​(Set<Point> points)
    Given a set of points, find a shortest path that connects the points.
    static Point findTriangleIncenter​(Point p1, Point p2, Point p3)
    Given three non-collinear points, calculate the incenter (center of the inscribed circle) of the triangle with vertices at those points.
    static void main​(String[] args)
    Main method.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • drawSquare

      public static void drawSquare​(Turtle turtle, int sideLength)
      Draw a square.
      Parameters:
      turtle - the turtle context
      sideLength - length of each side, must be >= 0
    • chordLength

      public static double chordLength​(double radius, double angle)
      Determine the length of a chord of a circle. (There is a simple formula; derive it or look it up.)
      Parameters:
      radius - radius of a circle, must be > 0
      angle - in degrees, where 0 <= angle < 180
      Returns:
      the length of the chord subtended by the given `angle` in a circle of the given `radius`
    • drawApproximateCircle

      public static void drawApproximateCircle​(Turtle turtle, double radius, int numSides)
      Approximate a circle by drawing a many-sided regular polygon, using only right-hand turns, and restoring the turtle's original heading and position after the drawing is complete.
      Parameters:
      turtle - the turtle context
      radius - radius of the circle circumscribed around the polygon, must be > 0
      numSides - number of sides of the polygon to draw, must be >= 10
    • distance

      public static double distance​(Point p1, Point p2)
      Calculate the distance between two points.
      Parameters:
      p1 - one point
      p2 - another point
      Returns:
      Euclidean distance between p1 and p2
    • findTriangleIncenter

      public static Point findTriangleIncenter​(Point p1, Point p2, Point p3)
      Given three non-collinear points, calculate the incenter (center of the inscribed circle) of the triangle with vertices at those points.
      Parameters:
      p1 - one point
      p2 - another point
      p3 - a third point which is not collinear with p1 and p2
      Returns:
      the center of the circle inscribed in the triangle whose vertices are p1, p2, p3.
    • findShortestPath

      public static List<Point> findShortestPath​(Set<Point> points)
      Given a set of points, find a shortest path that connects the points.
      Parameters:
      points - input points
      Returns:
      a list containing all the input points, in an order that minimizes the total length of the line segments from each point to its successor in the list (i.e., minimizing the sum of the distances from list.get(i) to list.get(i+1) for all adjacent indices i,i+1 in the list )
    • drawPersonalArt

      public static void drawPersonalArt​(Turtle turtle)
      Draw your personal, custom art. Many interesting images can be drawn using the simple implementation of a turtle. See the problem set handout for more information.
      Parameters:
      turtle - the turtle context
    • main

      public static void main​(String[] args)
      Main method. This is the method that runs when you run "java TurtleSoup".
      Parameters:
      args - unused