Advertisement
Omar_Natour

Untitled

Nov 19th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. public void paint() {
  2. getChildren().clear();
  3. startX0 = (getWidth() / 3);
  4. startX1 = (getWidth() - getWidth() / 3);
  5. startX2 = (getWidth() / 2);
  6. startY0 = (getHeight() / 2
  7. + Math.sqrt(Math.pow(startX1 - startX0, 2) - Math.pow(((startX1 - startX0) / 2), 2)) / 2);
  8. startY1 = startY0;
  9. startY2 = startY0 - Math.sqrt(Math.pow(startX1 - startX0, 2) - Math.pow(((startX1 - startX0) / 2), 2));
  10.  
  11. paintKochCurve(order, startX0, startX1, startX2, startY0, startY1, startY2);
  12.  
  13. }
  14.  
  15. public void paintKochCurve(int order, double x0, double x1, double x2, double y0, double y1, double y2) {
  16. if (order == 0)
  17. ;//getChildren().add(new Polyline(startX0, startY0, startX1, startY0, startX2, startY2, startX0, startY0));
  18. else {
  19.  
  20. double uxs = Math.sqrt(Math.pow((x1 - x0) / 3, 2) - Math.pow((y0 - y2) / 3, 2)) + x2;
  21. double uys = ((y0 - y2) / 3) + y2;
  22. double uxe = Math.sqrt(Math.pow((2 * (x1 - x0)) / 3, 2) - Math.pow((2 * (y0 - y2)) / 3, 2)) + x2;
  23. double uye = (2 * (y0 - y2)) / 3 + y2;
  24. double uxp = x1;
  25. double uyp = uys;
  26.  
  27. double dxs = ((x1 - x0) / 3) + x0;
  28. double dys = y0;
  29. double dxe = (2 * (x1 - x0)) / 3 + x0;
  30. double dye = y0;
  31. double dxp = (x1 + x0) / 2;
  32. double dyp = y0 + Math.sqrt(Math.pow(dxe - dxs, 2) - Math.pow(((dxe - dxs) / 2), 2));
  33.  
  34. double txs = dxs;
  35. double tys = ((y0 - y2) / 3) + y2;
  36. double txe = -Math.sqrt(Math.pow((2 * (x1 - x0)) / 3, 2) - Math.pow((2 * (y0 - y2)) / 3, 2)) + x2;
  37. double tye = (2 * (y0 - y2)) / 3 + y2;
  38. double txp = x0;
  39. double typ = tys;
  40.  
  41. getChildren().add(new
  42. Polyline(x2,y2,uxs,uys,uxp,uyp,uxe,uye,x1,y0));
  43. getChildren().add(new
  44. Polyline(x0,y0,dxs,dys,dxp,dyp,dxe,dye,x1,y0));
  45. getChildren().add(new
  46. Polyline(x2,y2,txs,tys,txp,typ,txe,tye,x0,y0));
  47.  
  48. paintKochCurve(order - 1, uxs, uys, uxp, uyp, uxe, uye);
  49. paintKochCurve(order -1, dxs, dys, dxp, dyp, dxe, dye);
  50. paintKochCurve(order -1, txs, tys, txp, typ, txe, tye);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement