如何在javascript中计算SVG路径的椭圆路径坐标?
在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
椭圆
标记创建椭圆形状很容易。
使用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";
}