0

Well I`m trying to find solution to a small problem.

I have multiple points on a canvas and have to connect them with a straight line. So exactly one incoming or outgoing connection per point. I have the 2 points for a line.

It all works with canvas.drawline(...) method. But now i want to be able to detect if a there was a click/touch event on a particular line within the line + padding area.

As line is drawn inside a rectangular bounding box its size varies based on the length and frequently overlaps with other bounding boxes. So considering touch within the bounding box is completely dumb i guess.

Can someone please give me some input in this direction? Thanks a lot!

GIGAMOLE
  • 1,274
  • 1
  • 11
  • 17
niknitesh
  • 1
  • 2

1 Answers1

0

You can calculate perpendicular distance of the touch from the line.If the distance is within some range(in your case padding size) you consider as touch event on the line.

To calculate perpendicular distance use this formula refer-Shortest distance between a point and a line segment

Community
  • 1
  • 1
rupesh jain
  • 3,410
  • 1
  • 14
  • 22