University stuff.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Oblig4.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. abstract class Oblig4 {
  2. // Required for TegnUt
  3. int x[];
  4. int y[];
  5. int n;
  6. int MAX_Y;
  7. int MAX_X;
  8. int minX;
  9. int maxX;
  10. int minY;
  11. int maxY;
  12. IntList coHull;
  13. NPunkter17 points;
  14. String name = "Oblig4";
  15. Oblig4(NPunkter17 points) {
  16. this.points = points;
  17. n = points.n;
  18. x = new int[n];
  19. y = new int[n];
  20. coHull = new IntList();
  21. points.fyllArrayer(x, y);
  22. }
  23. abstract void solve();
  24. void draw() {
  25. TegnUt t = new TegnUt(this, coHull, name);
  26. t.setVisible(true);
  27. }
  28. int lineA(int p1, int p2) {
  29. return y[p1] - y[p2];
  30. }
  31. int lineB(int p1, int p2) {
  32. return x[p2] - x[p1];
  33. }
  34. int lineC(int p1, int p2) {
  35. return (y[p2] * x[p1]) - (y[p1] * x[p2]);
  36. }
  37. // From p1 to p2.
  38. // == 0: p3 is on the line.
  39. // > 0: p3 is left of the line.
  40. // < 0: p3 is right of the line.
  41. double lineEquation(int a, int b, int c, int p3) {
  42. return (a * x[p3]) + (b * y[p3]) + c;
  43. }
  44. // Distance between two points
  45. double pointDist(int p1, int p2) {
  46. int x1 = x[p1], y1 = y[p1];
  47. int x2 = x[p2], y2 = y[p2];
  48. int dx = x2 - x1;
  49. int dy = y2 - y1;
  50. return Math.abs(Math.sqrt((dx * dx) + (dy * dy)));
  51. }
  52. // Distance between the line and p3
  53. double dist(double l, int a, int b) {
  54. return l / Math.sqrt((a * a) + (b * b));
  55. }
  56. }