Trochoid.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var Path = require("../Path");
  2. /**
  3. * 内外旋轮曲线
  4. * @module zrender/graphic/shape/Trochold
  5. */
  6. var cos = Math.cos;
  7. var sin = Math.sin;
  8. var _default = Path.extend({
  9. type: 'trochoid',
  10. shape: {
  11. cx: 0,
  12. cy: 0,
  13. r: 0,
  14. r0: 0,
  15. d: 0,
  16. location: 'out'
  17. },
  18. style: {
  19. stroke: '#000',
  20. fill: null
  21. },
  22. buildPath: function (ctx, shape) {
  23. var x1;
  24. var y1;
  25. var x2;
  26. var y2;
  27. var R = shape.r;
  28. var r = shape.r0;
  29. var d = shape.d;
  30. var offsetX = shape.cx;
  31. var offsetY = shape.cy;
  32. var delta = shape.location === 'out' ? 1 : -1;
  33. if (shape.location && R <= r) {
  34. return;
  35. }
  36. var num = 0;
  37. var i = 1;
  38. var theta;
  39. x1 = (R + delta * r) * cos(0) - delta * d * cos(0) + offsetX;
  40. y1 = (R + delta * r) * sin(0) - d * sin(0) + offsetY;
  41. ctx.moveTo(x1, y1); // 计算结束时的i
  42. do {
  43. num++;
  44. } while (r * num % (R + delta * r) !== 0);
  45. do {
  46. theta = Math.PI / 180 * i;
  47. x2 = (R + delta * r) * cos(theta) - delta * d * cos((R / r + delta) * theta) + offsetX;
  48. y2 = (R + delta * r) * sin(theta) - d * sin((R / r + delta) * theta) + offsetY;
  49. ctx.lineTo(x2, y2);
  50. i++;
  51. } while (i <= r * num / (R + delta * r) * 360);
  52. }
  53. });
  54. module.exports = _default;