Calculate pixels between two points on a image

China☆狼群 提交于 2019-12-06 01:20:17

Distance between two points (Pythagora):

dx = x1 - x2;
dy = y1 - y2;

dist = sqrt (dx*dx + dy*dy);

Distance between two horizontal lines:

d = y1 - y2;

If your lines are defined as y1 = k1x + n1 and y2 = k2x + n2, then (they're horizontal, k1 and k2 are 0) the distance between them is n2 - n1.

EDIT: ok, after you edited your question it makes a bit more sense now. But still: since you (or user) is adding the lines, your code always knows where they lie. Their end coordinates would be:

line1: {(0,y1):(picture.width,y1)} line2: {(0,y2):(picture.width,y2)} distance: |y2-y1|

Since they're both horizontal they ofcourse never cross.

You should just keep a reference to y1 and y2 (from the line-placing code) in an appropriate space. Since your question is for Android and iOS the answer is: in that part of code that would correspond to model in MVC.

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