Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中计算SVG路径的椭圆路径坐标?_Javascript_Svg - Fatal编程技术网

如何在javascript中计算SVG路径的椭圆路径坐标?

如何在javascript中计算SVG路径的椭圆路径坐标?,javascript,svg,Javascript,Svg,在SVG中,使用椭圆标记创建椭圆形状很容易。 使用transform=“rotate”属性时,旋转该形状也很容易 但是,我需要在香草Javascript中创建许多具有一定旋转度的椭圆路径,因为稍后我将在animateMotion中使用它们 理想的函数应该是: function ellipsePath(rx, ry, cx, cy, degrees){ //create the elliptical path return "path"; } 示例代码(您应该测试它): 函数椭圆分离(r

在SVG中,使用
椭圆
标记创建椭圆形状很容易。 使用
transform=“rotate”
属性时,旋转该形状也很容易

但是,我需要在香草Javascript中创建许多具有一定旋转度的椭圆路径,因为稍后我将在
animateMotion
中使用它们

理想的函数应该是:

function ellipsePath(rx, ry, cx, cy, degrees){
  //create the elliptical path

 return "path";
}
示例代码(您应该测试它):

函数椭圆分离(rx、ry、cx、cy、度){
//创建椭圆路径
var numPoints=10,i,x,y,toRad=Math.PI/180,
角度=0,da=度/点数;

对于(i=0;该函数是错误的,因为在循环迭代过程中x和y始终相同。此外,该函数不创建旋转椭圆。@用户2070775度的作用不清楚,如果它仅表示椭圆的圆弧或旋转椭圆,如果需要,我可以更新答案(尽管wiki链接也包含旋转椭圆的公式),但我只想说,答案中提到的是部分答案。因此,你可以在投票前要求更新新信息
function ellipsePath(rx, ry, cx, cy, degrees){
  //create the elliptical path
 var numPoints = 10, i, x, y, toRad = Math.PI/180,
     angle = 0, da = degrees/numPoints;
 for (i=0; i<numPoints; i++)
 { 
    x = rx * Math.cos(angle*toRad) + cx;
    y = ry * Math.sin(angle*toRad) + cy;
    angle += da;
   // use x,y points to add to the SVG path
 }
 return "path";
}