四分之一圆的d3路径半径计算 [英] d3 path radius calculation for quarter circle

查看:182
本文介绍了四分之一圆的d3路径半径计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两点之间绘制一条路径,该点有一个四分之一圆弧,圆弧半径= x2-x1.

I'd like to draw a path between two points, which has a quarter circle arc where the arc radius = x2-x1.

例如:

x1=100
y1=100
x2=300
y2=300

我正在使用:

dx = x2-x1,
dy = y2-y1,
dr = Math.sqrt(dx*dx+dy*dy);    
return "M" + x1 + "," + y1 + "A" + dr + "," + dr + " 0 0,1 " + x2 + "," + y2;

我正在努力为四分之一圆半径计算正确的博士.

I am struggling to calculate the correct dr for the quarter circle radius.

谢谢

推荐答案

在这种情况下,连接两个点的线就是三角形的斜边.另一侧将具有相同的长度,即半径.您可以这样计算:

In this case, the line connecting your two points would be the hypotenuse of your triangle. The other sides would have the same length, i.e. the radius. You can calculate it like this:

var dr = Math.sqrt((dx*dx+dy*dy)/2);

完整示例: http://jsfiddle.net/E7JPy/1/

这篇关于四分之一圆的d3路径半径计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆