HTML5 Canvas: get curve's coordinates

蓝咒 提交于 2019-12-13 15:33:12

问题


I have a quadratic curve in canvas (defined by start, end and control point). What I need is to get more of the curve's coordinates (eg. the middle, quarters etc.). With that, I'd be able (after a few iterations of finding coordinates) to animate an object based on this curve (I know it can be done easily with SVG, but that's not an option).

image taken from http://www.html5canvastutorials.com/tutorials/html5-canvas-quadratic-curves/

Is there an easy way to do this? When I checked for bisecting curve on google, the only thing I found was some complicated Math including drawing, which is out of the question.


回答1:


These functions may be of interest to you:

Kinetic.Path.getPointOnCubicBezier = function(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y)
Kinetic.Path.getPointOnQuadraticBezier = function(pct, P1x, P1y, P2x, P2y, P3x, P3y)



回答2:


I am seeking a similar solution for bezier curves. How do I get a list of the coordinates on the curve?

To solve your problem, perhaps you could plugin the x-coordinate (or y-coordinate) into the quadratic equation:

y = a*x^2 + b*x + c

I can't seem to find a function that returns the coordinates of the curve. It would be nice to get a list of the coordinates for any curve / shape.



来源:https://stackoverflow.com/questions/12420092/html5-canvas-get-curves-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!