d7685c9bbbb9eeb4609b7d5d45d32bd6faa1afc0.svn-base 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" >
  2. <head>
  3. <title>Approximation of an arc with bezier</title>
  4. <style type="text/css">
  5. @import "../../../dojo/resources/dojo.css";
  6. @import "../../../dijit/tests/css/dijitTests.css";
  7. </style>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <!--
  10. The next line should include Microsoft's Silverligth.js, if you plan to use the silverlight backend
  11. <script type="text/javascript" src="Silverlight.js"></script>
  12. -->
  13. <script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true"></script>
  14. <script type="text/javascript" src="../_base.js"></script>
  15. <script type="text/javascript" src="../shape.js"></script>
  16. <script type="text/javascript" src="../path.js"></script>
  17. <script type="text/javascript" src="../arc.js"></script>
  18. <!--<script type="text/javascript" src="../vml.js"></script>-->
  19. <!--<script type="text/javascript" src="../svg.js"></script>-->
  20. <!--<script type="text/javascript" src="../canvas.js"></script>-->
  21. <!--<script type="text/javascript" src="../silverlight.js"></script>-->
  22. <script type="text/javascript">
  23. dojo.require("dojox.gfx");
  24. makeShapes = function(){
  25. var surface = dojox.gfx.createSurface("test", 500, 300);
  26. var g = surface.createGroup();
  27. // create a reference ellipse
  28. var rx = 200;
  29. var ry = 100;
  30. var startAngle = -30;
  31. var arcAngle = -90;
  32. var axisAngle = -30;
  33. var e = g.createEllipse({rx: rx, ry: ry}).setStroke({});
  34. // calculate a bezier
  35. var alpha = dojox.gfx.matrix._degToRad(arcAngle) / 2; // half of our angle
  36. var cosa = Math.cos(alpha);
  37. var sina = Math.sin(alpha);
  38. // start point
  39. var p1 = {x: cosa, y: sina};
  40. // 1st control point
  41. var p2 = {x: cosa + (4 / 3) * (1 - cosa), y: sina - (4 / 3) * cosa * (1 - cosa) / sina};
  42. // 2nd control point (symmetric to the 1st one)
  43. var p3 = {x: p2.x, y: -p2.y};
  44. // end point (symmetric to the start point)
  45. var p4 = {x: p1.x, y: -p1.y};
  46. // rotate and scale poins as appropriate
  47. var s = dojox.gfx.matrix.normalize([dojox.gfx.matrix.scale(e.shape.rx, e.shape.ry), dojox.gfx.matrix.rotateg(startAngle + arcAngle / 2)]);
  48. p1 = dojox.gfx.matrix.multiplyPoint(s, p1);
  49. p2 = dojox.gfx.matrix.multiplyPoint(s, p2);
  50. p3 = dojox.gfx.matrix.multiplyPoint(s, p3);
  51. p4 = dojox.gfx.matrix.multiplyPoint(s, p4);
  52. // draw control trapezoid
  53. var t = g.createPath().setStroke({color: "blue"});
  54. t.moveTo(p1.x, p1.y);
  55. t.lineTo(p2.x, p2.y);
  56. t.lineTo(p3.x, p3.y);
  57. t.lineTo(p4.x, p4.y);
  58. t.lineTo(p1.x, p1.y);
  59. t.moveTo((p1.x + p4.x) / 2, (p1.y + p4.y) / 2);
  60. t.lineTo((p2.x + p3.x) / 2, (p2.y + p3.y) / 2);
  61. t.moveTo((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
  62. t.lineTo((p3.x + p4.x) / 2, (p3.y + p4.y) / 2);
  63. // draw a bezier
  64. var b = g.createPath().setStroke({color: "red"});
  65. b.moveTo(p1.x, p1.y);
  66. b.curveTo(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
  67. // move everything in a middle
  68. g.setTransform([dojox.gfx.matrix.translate(250, 150), dojox.gfx.matrix.rotateg(axisAngle)]);
  69. };
  70. dojo.addOnLoad(makeShapes);
  71. </script>
  72. </head>
  73. <body>
  74. <h1>Approximation of an arc with bezier</h1>
  75. <!--<p><button onclick="makeShapes();">Make</button></p>-->
  76. <div id="test" style="width: 500px; height: 300px;"></div>
  77. <p>That's all Folks!</p>
  78. </body>
  79. </html>