java - How to check whether the given points are in the line segment or not? -


this question has answer here:

how check whether given points in line segment or not?

i used @ first:

if (s == null) { return false; } if (!(s instanceof point)) { return false; } return (x == ((point) s).x && y == ((point) s).y);  

but didn't work, because linesegment not object..

this code far:

public class point {      double x;     double y;         public point(double x, double y) {          this.x = x;         this.y = y;     }     public string tostring () {         return "(" + x + ", " + y + ")";     }      public line straightthrough (point p) {     // todo      }      public boolean onlinesegment(linesegment s) {          if (s == null) {             return false;         // todo         }     } } 

edit: know there questions on here may same mine... answer needed wasn't there.

well, assuming if line segment defined 2 points: enpoint , startpoint, how can test if given point on line segment:

boolean     isonlinesegment(linesegment seg, point test) {  return  (   (test.y-seg.startpoint.y)/(test.x-seg.startpoint.x) == (test.y-seg.endpoint.y)/(test.x-seg.endpoint.y);  } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -