java - Point orientation relative to a line -


i'm trying write method in java determines orientation of position relative line.

a little context: (not necessary answer may helpful) i'm working on collision detection ball on body parts on player. player has head chest knee ankle , toe, defined having position , tether position. example tether position head chest, chest position of player(or hips) , on.

for collision detection have function written determines distance between ball , body parts, fails catch when body part dragged , skips on ball.

i have methods in each body part class supposed determine orientation of position relative body part.

the methods wrote call getangle method: pivotpos , basepos base line, , position method called

public double getangle(position basepos, position pivotpos) {     double baseangle = math.todegrees(math.atan2(             pivotpos.gety() - basepos.gety(),             pivotpos.getx() - basepos.getx())) + 180;     double otherangle = math.todegrees(math.atan2(             this.gety() - pivotpos.gety(), this.getx() - pivotpos.getx()));     return baseangle - otherangle; } 

this have written chest , head.

@override public int isongoodside(position p, double radius) {     double angle1 = p.getangle(tetherposition, position);     double angle2 = p.getangle(position, tetherposition);     if (angle1 >= 270 && angle2 <= 90) {         if (p.distancebetweenpointandline(tetherposition, position) > radius) {             return 1;         }         return -1;     } else if (angle1 <= 90 && angle2 >= 270) {         return -1;     }     return 0; } 

this have written knee ankle , toe

@override public int isongoodside(position p, double radius) {     double angle1 = p.getangle(position, tetherposition);     double angle2 = p.getangle(tetherposition, position);     if (angle2 <= 90 && angle1 >= 270) {         if (p.distancebetweenpointandline(tetherposition, position) > radius){             return 1;            }         return -1;     } else if (angle2 >= 270 && angle1 <= 90) {         return -1;     }     return 0; } 

here part of test cases.

public void test_isongoodside() {     position pos1 = new position(10, 10);     position pos2 = new position(20, 10);      // horizontal line     position pos7 = new position(15, 15);     position pos8 = new position(15, 5);     position pos9 = new position(5, 100);     position pos10 = new position(25, 20);      knee knee1 = new knee(pos1, pos2);     assertequals(1, knee1.isongoodside(pos7, 0));     assertequals(-1, knee1.isongoodside(pos8, 0));     assertequals(0, knee1.isongoodside(pos9, 0));     assertequals(0, knee1.isongoodside(pos10, 0)); 

basically these methods done work, have plenty of test cases cant figure out error. if see wrong code or can offer solution helpful. tried read through jon shewchuk's "fast robust predicates computational geometry" couldn't understand it. in advance!


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -