diff --git a/README.md b/README.md index 681ed02221d1924e5d5fdd41ea89adb7fdd8b7cc..a9d28e0ca576c1d4f7d1bdff570a310b7c5ecb66 100644 --- a/README.md +++ b/README.md @@ -84,4 +84,17 @@ In this exercise we need to implement this new method in the following classes: view/graphics/PaintableBezierCurve.java ### Expected behavior: -Bezier Curve can be painted as before. \ No newline at end of file +Bezier Curve can be painted as before. + +## Exercise 7 +This exercise is based on the tenth lecture about the spline interpolation method. +In this exercise we need to implement this new interpolation method in the following classes: + + model/Spline.java + +Additionally, the following class was added to the project: + + view/graphics/PaintableSpline.java + +### Expected behavior: +Spline interpolation can be painted. \ No newline at end of file diff --git a/src/main/java/irmb/flowsim/view/graphics/PaintableSpline.java b/src/main/java/irmb/flowsim/view/graphics/PaintableSpline.java index 0cce4dc1ec73a9dbb9c7f6389dac3b22b57e55f6..0182b7bc26b084813ff713a2aea0090ffc706663 100644 --- a/src/main/java/irmb/flowsim/view/graphics/PaintableSpline.java +++ b/src/main/java/irmb/flowsim/view/graphics/PaintableSpline.java @@ -23,9 +23,33 @@ public class PaintableSpline extends PaintableShape { @Override public void paint(Painter painter) { - //TODO - } + List<Point> pointList = spline.getPointList(); + int numOfPoints = 100; + painter.setColor(Color.BLACK); + // Spline zeichnen + 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 = spline.getPointOnSpline(t1); + Point p2 = spline.getPointOnSpline(t2); + + // draw line + painter.paintLine(p1, p2); + } + } + + // Kontrollpunkte zeichnen + for (int i = 0; i < pointList.size(); i++) { + Point p = pointList.get(i); + int k = 4; + Point p_view = trafo.transformToPointOnScreen(p); + painter.paintLine(p_view.getX() - k, p_view.getY() - k, p_view.getX() + k, p_view.getY() + k); + painter.paintLine(p_view.getX() + k, p_view.getY() - k, p_view.getX() - k, p_view.getY() + k); + } + }