#3にも誤記が・・・(^^;
3つの頂点の点Aが作る三つの三角形の面積の和が
正三角形と等しい
ではなく
3つの頂点のうち2つと点Aが作る三つの三角形の面積の和が正三角形と等しい
ですね。
試しにくんでみたら、下記のようになりました
-----------------------------------------------
package JavaTest;
import JavaTest.Point;
class MyJava
{
public static void main(String ar[])
{
Point pInput = new Point(11,1);
Point pJu = new Point(0,0);
Point pCho = new Point(0,10);
String str;
boolean fIn = Mathplus.IsIn(pInput,pJu,pCho);
if(fIn)
{
str = "正三角形内";
}
else
{
str = "正三角形外";
}
System.out.println(str);
}
}
class Mathplus
{
public static double degrees(double dR)
{
return 180 * dR / Math.PI;
}
public static double radians(double dD)
{
return Math.PI * dD / 180;
}
public static double mod(double dA, double dB)
{
double dR = Math.floor(dA / dB);
return dA - dR * dB;
}
public static boolean IsIn(Point pInput, Point pJu, Point pCho)
{
double d = pJu.Distance(pCho);
double dTheta = Mathplus.mod(
360+90-Mathplus.degrees(Math.atan2(pCho.y,pCho.x)),360);
Point pCho2 = new Point(
Math.sin(Mathplus.radians(dTheta+120))*(d),
Math.cos(Mathplus.radians(dTheta+120))*(d));
Point pCho3 = new Point(
Math.sin(Mathplus.radians(dTheta+240))*(d),
Math.cos(Mathplus.radians(dTheta+240))*(d));
double dSum = pInput.Distance(pCho,pCho2) +
pInput.Distance(pCho2,pCho3) +
pInput.Distance(pCho3,pCho);
Point pM = new Point((pCho2.x+pCho3.x)/2,(pCho2.y+pCho3.y)/2);
double dTakasa = pCho.Distance(pM);
return Math.abs(dTakasa - dSum) < 0.00000001;
}
}
-----------------------------------------------
package JavaTest;
/**
* Pointクラス
*/
public class Point
{
public double x,y;
public Point()
{
x = 0;
y = 0;
}
public Point(double px,double py)
{
x = px;
y = py;
}
public double Distance(Point p1)
{
double r = Math.sqrt(
((p1.x-this.x)*(p1.x-this.x)+
(p1.y-this.y)*(p1.y-this.y)));
return r;
}
public double Distance(Point p1,Point p2)
{
Point pT = new Point(0,0);
double vec_x, vec_y, alpha,len;
vec_x = p2.x-p1.x;
vec_y = p2.y-p1.y;
alpha = ( vec_x * this.x + vec_y * this.y
-vec_x * p1.x - vec_y * p1.y) /
(vec_x * vec_x + vec_y * vec_y);
if (alpha < 0.0)
{
len = Distance(p1);
}
else if (alpha > 1.0)
{
len = Distance(p2);
}
else
{
pT.x = p1.x + vec_x * alpha;
pT.y = p1.y + vec_y * alpha;
len = Distance(pT);
}
return len;
}
}
-----------------------------------------------