Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class SphericBezier extends AbstractNode {
  2.  
  3. private Vector a;
  4. private Vector b;
  5.  
  6.  
  7.  
  8. public SphericBezier(Vector position , Vector end, Vector a , Vector b ) {
  9. super(position , end);
  10. this.a = a;
  11. this.b = b;
  12. }
  13.  
  14.  
  15. public void reCalculate() {
  16. Vector last ;
  17. Vector v ;
  18. double l = 0;
  19. last = getFirst().clone();
  20.  
  21. float jump = (float) 1/getPrecision();
  22. for (int j = 0 ; j <= getPrecision() ; j++) {
  23. v = calculate(jump+j);
  24. l += last.distance(v);
  25. setLength(l);
  26. }
  27. }
  28.  
  29. public Vector calculate(float range) {
  30. //t = 1-range
  31. float t = 1-range;
  32. //p-0
  33. Vector v = getFirst().clone();
  34. v.multiply(Math.pow(t, 3));
  35. //p-1
  36. Vector c = a.clone();
  37. c.multiply(3*Math.pow(t, 2)*range);
  38. v.add(c);
  39. //p-2
  40. c = b.clone();
  41. c.multiply(3*Math.pow(t, 2)*Math.pow(range, 2));
  42. v.add(c);
  43. //p-3
  44. c = getLast().clone();
  45. c.multiply(Math.pow(range, 3));
  46. v.add(c);
  47. return v;
  48. }
  49.  
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement