1

I allowed myself to use image from other stackoverflow's question. I hope that's fine

I allowed myself to use image from other stackoverflow's question. I hope that's fine

So using using functions of Path class (https://api.flutter.dev/flutter/dart-ui/Path-class.html) we can draw picture above

path.moveTo(startPoint.x, startPoint.y)
path.quadraticBezierTo(handlePoint.x, handlePoint.y,  endPoint.x, endPoint.y) 

My question is how I can calculate x,y of the highest point on drawn line ?

sonic
  • 1,282
  • 1
  • 9
  • 22

2 Answers2

0

Use any ui softwares like Photoshop. Create a canvas of same size that you are planning to use while drawing this path in flutter. Now use a pen tool and draw a curve. Now you should get a handle on each point. By handle i mean a line that denotes the direction and length of curve. Check the right side handles position in the canvas using ruler (ctrl+ r) that's the top most point you are looking for.. also there are a few online tools available to convert svg to path if you are looking for an easy alternative

Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30
  • I'm sorry if my question made you angry. – sonic Jul 31 '22 at 17:48
  • No no sorry if i sounded rude. Thats really a hack to find the points. I have used this method to trace a design and find its points. – Kaushik Chandru Jul 31 '22 at 17:52
  • ok. I just didn't get the answer really. Would I get from there some formula ? – sonic Jul 31 '22 at 17:56
  • no you wont get a formula in photoshop. Sorry. May i please know what you are trying to achieve? The formula can be found by clicking on the specific class you are already using.. hold ctrl and click on quadratic beizer to and it eill show all codes in that method – Kaushik Chandru Jul 31 '22 at 18:15
  • never mind, I won't be using photoshop for it. Thank you for trying to help anyway. – sonic Jul 31 '22 at 18:27
0

SOLUTION

ok So I went for PathMetric class, this is what is needed to find solution without finding the right mathematical formula.

List<PathMetric> metric = path.computeMetrics().toList();
PathMetric pathMetric = metric[0];
double lastPoint = size.height / 2;
double rightTangentOffset = 0;

for (double i = 0; i < pathMetric.length; i = i + 1) {
  if (pathMetric.getTangentForOffset(i).position.dy < lastPoint) { // only for up parabola
    lastPoint = pathMetric.getTangentForOffset(i).position.dy;
    rightTangentOffset = i;
  }
}
Offset position = pathMetric.getTangentForOffset(rightTangentOffset).position;
canvas.drawCircle(position, circleSize, circleOnLine);

you get an idea... lastPoint is due to where I start drawing.

sonic
  • 1,282
  • 1
  • 9
  • 22