在 d3.js 中查找路径的切线 [英] Find tangent of path in d3.js

查看:41
本文介绍了在 d3.js 中查找路径的切线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想沿路径放置 svg 元素(例如椭圆),例如使用 d3.js 生成的曲线 带 B 样条插值的线生成器.虽然使用 path.getPointAtLength() 可以轻松找到沿路径点的坐标,但我无法弄清楚如何找到线上任何点的切线.如果我能得到切线(或导数),我就可以相应地旋转元素,使它们看起来好像沿着线定位.

I'd like to position svg elements (say, ellipses) along a path, for instance a curve generated with a d3.js line generator with B-spline interpolation. While finding the coordinates of points along the path is easy using path.getPointAtLength(), I can't figure out how to find the tangent of any point on the line. If I could get the tangent (or the derivative), I would be able to rotate the elements accordingly to make them look as if they are positioned along the line.

推荐答案

在靠近的两个点调用 path.getPointAtLength().微积分告诉我们区别在于那个点的斜率/切线.

Call path.getPointAtLength() at two points close together. Calculus tells us the difference is the slope/tangent at that point.

这篇关于在 d3.js 中查找路径的切线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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