Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package azaza;
- public class Segment {
- private IVector start, end;
- public Segment(IVector start, IVector end) {
- this.start = start;
- this.end = end;
- }
- public IVector getStart() {return start;}
- public IVector getEnd() {return end;}
- public double length() {return this.end.sub(this.start).length();}
- public double distanceTo(IVector point) {
- IVector mainSideA = end.sub(start);
- IVector sideB = point.sub(start);
- IVector sideC = point.sub(end);
- double mainA = mainSideA.length();
- double B = sideB.length();
- double C = sideC.length();
- double p = (mainA+B+C)/2;
- double S = Math.sqrt(p*(p-mainA)*(p-B)*(p-C));
- double distance = 2*S/mainA;
- return distance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement