Class Triangle

java.lang.Object
  extended by Triangle

public class Triangle
extends java.lang.Object


Constructor Summary
Triangle(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y, objectdraw.DrawingCanvas canvas)
          Constructor that takes six double parameters, i.e., x,y-coordinate for three points
Triangle(objectdraw.Location p1, objectdraw.Location p2, objectdraw.Location p3, objectdraw.DrawingCanvas canvas)
          Constructor that takes three Location parameters
Triangle(Triangle tri, objectdraw.DrawingCanvas canvas)
          Constructor that makes a copy of a triangle from an existing triangle
 
Method Summary
 boolean contains(objectdraw.Location p)
          Returns true if the Location p is strictly inside the bounding box of the triangle, otherwise return false Specifically, all of the following are satisfied: p.getX() is less than the triangle's largest x-coordinate p.getX() is greater than the triangle's smallest x-coordinate p.getY() is less than the triangle's largest y-coordinate p.getY() is greater than the triangle's smallest y-coordinate For extra credit, you can implement this method so that it returns true only if the Location p is inside of the actual triangle.
 java.awt.Color getColor()
          Returns the current color of the triangle
 double getHeight()
          Returns the height of the triangle's surrounding box, i.e., The maximum y-coordinate minus the minimum y-coordinate
 double getWidth()
          Returns the width of the triangle's surrounding box, i.e., The maximum x-coordinate minus the minimum x-coordinate
 double getX()
          Returns the x-coordinate of the top-left corner of the triangle Specifically, this returns the smallest x-coordinate among the triangles three points
 double getY()
          Returns the y-coordinate of the top-left corner of the triangle Specifically, this returns the smallest y-coordinate among the triangles three points
 void move(double x, double y)
          Moves the triangle in the x and y direction by the amounts specified; Use positive numbers to move x right and negative numbers to move x left Use positive numbers to move y down and negative numbers to move y up
 void moveTo(double x, double y)
          Moves the triangle to the specified x,y destination
 void removeFromCanvas()
          Removes the triangle from the canvase Removes each of the three lines from the canvas
 void setColor(java.awt.Color c)
          Sets the color of the triangle to a new color
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Triangle

public Triangle(double p1x,
                double p1y,
                double p2x,
                double p2y,
                double p3x,
                double p3y,
                objectdraw.DrawingCanvas canvas)
Constructor that takes six double parameters, i.e., x,y-coordinate for three points

Parameters:
p1x - A point's x-coordinate
p1y - A points' y-coordinate
p2x - A point's x-coordinate
p2y - A points' y-coordinate
p3x - A point's x-coordinate
p3y - A points' y-coordinate
canvas - The canvas used to draw the triangle

Triangle

public Triangle(objectdraw.Location p1,
                objectdraw.Location p2,
                objectdraw.Location p3,
                objectdraw.DrawingCanvas canvas)
Constructor that takes three Location parameters

Parameters:
p1 - A point of the triangle
p2 - A point of the triangle
p3 - A point of the triangle
canvas - The canvas used to draw the triangle

Triangle

public Triangle(Triangle tri,
                objectdraw.DrawingCanvas canvas)
Constructor that makes a copy of a triangle from an existing triangle

Parameters:
tri - The triangle to copy
canvas - The canvas used to draw the triangle
Method Detail

contains

public boolean contains(objectdraw.Location p)
Returns true if the Location p is strictly inside the bounding box of the triangle, otherwise return false Specifically, all of the following are satisfied: p.getX() is less than the triangle's largest x-coordinate p.getX() is greater than the triangle's smallest x-coordinate p.getY() is less than the triangle's largest y-coordinate p.getY() is greater than the triangle's smallest y-coordinate For extra credit, you can implement this method so that it returns true only if the Location p is inside of the actual triangle. Note that you must use line geometery and the algorithm is well-known.


getColor

public java.awt.Color getColor()
Returns the current color of the triangle

Returns:
The current triangle color (type Color)

getHeight

public double getHeight()
Returns the height of the triangle's surrounding box, i.e., The maximum y-coordinate minus the minimum y-coordinate

Returns:
height of the triangle's surrounding box

getWidth

public double getWidth()
Returns the width of the triangle's surrounding box, i.e., The maximum x-coordinate minus the minimum x-coordinate

Returns:
height of the triangle's surrounding box

getX

public double getX()
Returns the x-coordinate of the top-left corner of the triangle Specifically, this returns the smallest x-coordinate among the triangles three points

Parameters:
x-coordinate - of the top-left corner

getY

public double getY()
Returns the y-coordinate of the top-left corner of the triangle Specifically, this returns the smallest y-coordinate among the triangles three points

Parameters:
y-coordinate - of the top-left corner

move

public void move(double x,
                 double y)
Moves the triangle in the x and y direction by the amounts specified; Use positive numbers to move x right and negative numbers to move x left Use positive numbers to move y down and negative numbers to move y up

Parameters:
x - Amount to move in the x direction (left or right)
y - Amount to move in the y direction (up or down)

moveTo

public void moveTo(double x,
                   double y)
Moves the triangle to the specified x,y destination

Parameters:
x - The x-coordinate of the destination location
y - The y-coordinate of the destination location

removeFromCanvas

public void removeFromCanvas()
Removes the triangle from the canvase Removes each of the three lines from the canvas


setColor

public void setColor(java.awt.Color c)
Sets the color of the triangle to a new color

Parameters:
The - new color (type Color)