IoU icon indicating copy to clipboard operation
IoU copied to clipboard

is there a logic error in Line::isOnEdge() function?

Open zhuzy-2018 opened this issue 4 years ago • 1 comments

in iou.cpp line27-29,it is said: if (abs(pp1^pp2) < EPS && pp1pp2 < EPS) return true; which from my point of view is |pp1||pp2|sin(pp1,pp2)<EPS and |pp1||pp2|*cos(pp1,pp2)<EPS. but it doesnt mean that p is on p1p2.

why dont you use the value of cos/sin of pp1 and pp2 to judge if p in on line p1p2?

zhuzy-2018 avatar Jul 28 '21 03:07 zhuzy-2018

简单解释一下:

这个接口是判断点是否在线段

  1. abs(pp1^pp2) < EPS(即sin(pp1,pp2)<EPS)说明点PP1P2共线(EPS为容差值)
  2. 满足1)的条件下还存在三种可能 a. PP1P2线段上(P1_P_P2为180度) b. PP1P2线段的延长线上(P1_P_P2为0度) c. P在一个相对很远的位置(P1_P_P2为0度,类似于b,算是一种退化?)
  3. 通过pp1pp2 < EPS排除情况b)和c)

应该是等效于你提到的sin/cos,对2)中不满足的情况无法排除,而且存在除零的风险

我的方法存在归一化的问题,建议对PP1PP2进行一下归一化

weiquanmao avatar Jul 28 '21 14:07 weiquanmao