// |
// |
// |
|
// |
|
// $B:BI87O$,2hLL:BI87O(B($B:8>e$,(B(0,0))$B$G$"$k$3$H$KCm0U$9$k(B |
// $B:BI87O$,2hLL:BI87O(B($B:8>e$,(B(0,0))$B$G$"$k$3$H$KCm0U$9$k(B |
// |
// |
|
// (0,-1) |
|
// (-1,0) (0,0) (1,0) |
|
// (0,1) |
public final class Point { |
public final class Point { |
double x,y; |
double x,y; |
// 10^-5$B0J2<$O(B0$B$H8+$J$9!%(B |
// 10^-5$B0J2<$O(B0$B$H8+$J$9!%(B |
public Point minus(Point p){ |
public Point minus(Point p){ |
return new Point(x-p.getX(),y-p.getY()); |
return new Point(x-p.getX(),y-p.getY()); |
} |
} |
|
public Point neg(){ |
|
return new Point(-x,-y); |
|
} |
public Point times(double r){ |
public Point times(double r){ |
return new Point(x*r,y*r); |
return new Point(x*r,y*r); |
} |
} |
|
public Point timesX(double r){ |
|
return new Point(x*r,y); |
|
} |
|
public Point timesY(double r){ |
|
return new Point(x,y*r); |
|
} |
// $B%Y%/%?!<$ND9$5$r(B newLength$B$K@55,2=$9$k!%(B |
// $B%Y%/%?!<$ND9$5$r(B newLength$B$K@55,2=$9$k!%(B |
public Point normal(double newLength){ |
public Point normal(double newLength){ |
double ratio=newLength/length(); |
double ratio=newLength/length(); |
public Point rot270(){ |
public Point rot270(){ |
return new Point(-y,x); |
return new Point(-y,x); |
} |
} |
|
// $BG$0UEY$N2sE>(B |
|
public Point rot(double theta){ |
|
double cosTheta=Math.cos(theta),sinTheta=Math.sin(theta); |
|
return new Point(x*cosTheta+y*sinTheta,-x*sinTheta+y*cosTheta); |
|
} |
// $B<+J,$H%Y%/%?!<(Bp$B$NFb@Q(B(inner product) |
// $B<+J,$H%Y%/%?!<(Bp$B$NFb@Q(B(inner product) |
public double product(Point p){ |
public double product(Point p){ |
return x*p.x+y*p.y; |
return x*p.x+y*p.y; |
} |
} |
|
// (1,0)$B$+$i8+$?<+J,$N3QEY(B |
|
public double theta(){ |
|
return Math.atan2(-y,x); |
|
} |
// $B<+J,$+$i%Y%/%?!<(Bp$B$r8+$?3QEY$N(B cos |
// $B<+J,$+$i%Y%/%?!<(Bp$B$r8+$?3QEY$N(B cos |
public double cosTheta(Point p){ |
public double cosTheta(Point p){ |
return product(p)/(p.length()*length()); |
return product(p)/(p.length()*length()); |
} |
} |
// $B<+J,$+$i%Y%/%?!<(Bp$B$r8+$?3QEY$N(B sin |
// $B<+J,$+$i%Y%/%?!<(Bp$B$r8+$?3QEY$N(B sin |
public double cosTheta(Point p){ |
public double sinTheta(Point p){ |
return rot270().cosTheta(p); |
return rot270().cosTheta(p); |
} |
} |
// $B<+J,$+$i%Y%/%?!<(B p $B$r8+$?3QEY(B |
// $B<+J,$+$i%Y%/%?!<(B p $B$r8+$?3QEY(B |