harvester's blog

By harvester, history, 4 weeks ago, translation, In English,

I tried to implement it myself but caught some bugs that I didn't debug yet. How would you implement this function: check if a whole ((ax1, ay1), (ax2, ay2)) segment is part of ((bx1, by1), (bx2, by2)) segment?

  • Vote: I like it  
  • +4
  • Vote: I do not like it  

4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Find eq of line passing through (bx1,by1) (bx2,by2) which is (y-by1)*(bx2-bx1)=(by2-by1)*(x-bx1)....put ax1 at x and ay1 at y..if LHS==RHS then further check for ax2 and ay2 and if LHS=RHS then we can be sure that these points lie on the line passing through (bx1,by1) (bx2,by2).To check for part of we need to check ax1>=bx1 and ax2<=bx2 if we sort the segments such that (ax1<=ax2 and bx1<=bx2).

4 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
  1. Check if all segments connecting every two point has the same delta y over delta x.

2.If yes it becomes a one dimensional problem (be aware of vertical lines)