Skip to content
Snippets Groups Projects
Commit 384af224 authored by Soeren Peters's avatar Soeren Peters
Browse files

Add casteljau stubs

parent 960c9098
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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();
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment