8
I need to figure out the rendered size of a curve on canvas 2d
context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
with this code, for example
// pontos de controle
var cp1x = 200,
cp1y = 150,
cp2x = 260,
cp2y = 10;
var x = 0,
y = 0;
// calculação
var curveWidth = cp1x > x ? cp1x - x : x - cp1x,
curveHeight = cp1y > y ? cp1y - y : y - cp1y;
However, point cp2 can further lengthen the curve if it exceeds an initial or final point (this is what happens in this code, cp1x = 200, cp2x = 260
). For example, let’s assume that the point cp2 is marked with the red dot in this image and that its x coordinate is greater than the x coordinate of cp1, which appears to be the end point of the curve:
So how can I consider the width of point cp2 in the value of curveWidth
and the value of curveHeight
to be exact?
It seems to be useful! Unfortunately my notebook is not calling, but I will test your code on mobile, vlw by attention
– Klaider
I do not know if in the mobile application appears the button to run the code, but going through the Chrome of my mobile did not appear. Anyway good luck with the design and with the notebook. Suddenly it’s just discharged battery.
– Antonio Alexandre
I was able to run the code on https://jsfiddle.net, it was just a bit Tricky to copy it :v. Um..., I think the notebook battery is damaged. When I can get back to working on it I will use your utility to see the differences between control points!
– Klaider