Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package geometricShapes;
- import java.awt.Point;
- import java.awt.image.BufferedImage;
- import javax.swing.text.AbstractDocument.LeafElement;
- public class Triangle extends CustomShape {
- private int sideLength;
- private Point thirdPoint;
- public Triangle(Point cntrPnt, Point refPnt) {
- thirdPoint = new Point();
- this.cntrPnt = new Point(cntrPnt);
- this.refPnt = new Point(refPnt);
- getSideLength();
- thirdPoint.y = refPnt.y;
- thirdPoint.x = cntrPnt.x - sideLength / 2;
- this.refPnt.x = cntrPnt.x + sideLength / 2;
- System.out.println(sideLength);
- }
- public void draw(BufferedImage grid) {
- drawLine(cntrPnt, refPnt, grid);
- drawLine(cntrPnt, thirdPoint, grid);
- drawLine(refPnt, thirdPoint, grid);
- }
- private void getSideLength() {
- double deltaY = Math.abs(refPnt.y - cntrPnt.y);
- sideLength = (int)Math.sqrt(4 * deltaY * deltaY / 3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement