diff --git a/README.md b/README.md index 68b240f7fa4d8b99376c3dc11371100c7dc97d1b..681ed02221d1924e5d5fdd41ea89adb7fdd8b7cc 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ The task is implement BuildObjectMouseStrategy and MoveMouseStrategy. ### Expected behavior: Shapes can be painted via the menu or the toolbar. Additionally, the shapes can be moved via the mouse, the window can be panned and zoomed. A right click should remove the shape. -## Exercuse 5 +## Exercise 5 This exercise is based on the eighth lecture about the bezier interpolation method. Compared to the last exercise, we now have the following folder filled with class stubs. @@ -75,3 +75,13 @@ Compared to the last exercise, we now have the following folder filled with clas ### Expected behavior: Bezier Curve can be painted. + +## Exercise 6 +This exercise is based on the ninth lecture about the casteljau bezier interpolation method. +In this exercise we need to implement this new method in the following classes: + + model/BezierCurve.java + view/graphics/PaintableBezierCurve.java + +### Expected behavior: +Bezier Curve can be painted as before. \ No newline at end of file diff --git a/src/main/java/irmb/flowsim/model/BezierCurve.java b/src/main/java/irmb/flowsim/model/BezierCurve.java index 01b5802758b86d076c6a3271eb5c7da04a50e97c..dbbb2eaae1ffb55952a4bb6c6bb545606c3b308c 100644 --- a/src/main/java/irmb/flowsim/model/BezierCurve.java +++ b/src/main/java/irmb/flowsim/model/BezierCurve.java @@ -11,6 +11,22 @@ import java.util.List; public class BezierCurve extends PolyLine { + public List<Point> calculateCasteljau(List<Point> pointList, double t) { + //TODO + return null; + } + + private List<Point> getSubPointList(double t, List<Point> tempList) { + //TODO + return null; + } + + private Point getSubPoint(double t, Point first, Point second) { + //TODO + return null; + } + + public Point calculatePointWithBernstein(double t) { List<Point> pointList = getPointList(); int size = pointList.size(); diff --git a/src/main/java/irmb/flowsim/view/graphics/PaintableBezierCurve.java b/src/main/java/irmb/flowsim/view/graphics/PaintableBezierCurve.java index 2a0f6694674628eea9ed3ca61e48a12e4c57b350..b8e5bce76acb1c9fb0279d509acda96f0b085948 100644 --- a/src/main/java/irmb/flowsim/view/graphics/PaintableBezierCurve.java +++ b/src/main/java/irmb/flowsim/view/graphics/PaintableBezierCurve.java @@ -23,21 +23,39 @@ public class PaintableBezierCurve extends PaintableShape { @Override public void paint(Painter painter) { - List<Point> pointList = bezierCurve.getPointList(); - int numOfPoints = 100; - if (pointList.size() >= 2) { - for (int i = 0; i < numOfPoints-1; i++) { - double t1 = (i) / (double) (numOfPoints - 1); - double t2 = (i + 1.0) / (double) (numOfPoints - 1); - - Point p1 = bezierCurve.calculatePointWithBernstein(t1); - Point p2 = bezierCurve.calculatePointWithBernstein(t2); + painter.setColor(Color.BLACK); + recursivePaint(painter, bezierCurve.getPointList()); - painter.paintLine(new Point(p1.getX(), p1.getY()), new Point(p2.getX(), p2.getY())); - } + for (Point point : bezierCurve.getPointList()) { + Point viewPoint = transformer.transformToPointOnScreen(point); + painter.paintPoint(viewPoint.getX(), viewPoint.getY()); } } + private void recursivePaint(Painter painter, List<Point> pointList) { + // TODO + } + + + // ## old paint method: + // + // @Override + // public void paint(Painter painter) { + // List<Point> pointList = bezierCurve.getPointList(); + // int numOfPoints = 100; + // if (pointList.size() >= 2) { + // for (int i = 0; i < numOfPoints-1; i++) { + // double t1 = (i) / (double) (numOfPoints - 1); + // double t2 = (i + 1.0) / (double) (numOfPoints - 1); + + // Point p1 = bezierCurve.calculatePointWithBernstein(t1); + // Point p2 = bezierCurve.calculatePointWithBernstein(t2); + + // painter.paintLine(new Point(p1.getX(), p1.getY()), new Point(p2.getX(), p2.getY())); + // } + // } + // } + @Override public boolean isPointOnBoundary(Point point, double radius) { if (getDefinedPoint(point, radius) != null)