(* ::Package:: *)

(* DyGeom.m   by Kazushi Ahara *)
(* pre-alpha version *)


DyGeomVersion="0.30";(*\:73fe\:5728\:306e\:30d0\:30fc\:30b8\:30e7\:30f3*)
MyTeXFileName="zu.tex";(*\:51fa\:529b\:30d5\:30a1\:30a4\:30eb\:540d\:6307\:5b9a*)
MyPolynomialCalculation=False;(*\:6570\:5f0f\:8a08\:7b97\:3092\:3059\:308b\:30d5\:30e9\:30b0*)
MyXYDomain=True; (*\:63cf\:753b\:7bc4\:56f2\:3092\:81ea\:52d5\:691c\:51fa\:3059\:308b\:30d5\:30e9\:30b0*)
MyAxes=False; (*\:8ef8\:3092\:63cf\:753b\:3059\:308b\:305f\:3081\:306e\:30d5\:30e9\:30b0*)
MyDeath=False; (*\:6b7b\:4ea1\:30d5\:30e9\:30b0*)


If[FileExistsQ["ketpic6.m"], <<ketpic6.m; ,
	If[FileExistsQ["ketpic5.m"], <<ketpic5.m;,
		Print["You need ketpic package for mathematica."];
		Exit[];
	];
]
NextPointName = "P";
NextPointNumber = 0;
NextLineName = "L";
NextLineNumber = 0;
NextCircleName = "C";
NextCircleNumber = 0;
NextFunctionName = "F";
NextFunctionNumber = 0;
NextMarkName = "M";
NextMarkNumber = 0;


GetNewPointName[] := Module[{},
	NextPointNumber=NextPointNumber+1;
	NextPointName<>ToString[NextPointNumber]
]

GetNewLineName[] := Module[{},
	NextLineNumber ++;
	NextLineName<>ToString[NextLineNumber]
]

GetNewCircleName[] := Module[{},
	NextCircleNumber ++;
	NextCircleName<>ToString[NextCircleNumber]
]

GetNewFunctionName[] := Module[{},
	NextFunctionNumber ++;
	NextFunctionName<>ToString[NextFunctionNumber]
]

GetNewMarkName[] := Module[{},
	NextMarkNumber ++;
	NextMarkName<>ToString[NextMarkNumber]
]



ReduceTriple[arg_]:=Module[{myGCD,ret},
ret=arg;
If[Length[arg]>=3,
	If[IntegerQ[arg[[1]]] && IntegerQ[arg[[2]]]&&IntegerQ[arg[[3]]], 
		myGCD=GCD[arg[[1]],arg[[2]],arg[[3]]];
		(*Print["myGCD@ReduceTriple=",myGCD];*)
		ret=If[myGCD!=0, arg/myGCD]; , 
		If[NumberQ[arg[[3]]]&&Abs[arg[[3]]]>1000, ret=arg/arg[[3]];];(* \:5206\:6bcd\:304c\:5927\:304d\:304f\:306a\:308a\:3059\:304e\:305f\:3089\:6d6e\:52d5\:5c0f\:6570\:70b9\:8a08\:7b97\:306b\:79fb\:308b\:3002*) 	
	];
];
ret
]

ReduceTriplePolynomial[arg_]:=Module[{myGCD,newLL},
newLL=arg;
myGCD=PolynomialGCD[arg[[1]],arg[[2]],arg[[3]]];
If[!(myGCD===0), 
	(*Print[Together[{arg[[1]],arg[[2]],arg[[3]]}/myGCD]];*)
	newLL=Together[{arg[[1]],arg[[2]],arg[[3]]}/myGCD];
	If[Length[arg]>3,
		newLL=Append[newLL,arg[[4]]];
	]; 
];
newLL
]



\:70b9[argseq__] := Module[{},FreePoint[argseq]]
FreePoint[argseq__] := Module[ {args,myname,ptx,pty},
args={argseq};
myname = GetNewPointName[];
If[NumberQ[args[[1]]], ptx=args[[1]], ptx = NextPointNumber];
args = Drop[args , 1];
If[NumberQ[args[[1]]], pty=args[[1]], pty = 0];
args = Drop[args , 1];
If[MyPolynomialCalculation, 
	Append[{"Point",myname,{ptx,pty,1},{myname<>"x",myname<>"y",myname<>"z",{}}},args],
	Append[{"Point",myname,{ptx,pty,1},{0,0,0}},args]]
]

\:76f4\:7dda\:4e0a\:306e\:70b9[argseq__]:=Module[{}, PointOnLine[argseq]]
PointOnLine[argseq__]:=Module[{args,myname,p1,p2,ln,ptx,pty,ptz,ret},
args={argseq};
myname = GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0,{}},{}};
If[Length[args]>=3,
	If[NumberQ[args[[1]]] && NumberQ[args[[2]]] && Length[args[[3]]]>=3,
		p1=args[[1]];
		p2=args[[2]];
		ln=args[[3]];
	];
	If[NumberQ[args[[2]]] && NumberQ[args[[3]]] && Length[args[[1]]]>=3,
		p1=args[[2]];
		p2=args[[3]];
		ln=args[[1]];
	];
	If[ln[[1]]=="Line",
		ln=ln[[3]];
		args=Drop[args,3];
		ptx=ln[[2]]^2*p1-ln[[1]]*ln[[2]]*p2-ln[[1]]*ln[[3]];
		pty=-ln[[2]]*ln[[1]]*p1+ln[[1]]^2*p2-ln[[2]]*ln[[3]];
		ptz=ln[[1]]^2+ln[[2]]^2;
		If[MyPolynomialCalculation,
			ret=Append[{"Point",myname,{ptx,pty,ptz},{myname<>"x",myname<>"y",myname<>"z",{ln[[1]]*myname<>"x"+ln[[2]]*myname<>"y"+ln[[3]]*myname<>"z"}}},args];,
			ret=Append[{"Point",myname,{ptx,pty,ptz},{0,0,0}},args];
		];
	];
];
ret
]

\:5186\:4e0a\:306e\:70b9[argseq__]:=Module[{}, PointOnCircle[argseq]]
PointOnCircle[argseq__]:=Module[{args,myname,p1,p2,ci,cicenter,ciradius,myp1,myp2,ptx,pty,ret},
args={argseq};
myname = GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0,{}},{}};
If[Length[args]>=3,
	If[NumberQ[args[[1]]] && NumberQ[args[[2]]] && Length[args[[3]]]>=3,
		p1=args[[1]];
		p2=args[[2]];
		ci=args[[3]];
	];
	If[NumberQ[args[[2]]] && NumberQ[args[[3]]] && Length[args[[1]]]>=3,
		p1=args[[2]];
		p2=args[[3]];
		ci=args[[1]];
	];
	(*Print[{p1,p2,ci}];*)
	If[ci[[1]]=="Circle" && ci[[3]][[1]]!=0,
		ci=ci[[3]];
		args=Drop[args,3];
		cicenter={ci[[2]]/(-2*ci[[1]]),ci[[3]]/(-2*ci[[1]])};
		ciradius=CircleRadius[ci];
		If[p1==cicenter[[1]] && p2==cicenter[[2]], p1=p1+1;]; (*\:6307\:5b9a\:3057\:305f\:70b9\:304c\:4e2d\:5fc3\:3068\:4e00\:81f4\:3057\:305f\:3068\:304d\:306e\:4f8b\:5916\:51e6\:7406*)
		If[Im[cicenter]!=0, cicenter=1;]; (*\:534a\:5f84\:304c\:865a\:6570\:306e\:3068\:304d\:306e\:4f8b\:5916\:51e6\:7406*)
		myp1={p1,p2};
		myp2=cicenter+(myp1-cicenter)*ciradius/Norm[myp1-cicenter];
		(*Print[{cicenter,ciradius,Norm[myp1-cicenter]}];*)
		If[MyPolynomialCalculation,
			ret=Append[{"Point",myname,Join[myp2,{1}],{myname<>"x",myname<>"y",myname<>"z",{ci[[1]]*((myname<>"x")^2+(myname<>"y")^2)+ci[[2]]*(myname<>"x")*(myname<>"z")+ci[[3]]*(myname<>"y")*(myname<>"z")+ci[[4]]*(myname<>"z")^2}}},args];,
			ret=Append[{"Point",myname,Join[myp2,{1}],{0,0,0}},args];
		];
	];
];
ret
]



ConnectPointsCoord[arg1_,arg2_] := Module[ {pt1,pt2,rel1,rel2},
pt1=arg1[[1;;3]];
pt2=arg2[[1;;3]];
If[Length[arg1]>3, rel1=arg1[[4]], rel1={};];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={};];
{ arg1[[2]]*arg2[[3]]-arg1[[3]]*arg2[[2]],
arg1[[3]]*arg2[[1]]-arg1[[1]]*arg2[[3]],
arg1[[1]]*arg2[[2]]-arg1[[2]]*arg2[[1]],Join[rel1,rel2] }
]

\:7dda\:5206[argseq__] := Module[{args,myname,p1,p2,ret},
args={argseq};
myname = GetNewLineName[];
ret={"Line",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
	p1=args[[1]];
	p2=args[[2]];
	args=Drop[args,2];
	args=Append[args,clipping->{p1,p2}];
	If[p1[[1]]=="Point" && p2[[1]]=="Point",
		(*Print["p1[[3]],p2[[3]]=",p1[[3]],p2[[3]]];*)
		(*Print["ConnectPointsCoord=",ConnectPointsCoord[p1[[3]],p2[[3]]]];*)
		ret={"Line",myname, 
		ReduceTriple[ConnectPointsCoord[p1[[3]],p2[[3]]]],
		ReduceTriplePolynomial[ConnectPointsCoord[p1[[4]],p2[[4]]]],
		args} ;
	];
];
ret
]

\:76f4\:7dda[argseq__] := Module[{},ConnectPoints[argseq]]
ConnectPoints[argseq__] := Module[ {args,myname,p1,p2,ret},
args={argseq};
myname = GetNewLineName[];
ret={"Line",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
	p1=args[[1]];
	p2=args[[2]];
	args=Drop[args,2];
	If[p1[[1]]=="Point" && p2[[1]]=="Point",
		(*Print["p1[[3]],p2[[3]]=",p1[[3]],p2[[3]]];*)
		(*Print["ConnectPointsCoord=",ConnectPointsCoord[p1[[3]],p2[[3]]]];*)
		ret={"Line",myname, 
		ReduceTriple[ConnectPointsCoord[p1[[3]],p2[[3]]]],
		ReduceTriplePolynomial[ConnectPointsCoord[p1[[4]],p2[[4]]]],
		args} ;
	];
];
ret
]



MidPointCoord[arg1_,arg2_] := Module[ {pt1,pt2,rel1,rel2},
pt1=arg1[[1;;3]];
pt2=arg2[[1;;3]];
(*Print["MidPointCoord:",{pt1,pt2}];*)
If[Length[arg1]>3, rel1=arg1[[4]], rel1={};];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={};];
{pt1[[1]]*pt2[[3]]+pt2[[1]]*pt1[[3]],
pt1[[2]]*pt2[[3]]+pt2[[2]]*pt1[[3]],
2*pt1[[3]]*pt2[[3]],Join[rel1,rel2]}
]

\:4e2d\:70b9[argseq__] := Module[{},MidPoint[argseq]]
MidPoint[argseq__] := Module[ {args,myname,p1,p2,ret},
args={argseq};
myname = GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
	p1=args[[1]];
	p2=args[[2]];
	args=Drop[args,2];
	If[p1[[1]]=="Point" && p2[[1]]=="Point",
		ret={"Point",myname,
		ReduceTriple[MidPointCoord[p1[[3]],p2[[3]]]],
		MidPointCoord[p1[[4]],p2[[4]]],
		args}; 
	];
];
ret
]



IntersectionLL[argseq__]:=Module[{args,myname,l1,l2,ret},
args={argseq};
myname=GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0},{}};
	l1=args[[1]];
	l2=args[[2]];
	args=Drop[args,2];
	If[l1[[1]]=="Line" && l2[[1]]=="Line",
		ret={"Point",myname, 
		ReduceTriple[ConnectPointsCoord[l1[[3]],l2[[3]]]],
		ReduceTriplePolynomial[ConnectPointsCoord[l1[[4]],l2[[4]]]],
		args} ;
	];
ret
]

IntersectionLCCoord[arg1_,arg2_]:=Module[{ln,ci,x1,x2,y1,y2,z1,rel1,rel2},
ln=arg1[[1;;3]];
ci=arg2[[1;;4]];
If[Length[arg1]>3, rel1=arg1[[4]], rel1={};];
If[Length[arg2]>4, rel2=arg2[[5]], rel2={};];
x1=-2*ln[[1]]*ln[[3]]*ci[[1]]-ln[[2]]^2*ci[[2]]+ln[[1]]*ln[[2]]*ci[[3]];
x2=ln[[2]]*Sqrt[4*ln[[3]]*ci[[1]]*(-ln[[3]]*ci[[1]]+ln[[1]]*ci[[2]]+ln[[2]]*ci[[3]])+(ln[[2]]*ci[[2]]-ln[[1]]*ci[[3]])^2-4*(ln[[1]]^2+ln[[2]]^2)*ci[[1]]*ci[[4]]];
z1=2*(ln[[1]]^2+ln[[2]]^2)*ci[[1]];
y1=-2*ln[[2]]*ln[[3]]*ci[[1]]-ln[[1]]^2*ci[[3]]+ln[[1]]*ln[[2]]*ci[[2]];
y2=-ln[[1]]*Sqrt[4*ln[[3]]*ci[[1]]*(-ln[[3]]*ci[[1]]+ln[[1]]*ci[[2]]+ln[[2]]*ci[[3]])+(ln[[2]]*ci[[2]]-ln[[1]]*ci[[3]])^2-4*(ln[[1]]^2+ln[[2]]^2)*ci[[1]]*ci[[4]]];
Print["IntersectionLCCoord:",{x1,x2,y1,y2,z1}];
{x1,x2,y1,y2,z1,Join[rel1,rel2]}
]

GetRadicalLine[ci1_,ci2_]:=Module[{radicalline},
radicalline={0,0,0,{}};
If[Length[ci1]>=4 && Length[ci2]>=4 , 
	If[Length[ci1]>=5, 
		radicalline={ci1[[2]]*ci2[[1]]-ci2[[2]]*ci1[[1]],ci1[[3]]*ci2[[1]]-ci2[[3]]*ci1[[1]],ci1[[4]]*ci2[[1]]-ci2[[4]]*ci1[[1]],ci1[[5]]};,
		radicalline={ci1[[2]]*ci2[[1]]-ci2[[2]]*ci1[[1]],ci1[[3]]*ci2[[1]]-ci2[[3]]*ci1[[1]],ci1[[4]]*ci2[[1]]-ci2[[4]]*ci1[[1]],{}};
	];
];
radicalline
]

IntersectionLC[argseq__]:=Module[{args,myname,ln,ci,radicalline,ret1,res1,ret2,res2,ret,option,i,norm1,norm2,epsilon},
args={argseq};
myname=GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0},{}};
ln=args[[1]];
If[ln[[1]]=="Circle", ci=args[[1]]; ln=args[[2]];, ci=args[[2]]];
args=Drop[args,2];
If[ln[[1]]=="Line" && ci[[1]]=="Circle",
(*Print["Checkpoint: IntersectionLC"];*)
	epsilon=1;
	ret1=IntersectionLCCoord[ln[[3]],ci[[3]]];
	For[i=1,i<=Length[args],i++,
		If[args[[i]][[1]]==near, 
			If[Length[args[[i]][[2]]]>1,
				If[NumberQ[args[[i]][[2]][[1]]] && ret1[[5]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					If[norm1<norm2, epsilon=1, epsilon=-1];
				];
				If[args[[i]][[2]][[1]]=="Point" && args[[i]][[2]][[3]][[3]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					If[norm1<norm2, epsilon=1, epsilon=-1];
				];
			];
		];	
		If[args[[i]][[1]]==farfrom || args[[i]][[1]]==not, 
			If[Length[args[[i]][[2]]]>1,
				If[NumberQ[args[[i]][[2]][[1]]] && ret[[5]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					If[norm1>norm2, epsilon=1, epsilon=-1];
				];
				If[args[[i]][[2]][[1]]=="Point" && args[[i]][[2]][[3]][[3]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					(*Print["norm1=",norm1," : norm2=",norm2];*)
					If[norm1>norm2, epsilon=1, epsilon=-1];
				];
			];
		];	
		If[args[[i]][[1]]==direction ,
			If[args[[i]][[2]]=="e",
				If[ret1[[2]]*ret1[[5]]>=0, epsilon=1, epsilon=-1];
			];
			If[args[[i]][[2]]=="w",
				If[ret1[[2]]*ret1[[5]]<0, epsilon=1, epsilon=-1];
			];
			If[args[[i]][[2]]=="n",
				If[ret1[[4]]*ret1[[5]]>=0, epsilon=1, epsilon=-1];
			];
			If[args[[i]][[2]]=="s",
				If[ret1[[4]]*ret1[[5]]<0, epsilon=1, epsilon=-1];
			];
		];
	];
	If[epsilon==1, 
		res1={ret1[[1]]+ret1[[2]],ret1[[3]]+ret1[[4]],ret1[[5]],ret1[[6]]};,
		res1={ret1[[1]]-ret1[[2]],ret1[[3]]-ret1[[4]],ret1[[5]],ret1[[6]]}; 
	];
	ret2=IntersectionLCCoord[ln[[4]],ci[[4]]];
	If[MyPolynomialCalculation, 
		res2={ret2[[1]]+epsilon*(myname<>"d1"),ret2[[3]]+epsilon*(myname<>"d2"),ret2[[5]],Join[ret2[[6]],{ret2[[2]]^2-(myname<>"d1")^2,ret2[[4]]^2-(myname<>"d2")^2}]};
		ret={"Point",myname,ReduceTriple[res1],ReduceTriplePolynomial[res2],args} ;\:3000,
		res2={0,0,0,{}};
		ret={"Point",myname,ReduceTriple[res1],res2,args} ;\:3000
	];
];
If[ln[[1]]=="Circle" && ci[[1]]=="Circle",
	Print["Checkpoint: IntersectionCC"];
	epsilon=1;
	radicalline=GetRadicalLine[ln[[3]],ci[[3]]];
	(*Print["radicalline = ",radicalline];*)
	ret1=IntersectionLCCoord[radicalline,ci[[3]]];
	For[i=1,i<=Length[args],i++,
		If[args[[i]][[1]]==near, 
			If[Length[args[[i]][[2]]]>1,
				If[NumberQ[args[[i]][[2]][[1]]] && ret1[[5]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					If[norm1<norm2, epsilon=1, epsilon=-1];
				];
				If[args[[i]][[2]][[1]]=="Point" && args[[i]][[2]][[3]][[3]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					If[norm1<norm2, epsilon=1, epsilon=-1];
				];
			];
		];	
		If[args[[i]][[1]]==farfrom || args[[i]][[1]]==not, 
			If[Length[args[[i]][[2]]]>1,
				If[NumberQ[args[[i]][[2]][[1]]] && ret[[5]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[1]],args[[i]][[2]][[2]]}];
					If[norm1>norm2, epsilon=1, epsilon=-1];
				];
				If[args[[i]][[2]][[1]]=="Point" && args[[i]][[2]][[3]][[3]]!=0,
					norm1=Norm[{(ret1[[1]]+ret1[[2]])/ret1[[5]],(ret1[[3]]+ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					norm2=Norm[{(ret1[[1]]-ret1[[2]])/ret1[[5]],(ret1[[3]]-ret1[[4]])/ret1[[5]]}-{args[[i]][[2]][[3]][[1]]/args[[i]][[2]][[3]][[3]],args[[i]][[2]][[3]][[2]]/args[[i]][[2]][[3]][[3]]}];
					(*Print["norm1=",norm1," : norm2=",norm2];*)
					If[norm1>norm2, epsilon=1, epsilon=-1];
				];
			];
		];	
		If[args[[i]][[1]]==direction ,
			If[args[[i]][[2]]=="e",
				If[ret1[[2]]*ret1[[5]]>=0, epsilon=1, epsilon=-1];
			];
			If[args[[i]][[2]]=="w",
				If[ret1[[2]]*ret1[[5]]<0, epsilon=1, epsilon=-1];
			];
			If[args[[i]][[2]]=="n",
				If[ret1[[4]]*ret1[[5]]>=0, epsilon=1, epsilon=-1];
			];
			If[args[[i]][[2]]=="s",
				If[ret1[[4]]*ret1[[5]]<0, epsilon=1, epsilon=-1];
			];
		];
	];
	If[epsilon==1, res1={ret1[[1]]+ret1[[2]],ret1[[3]]+ret1[[4]],ret1[[5]]},res1={ret1[[1]]-ret1[[2]],ret1[[3]]-ret1[[4]],ret1[[5]],ret1[[6]]} ];
	ret2=IntersectionLCCoord[GetRadicalLine[ln[[4]],ci[[4]]],ci[[4]]];
	If[MyPolynomialCalculation, 
		res2={ret2[[1]]+epsilon*(myname<>"d1"),ret2[[3]]+epsilon*(myname<>"d2"),ret2[[5]],Join[ret2[[6]],{ret2[[2]]^2-(myname<>"d1")^2,ret2[[4]]^2-(myname<>"d2")^2}]};
		ret={"Point",myname,ReduceTriple[res1],ReduceTriplePolynomial[res2],args} ;\:3000,
		res2={0,0,0,{}};
		ret={"Point",myname,ReduceTriple[res1],res2,args} ;\:3000
	];
];
ret
]

Crossing[argseq__]:=Module[{}, GeomIntersection[argseq]]
\:4ea4\:70b9[argseq__]:=Module[{}, GeomIntersection[argseq]]
GeomIntersection[argseq__]:=Module[{args,myname,ret},
args={argseq};
myname=GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
(*Print[args[[1]][[1]],"  ",args[[2]][[1]],"->" ];*)
	If[args[[1]][[1]]=="Line" && args[[2]][[1]]=="Line", ret=IntersectionLL[argseq]];	
	If[args[[1]][[1]]=="Circle" && args[[2]][[1]]=="Line", ret=IntersectionLC[argseq]];	
	If[args[[1]][[1]]=="Line" && args[[2]][[1]]=="Circle", ret=IntersectionLC[argseq]];	
	If[args[[1]][[1]]=="Circle" && args[[2]][[1]]=="Circle", ret=IntersectionLC[argseq]];	
];
ret
]


\:5e73\:884c\:7dda[argseq__] := Module[ {},ParallelLine[argseq]]
ParallelLineCoord[arg1_,arg2_] := Module[ {ln1,pt1,rel1,rel2},
ln1=arg1[[1;;3]];
pt1=arg2[[1;;3]];
If[Length[arg1]>3, rel1=arg1[[4]], rel1={}];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={}];
{ln1[[1]]*pt1[[3]],ln1[[2]]*pt1[[3]],-(ln1[[1]]*pt1[[1]]+ln1[[2]]*pt1[[2]]),Join[rel1,rel2]}
]

ParallelLine[argseq__] := Module[ {args,myname,l1,p1,ret},
args={argseq};
myname = GetNewLineName[];
ret={"Line",myname,{0,0,0,{}},{0,0,0,{}},{}};
If[Length[args]>=2,
	l1=args[[1]];
	If[l1[[1]]=="Point", p1=l1;l1=args[[2]], p1=args[[2]];];
	args=Drop[args,2];
	If[l1[[1]]=="Line" && p1[[1]]=="Point",
		ret={"Line",myname,
		ReduceTriple[ParallelLineCoord[l1[[3]],p1[[3]]]],
		ParallelLineCoord[l1[[4]],p1[[4]]],
		args}; 
	];
];
ret
]



\:5782\:7dda[argseq__] := Module[ {},PerpendicularLine[argseq]]
PerpendicularCoord[arg1_,arg2_] := Module[ {args,ln1,pt1,rel1,rel2},
ln1=arg1[[1;;3]];
pt1=arg2[[1;;3]];
If[Length[arg1]>3, rel1=arg1[[4]], rel1={}];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={}];
{-ln1[[2]]*pt1[[3]],ln1[[1]]*pt1[[3]],ln1[[2]]*pt1[[1]]-ln1[[1]]*pt1[[2]],Join[rel1,rel2]}
]

PerpendicularLine[argseq__] := Module[ {args,myname,l1,p1,ret},
args={argseq};
myname = GetNewLineName[];
ret={"Line",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
	l1=args[[1]];
	If[l1[[1]]=="Point", p1=l1;l1=args[[2]], p1=args[[2]];];
	args=Drop[args,2];
	If[l1[[1]]=="Line" && p1[[1]]=="Point",
		ret={"Line",myname,
		ReduceTriple[PerpendicularCoord[l1[[3]],p1[[3]]]],
		PerpendicularCoord[l1[[4]],p1[[4]]],
		args}; 
	];
];
ret
]



\:89d2\:5ea6\:7dda[argseq__]:=Module[{}, AngleLine[argseq]]
AngleLineCoord[arg1_,arg2_,arg3_] := Module[ {args,ln1,pt1,theta,rel1,rel2},
ln1=arg1[[1;;3]];
pt1=arg2[[1;;3]];
If[Length[arg1]>3, rel1=arg1[[4]], rel1={}];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={}];
theta=arg3;
{(Cos[theta]*ln1[[1]]-Sin[theta]*ln1[[2]])*pt1[[3]],(Sin[theta]*ln1[[1]]+Cos[theta]*ln1[[2]])*pt1[[3]],-((Cos[theta]*ln1[[1]]-Sin[theta]*ln1[[2]])*pt1[[1]]+(Sin[theta]*ln1[[1]]+Cos[theta]*ln1[[2]])*pt1[[2]]),Join[rel1,rel2]}
]

AngleLine[argseq__] := Module[ {args,myname,l1,p1,theta,ret},
args={argseq};
myname = GetNewLineName[];
ret={"Line",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=3 && NumberQ[args[[3]]],
	l1=args[[1]];
	If[l1[[1]]=="Point", p1=l1;l1=args[[2]], p1=args[[2]];];
	theta=args[[3]];
	args=Drop[args,3];
	If[IntegerQ[theta], theta=theta*Pi/180];
	If[l1[[1]]=="Line" && p1[[1]]=="Point",
		ret={"Line",myname,
		ReduceTriple[AngleLineCoord[l1[[3]],p1[[3]],theta]],
		AngleLineCoord[l1[[4]],p1[[4]],theta],
		args}; 
	];
];
ret
]



CircleCoord[arg1_,arg2_] := Module[ {args,pt1,pt2,rel1,rel2},
pt1=arg1[[1;;3]];
pt2=arg2[[1;;3]];
If[Length[arg1]>3, rel1=arg1[[4]], rel1={};];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={};];
{pt1[[3]]*pt2[[3]]^2,
-2*pt1[[1]]*pt2[[3]]^2,
-2*pt1[[2]]*pt2[[3]]^2,
-pt1[[3]]*(pt2[[1]]^2+pt2[[2]]^2)+2*(pt1[[1]]*pt2[[1]]+pt1[[2]]*pt2[[2]])*pt2[[3]],Join[rel1,rel2]}
]

CircleRadius[ci_]:=Module[{},
If[ci[[1]]!=0, Sqrt[-ci[[4]]/ci[[1]]+(ci[[2]]^2+ci[[3]]^2)/(4*ci[[1]]^2)], 0]
]

\:5186[argseq__]:=Module[{},CircleByCenter[argseq]]
CircleByCenter[argseq__]:=Module[{args,myname,p1,p2,ret},
args={argseq};
myname=GetNewCircleName[];
ret={"Circle",myname,{0,0,0,0},{0,0,0,0},{}};
If[Length[args]>=2,
	p1=args[[1]];
	p2=args[[2]];
	args=Drop[args,2];
	If[p1[[1]]=="Point" && p2[[1]]=="Point",
		ret={"Circle",myname,
		CircleCoord[p1[[3]],p2[[3]]],
		CircleCoord[p1[[4]],p2[[4]]],
		args}; 
	];
];
ret
]



\:30b3\:30f3\:30d1\:30b9[argseq__]:=Module[{},CircleByCompass[argseq]]
CircleByCompassCoord[arg1_,arg2_,arg3_]:=Module[{rel1,rel2,rel3},
If[Length[arg1]>3, rel1=arg1[[4]], rel1={};];
If[Length[arg2]>3, rel2=arg2[[4]], rel2={};];
If[Length[arg3]>3, rel3=arg3[[4]], rel3={};];
	{arg1[[3]]^2*arg2[[3]]^2*arg3[[3]]^2,
	-2*arg1[[3]]^2*arg2[[3]]^2*arg3[[1]],
	-2*arg1[[3]]^2*arg2[[3]]^2*arg3[[2]],
	-(arg1[[1]]*arg2[[3]]-arg2[[1]]*arg1[[3]])^2*arg3[[3]]^2-(arg1[[2]]*arg2[[3]]-arg2[[2]]*arg1[[3]])^2*arg3[[3]]^2+(arg3[[1]]^2+arg3[[2]]^2)*arg1[[3]]^2*arg2[[3]]^2,Join[rel1,rel2,rel3]}
]

CircleByCompass[argseq__]:=Module[{args,myname,p1,p2,p3,ret},
args={argseq};
myname=GetNewCircleName[];
ret={"Circle",myname,{0,0,0,0},{0,0,0,0},{}};
If[Length[args]>=3,
	p1=args[[1]];
	p2=args[[2]];
	p3=args[[3]];
	args=Drop[args,3];
	If[p1[[1]]=="Point" && p2[[1]]=="Point" && p3[[1]]=="Point",
		ret={"Circle",myname,
		CircleByCompassCoord[p1[[3]],p2[[3]],p3[[3]]],
		CircleByCompassCoord[p1[[4]],p2[[4]],p3[[4]]],
		args};
	];
];
ret
]



\:89d2\:4e8c\:7b49\:5206[argseq__]:=Module[{},BisectorBy3[argseq]]
BisectorBy3Coor[arg1_,arg2_,arg3_]:=Module[{d12,d23,pn,rel1,rel3},
If[Length[arg1]>3, rel1=arg1[[4]], rel1={};];
If[Length[arg3]>3, rel3=arg3[[4]], rel3={};];
If[arg1[[3]]!=0 && arg2[[3]]!=0 && arg3[[3]]!=0,
	d12=Sqrt[(arg1[[1]]/arg1[[3]]-arg2[[1]]/arg2[[3]])^2+(arg1[[2]]/arg1[[3]]-arg2[[2]]/arg2[[3]])^2];
	d23=Sqrt[(arg3[[1]]/arg3[[3]]-arg2[[1]]/arg2[[3]])^2+(arg3[[2]]/arg3[[3]]-arg2[[2]]/arg2[[3]])^2];
	pn={arg1[[1]]*arg3[[3]]*d23+arg3[[1]]*arg1[[3]]*d12,arg1[[2]]*arg3[[3]]*d23+arg3[[2]]*arg1[[3]]*d12,(d12+d23)*arg1[[3]]*arg3[[3]],Join[rel1,rel3]};,
	pn={0,0,0,{}}
];
ConnectPointsCoord[pn,arg2]
]

BisectorBy3[argseq__]:=Module[{args,myname,p1,p2,p3,pn,len12,len23,ret},
args={argseq};
myname = GetNewLineName[];
ret={"Line",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=3,
	p1=args[[1]];
	p2=args[[2]];
	p3=args[[3]];
	args=Drop[args,3];
	If[p1[[1]]=="Point" && p2[[1]]=="Point" && p3[[1]]=="Point" && p1[[3]][[3]]!=0 && p2[[3]][[3]]!=0 && p3[[3]][[3]]!=0,
		ret={"Line",myname,
		N[BiangularBy3Coor[p1[[3]],p2[[3]],p3[[3]]]],
		BiangularBy3Coor[p1[[4]],p2[[4]],p3[[4]]],
		args};
	];
];
ret
]



\:30b0\:30e9\:30d5[argseq__]:=Module[{},FunctionGraph[argseq]]
FunctionGraph[argseq__]:=Module[{args,myname,ret,funct,src,tgt,j},
args={argseq};
myname = GetNewFunctionName[];
ret={"Function",myname,0,{x,-5,5},{}};
If[Length[args]>=2,
	funct=args[[1]];
	src=args[[2]];
	args=Drop[args,2];
	ret={"Function",myname,funct,src,args};
];
ret
]
\:30b0\:30e9\:30d5\:4e0a\:306e\:70b9[argseq__]:=Module[{},PointOnFunctionGraph[argseq]]
PointOnFunctionGraph[argseq__]:=Module[{args,myname,ret,funct,ptdt,ptx,pty,var},
args={argseq};
myname=GetNewPointName[];
ret={"Point",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
	funct=0;ptx=-9999;
	If[NumberQ[args[[2]]],
		If[args[[1]][[1]]=="Function",
			funct=args[[1]][[3]];
			ptx=args[[2]];
		];
	];
	If[NumberQ[args[[1]]],
		If[args[[2]][[1]]=="Function",
			funct=args[[2]][[3]];
			ptx=args[[1]];
		];
	];
	If[Length[args[[2]]]==2 && args[[1]][[1]]=="Function",
		ptdt=nearestpt[ args[[2]], plotdata[args[[1]][[3]],args[[1]][[4]]] ];
		(*Print["ptdt=",ptdt];*)
		funct=args[[1]][[3]];
		ptx=ptdt[[1]][[1]];
	];
	If[Length[args[[1]]]==2 && args[[2]][[1]]=="Function",
		ptdt=nearestpt[ args[[1]], plotdata[args[[2]][[3]],args[[2]][[4]]] ];
		(*Print["ptdt=",ptdt];*)
		funct=args[[2]][[3]];
		ptx=ptdt[[1]][[1]];
	];
	If[ptx!=-9999,
		var=x; (* \:56fa\:5b9a*)
		pty=ReplaceAll[funct,var->ptx];
		args=Drop[args,2];
		ret={"Point",myname,{ptx,pty,1},{myname<>"x",ReplaceAll[funct,var->(myname<>"x")],1},args};
	];
];
ret
]

\:30b0\:30e9\:30d5\:306e\:63a5\:7dda[argseq__]:=Module[{},TangentLineOnGraph[argseq]]
TangentLineOnGraph[argseq__]:=Module[{args,ret,myname,var,funct,ptx,pty,gradient,der,ptname},
args={argseq};
myname=GetNewLineName[];
ret={"Line",myname,{0,0,0},{0,0,0},{}};
If[Length[args]>=2,
	If[args[[1]][[1]]=="Function" && args[[2]][[1]]=="Point" && args[[2]][[3]][[3]]!=0,
		var=x; (* \:56fa\:5b9a*)
		ptname=args[[2]][[2]];
		funct=args[[1]][[3]];
		ptx=args[[2]][[3]][[1]]/args[[2]][[3]][[3]];
		pty=ReplaceAll[funct,var->ptx];
		der=D[funct,var];
		gradient=ReplaceAll[der,var->ptx];
		args=Drop[args,2];
		ret={"Line",myname,{gradient,-1,-ptx*gradient+pty},{ReplaceAll[der,var->(ptname<>"x")],-1,-(ptname<>"x")*ReplaceAll[der,var->(ptname<>"x")]+ReplaceAll[funct,var->(ptname<>"x")]},args};
	];
];
ret
]	


\:89d2\:5ea6\:5370[argseq__]:=Module[{},AngleMarkBy3[argseq]]
AngleMarkBy3[argseq__]:=Module[{args,mkname,p1,p2,p3,ret},
args={argseq};
mkname = GetNewMarkName[];
ret={"Mark",mkname,{0,0,0},{0,0,0},{}};
If[Length[args]>=3,
	p1=args[[1]];
	p2=args[[2]];
	p3=args[[3]];
	args=Drop[args,3];
	If[p1[[1]]=="Point" && p2[[1]]=="Point" && p3[[1]]=="Point" && p1[[3]][[3]]!=0 && p2[[3]][[3]]!=0 && p3[[3]][[3]]!=0,
		ret={"Mark",mkname,
		{p1[[3]],p2[[3]],p3[[3]]},{0,0,0},
		args};
	];
];
ret
]

AngleMarkPosition[arg1_,arg2_,arg3_,mkpos_]:=Module[{d12,d32,d42,arg4},
d12=Norm[arg1-arg2];
d32=Norm[arg3-arg2];
arg4=(d32*arg1+d12*arg3)/(d12+d32);
d42=Norm[arg4-arg2];
arg2+(arg4-arg2)*mkpos/d42
]

\:30ab\:30c3\:30b3\:5370[argseq__]:=Module[{},BowMark[argseq]]
BowMark[argseq__]:=Module[{args,mkname,ret,pt1,pt2},
args={argseq};
mkname = GetNewMarkName[];
ret={"Bow",mkname,{0,0,0,0},{0,0,0},{}};
If[Length[args]>=2 && args[[1]][[1]]=="Point" && args[[2]][[1]]=="Point",
	pt1=args[[1]][[3]];
	pt2=args[[2]][[3]];
	args=Drop[args,2];
	If[pt1[[3]]!=0 && pt2[[3]]!=0,
		ret={"Bow",mkname,{pt1[[1]]/pt1[[3]],pt1[[2]]/pt1[[3]],
			pt2[[1]]/pt2[[3]],pt2[[2]]/pt2[[3]]},{0,0,0},args};
	];
];
ret
]


AddOption[arg1_,arg2_]:=Module[{arg15},
arg15=Append[arg1[[5]],arg2];
Append[Drop[arg1,-1],arg15]
]


GetXYdomain[argseq__]:= Module[ {obj,args,xmax,xmin,ymax,ymin,r2,option,clip1,clip2,xpos,ypos,i,j},
args={argseq};
ymax=xmax=-999;
ymin=xmin=999;
For[i=1,i<=Length[args],i++,
	obj=args[[i]][[3]];
	If[args[[i]][[1]]=="Point" && obj[[3]]!=0 , 
		If[Im[obj[[1]]/obj[[3]]]==0 && Im[obj[[2]]/obj[[3]]]==0,
			If[xmax<obj[[1]]/obj[[3]],xmax=obj[[1]]/obj[[3]]];
			If[xmin>obj[[1]]/obj[[3]],xmin=obj[[1]]/obj[[3]]];
			If[ymax<obj[[2]]/obj[[3]],ymax=obj[[2]]/obj[[3]]];
			If[ymin>obj[[2]]/obj[[3]],ymin=obj[[2]]/obj[[3]]];
		];
	];
	If[args[[i]][[1]]=="Line",
		option=args[[i]][[5]];
		clip1=clip2={};
		For[j=1,j<=Length[option],j++,
			Switch[option[[j]][[1]], 
				clipping, clip1=option[[j]][[2]][[1]];clip2=option[[j]][[2]][[2]];,
				\:5207\:308a\:53d6\:308a, clip1=option[[j]][[2]][[1]];clip2=option[[j]][[2]][[2]];
			];
		];
		If[Length[clip1]>0 && Length[clip2]>0 && clip1[[3]][[3]]!=0 && clip2[[3]][[3]]!=0, 
			obj=clip1[[3]];
			(*Print["clip1[[3]]=",obj];*)
			If[Im[obj[[1]]/obj[[3]]]==0 && Im[obj[[2]]/obj[[3]]]==0,
				If[xmax<obj[[1]]/obj[[3]],xmax=obj[[1]]/obj[[3]]];
				If[xmin>obj[[1]]/obj[[3]],xmin=obj[[1]]/obj[[3]]];
				If[ymax<obj[[2]]/obj[[3]],ymax=obj[[2]]/obj[[3]]];
				If[ymin>obj[[2]]/obj[[3]],ymin=obj[[2]]/obj[[3]]];
			];
			obj=clip2[[3]];
			If[Im[obj[[1]]/obj[[3]]]==0 && Im[obj[[2]]/obj[[3]]]==0,
				If[xmax<obj[[1]]/obj[[3]],xmax=obj[[1]]/obj[[3]]];
				If[xmin>obj[[1]]/obj[[3]],xmin=obj[[1]]/obj[[3]]];
				If[ymax<obj[[2]]/obj[[3]],ymax=obj[[2]]/obj[[3]]];
				If[ymin>obj[[2]]/obj[[3]],ymin=obj[[2]]/obj[[3]]];
			];
		];
	];
	If[args[[i]][[1]]=="Circle" && obj[[1]]!=0, 
		r2=-obj[[4]]/obj[[1]]+(obj[[2]]^2+obj[[3]]^2)/(4*obj[[1]]^2);
		If[r2>=0 && Im[obj[[2]]/obj[[1]]]==0 && Im[obj[[3]]/obj[[1]]]==0,
			If[r2>0 && xmax < (-obj[[2]]/(2*obj[[1]]))+Sqrt[r2], xmax = (-obj[[2]]/(2*obj[[1]]))+Sqrt[r2]];
			If[r2>0 && xmin > (-obj[[2]]/(2*obj[[1]]))-Sqrt[r2], xmin = (-obj[[2]]/(2*obj[[1]]))-Sqrt[r2]];
			If[r2>0 && ymax < (-obj[[3]]/(2*obj[[1]]))+Sqrt[r2], ymax = (-obj[[3]]/(2*obj[[1]]))+Sqrt[r2]];
			If[r2>0 && ymin > (-obj[[3]]/(2*obj[[1]]))-Sqrt[r2], ymin = (-obj[[3]]/(2*obj[[1]]))-Sqrt[r2]];
		];
	];
	If[args[[i]][[1]]=="Function",
		If[Length[args[[i]]]>=4,
			If[Length[args[[i]][[4]]]>=3,
(*Print[args[[i]][[4]],",",xmin,",",xmax];*)
				If[xmin>args[[i]][[4]][[2]], xmin=args[[i]][[4]][[2]]];
				If[xmax<args[[i]][[4]][[3]], xmax=args[[i]][[4]][[3]]];
			];
		];
		If[Length[args[[i]]]>=5,
			option=args[[i]][[5]];
			For[j=1,j<=Length[option],j++,
				If[option[[j]][[1]]==target && Length[option[[j]][[2]]]==2,
(*Print[option[[j]][[2]],",",ymin,",",ymax];*)
					If[ymax<option[[j]][[2]][[2]], ymax=option[[j]][[2]][[2]]];
					If[ymin>option[[j]][[2]][[1]], ymin=option[[j]][[2]][[1]]];
				];
			];
		];
	];
	If[args[[i]][[1]]=="Bow",
		xpos=obj[[1]]+0.1*(obj[[4]]-obj[[2]]);(*bow\:306ebending\:306b\:3088\:3063\:30660 .1\:306f\:5909\:66f4\:3057\:306a\:3051\:308c\:3070\:306a\:3089\:306a\:3044\:3002*)
		If[xmax<xpos,xmax=xpos];
		If[xmin>xpos,xmin=xpos];
		ypos=obj[[2]]-0.1(obj[[3]]-obj[[1]]);
		If[ymax<ypos,ymax=ypos];
		If[ymin>ypos,ymin=ypos];
		xpos=obj[[3]]+0.1*(obj[[4]]-obj[[2]]);
		If[xmax<xpos,xmax=xpos];
		If[xmin>xpos,xmin=xpos];
		ypos=obj[[4]]-0.1*(obj[[3]]-obj[[1]]);
		If[ymax<ypos,ymax=ypos];
		If[ymin>ypos,ymin=ypos];
	];
	If[xmax>=xmin+1, XMAX=(xmax*10-xmin)/9;XMIN=(xmin*10-xmax)/9;,
	XMAX=xmax+1;XMIN=xmin-1;];
	If[ymax>=ymin+1, YMAX=(ymax*10-ymin)/9;YMIN=(ymin*10-ymax)/9;,
	YMAX=ymax+1;YMIN=ymin-1;];
];
]





AlmostZero[arg_]:=Module[{},
If[Abs[arg]<0.0000001, True, False]
]
(*PossibleZeroQ\:3092\:7528\:3044\:3088\:3002*)
Incidency[arg1_,arg2_]:=Module[{txt,testfunction},
txt="";
If[arg1[[1]]=="Point" && arg2[[1]]=="Line",
	If[Abs[arg1[[3]][[1;;3]].arg2[[3]][[1;;3]]]>0.0000001, txt="No incidency";,
		testfunction=Factor[arg1[[4]][[1;;3]].arg2[[4]][[1;;3]]];
		If[AlmostZero[testfunction], 
			txt=arg1[[2]]<>" is on the line "<>arg2[[2]]<>"."; , 
			txt="No incidency";
		];
	];
];
If[arg1[[1]]=="Line" && arg2[[1]]=="Point",
	If[Abs[arg1[[3]][[1;;3]].arg2[[3]][[1;;3]]]>0.0000001, txt="No incidency";,
		testfunction=Factor[arg1[[4]][[1;;3]].arg2[[4]][[1;;3]]];
		If[AlmostZero[testfunction], 
			txt=arg2[[2]]<>" is on the line "<>arg1[[2]]<>"."; , 
			txt="No incidency";
		];
	];
];
txt
]



(* ketpic6\:5185\:306eparamark\:3088\:308a\:6539\:5909\:ff0e\:30d9\:30af\:30c8\:30eb\:306e\:9577\:3055\:306b\:4f9d\:5b58\:3057\:306a\:3044\:30de\:30fc\:30af\:3092\:633f\:5165\:ff0e*)
paraabsmark[argseq__] := Module[{args, nargs, pA, pB, pC, k, r, u, v}, 
     args = {argseq}; nargs = Length[args]; pA = args[[1]]; pB = args[[2]]; 
      pC = args[[3]]; k = 0.3; If[nargs >= 4, k = N[args[[4]]]]; 
      (*r = Min[vecnagasa[pA - pB], vecnagasa[pC - pB]]*k;*)
      r=k; 
      u = r*((pA - pB)/vecnagasa[pA - pB]); 
      v = r*((pC - pB)/vecnagasa[pC - pB]); 
      If[gaiseki[pA - pB, pC - pB] != 0, listplotdata[{pB + u, pB + u + v, 
         pB + v}], {}]]
(* ketpic6\:5185\:306eanglemark\:3088\:308a\:6539\:5909\:ff0e\:98fe\:308a\:306e\:30aa\:30d7\:30b7\:30e7\:30f3\:3092\:8ffd\:52a0*)

anglemarksub[pA_,pB_,pC_,r_]:=Module[{cir,tmp,p1,p2,eps,tmp1,tmp2},
eps = N[10^(-3)]; 
cir = circledata[pB, r]; 
tmp = First[intersectcrvsPp[cir, listplotdata[{pA, pB}]]]; 
p1 = tmp[[2]]; 
tmp = First[intersectcrvsPp[cir, listplotdata[{pC, pB}]]]; 
p2 = tmp[[2]]; 
(*Print["p1=",p1,",p2=",p2];*)
If[Abs[p1 - p2] < eps, 
	Return[{}]
]; 
If[p1 < p2 - eps, 
	partcrv[p1, p2, cir], 
	tmp = numptcrv[cir]; 
	(*Print["tmp=",tmp];*)
	tmp1 = partcrv[p1, tmp, cir]; 
	tmp2 = partcrv[1, p2, cir];  (* 1 \:306b\:6ce8\:610f*)
	joincrvs[tmp1, tmp2]
]
]

anglemarkposition[arg1_,arg2_,arg3_,mkpos_]:=Module[{d12,d32,d42,arg4},
d12=Norm[arg1-arg2];
d32=Norm[arg3-arg2];
arg4=(d32*arg1+d12*arg3)/(d12+d32);
d42=Norm[arg4-arg2];
arg2+(arg4-arg2)*mkpos/d42
]

myanglemark[argseq__] :=Module[{args, nargs, pA, pB, pC, eps, p1, p2, k, r,  cir, tmp, tmp1, tmp2,shapeoption,ret},
args = {argseq}; 
nargs = Length[args]; 
pA = args[[1]]; 
pB = args[[2]]; 
pC = args[[3]]; 
r = 0.5; 
shapeoption=0;
For[k=4,k<=nargs,k++,
	If[NumberQ[args[[k]]], 
		r = N[args[[k]]]*r;
	];
	Switch[args[[k]],
		"single", shapeoption=0,
		"double", shapeoption=1,
		"triple", shapeoption=2,
		"dash", shapeoption=3,
		"dashdouble", shapeoption=4,
		"circle", shapeoption=5,
		"singlecircle", shapeoption=6
	];
]; 
Switch[shapeoption,
	0,ret=anglemarksub[pA,pB,pC,r];,
	1,ret={anglemarksub[pA,pB,pC,r*0.9],anglemarksub[pA,pB,pC,r*1.1]};,
	2,ret={anglemarksub[pA,pB,pC,r*0.85],anglemarksub[pA,pB,pC,r],anglemarksub[pA,pB,pC,r*1.15]};,
	3,ret={anglemarksub[pA,pB,pC,r],listplotdata[{anglemarkposition[pA,pB,pC,r*1.2],anglemarkposition[pA,pB,pC,r*0.8]}]};,
	4,ret={anglemarksub[pA,pB,pC,r*0.9],anglemarksub[pA,pB,pC,r*1.1],listplotdata[{anglemarkposition[pA,pB,pC,r*1.3],anglemarkposition[pA,pB,pC,r*0.7]}]};,
	5,ret={anglemarksub[pA,pB,pC,r],circledata[anglemarkposition[pA,pB,pC,r],r*0.15]};,
	6,ret=circledata[anglemarkposition[pA,pB,pC,r*0.8],r*0.15]
];
ret
]



MakePlotData[argseq__]:=Module[{args,pd,pointdata,textdata,obj,xsect1,xsect2,option,myname,
ptposition,mysize,radius,clip1,clip2,x1,x2,x3,y1,y2,y3,r2,xxmax,xxmin,yymax,yymin,d12,d23,bending,spacing,theta},
args={argseq};
pd={};
pointdata={};
textdata={};
For[i=1,i<=Length[args],i++,
	obj=args[[i]][[3]];
	If[args[[i]][[1]]=="Point" && obj[[3]]!=0 , 
		myname="";ptposition="";mysize="";
		option=args[[i]][[5]];
		(*Print[option];*)
		For[j=1,j<=Length[option],j++,
			Switch[option[[j]][[1]], 
				pointname, myname=option[[j]][[2]],
				pointposition, ptposition=option[[j]][[2]],
				pointsize, mysize=option[[j]][[2]],
				\:540d\:524d, myname=option[[j]][[2]],
				\:4f4d\:7f6e, ptposition=option[[j]][[2]],
				\:5927\:304d\:3055, mysize=option[[j]][[2]]
			];
		];
		If[myname!="",
			textdata=Append[textdata,{obj[[1]]/obj[[3]],obj[[2]]/obj[[3]],ptposition,myname}]
		];
		If[NumberQ[mysize],
			radius=mysize, 
			radius=Switch[mysize,"small",1,"midium",2,"large",3,_,2]
		];
		pointdata=Append[pointdata,{obj[[1]]/obj[[3]],obj[[2]]/obj[[3]],radius}];
	];
	If[args[[i]][[1]]=="Line", 
		option=args[[i]][[5]];
		clip1=clip2={};
		For[j=1,j<=Length[option],j++,
			Switch[option[[j]][[1]], 
				clipping, If[Length[option[[j]][[2]]]>=2, clip1=option[[j]][[2]][[1]];clip2=option[[j]][[2]][[2]]];,
				\:5207\:308a\:53d6\:308a, If[Length[option[[j]][[2]]]>=2, clip1=option[[j]][[2]][[1]];clip2=option[[j]][[2]][[2]]];
			];
		];
		xxmax=XMAX;xxmin=XMIN;yymax=YMAX;yymin=YMIN;
		(*Print["Here I am. ",Length[clip1]," and ",Length[clip2]];*)
		If[Length[clip1]>=3 && Length[clip2]>=3, 
			(*Print["I'm in depth 2. ",clip1[[3]][[3]]];*)
			If[clip1[[1]]=="Point" && clip2[[1]]=="Point" && clip1[[3]][[3]]!=0 && clip2[[3]][[3]]!=0,
				(*Print[clip1];*)
				xxmax=yymax=-999; xxmin=yymin=999;
				x1=clip1[[3]][[1]]/clip1[[3]][[3]];
				If[xxmax<x1,xxmax=x1];
				If[xxmin>x1,xxmin=x1];
				x2=clip2[[3]][[1]]/clip2[[3]][[3]];
				If[xxmax<x2,xxmax=x2];
				If[xxmin>x2,xxmin=x2];
				y1=clip1[[3]][[2]]/clip1[[3]][[3]];
				If[yymax<y1,yymax=y1];
				If[yymin>y1,yymin=y1];
				y2=clip2[[3]][[2]]/clip2[[3]][[3]];
				If[yymax<y2,yymax=y2];
				If[yymin>y2,yymin=y2];
			];
			(*Print[xxmax,xxmin,yymax,yymin]; *)
		];
		If[AlmostZero[obj[[2]]] && obj[[1]]!=0,
			y1=yymax;
			y2=yymin;
			pd=Append[pd,listplotdata[{{-obj[[3]]/obj[[1]],y1},{-obj[[3]]/obj[[1]],y2}}]]
		,
		If[AlmostZero[obj[[1]]] && obj[[2]]!=0,
			x1=xxmin;
			x2=xxmax;
			pd=Append[pd,plotdata[-obj[[3]]/obj[[2]],{x,x1,x2}]]
		,
		If[obj[[1]]!=0 && obj[[2]]!=0,
			xsect1= -(yymax*obj[[2]]+obj[[3]])/obj[[1]];
			xsect2= -(yymin*obj[[2]]+obj[[3]])/obj[[1]];
			x1=Max[xxmin,Min[xsect1,xsect2]];
			x2=Min[xxmax,Max[xsect1,xsect2]];
			(*Print["xxmin=",xxmin,":xxmax=",xxmax,":xsect1=",xsect1,":xsect2=",xsect2];*)
			pd=Append[pd,plotdata[-(obj[[1]]*xvar+obj[[3]])/obj[[2]],{xvar,x1,x2}]];
		];];];
	];
	If[args[[i]][[1]]=="Circle" && obj[[1]]!=0,(* if obj[[1]]==0 then it is a line.*) 
		option=args[[i]][[5]];
		r2=-obj[[4]]/obj[[1]]+(obj[[2]]^2+obj[[3]]^2)/(4*obj[[1]]^2);
		(* Print["r2=",r2]; *)
		If[r2>0, pd=Append[pd,circledata[{-obj[[2]]/(2*obj[[1]]),-obj[[3]]/(2*obj[[1]])},Sqrt[r2]]]];
	];
	If[args[[i]][[1]]=="Function",
		If[Length[args[[i]]]<4, 
			pd=Append[pd,plotdata[args[[i]][[3]]]];,
			(*Print[args[[i]][[3]],args[[i]][[4]]];*)
			pd=Append[pd,plotdata[args[[i]][[3]],args[[i]][[4]]]];
		];
	];
	If[args[[i]][[1]]=="Mark",
		option=args[[i]][[5]];
		myname="";ptposition=1;mysize="single";
		For[j=1,j<=Length[option],j++,
			Switch[option[[j]][[1]], 
				markname, myname=option[[j]][[2]],
				markposition,ptposition=option[[j]][[2]],
				markshape,mysize=option[[j]][[2]],
				\:6587\:5b57, myname=option[[j]][[2]],
				\:4f4d\:7f6e,ptposition=option[[j]][[2]],
				\:5f62,mysize=option[[j]][[2]]
			];
		];
		x1=obj[[1]][[1]]/obj[[1]][[3]];
		y1=obj[[1]][[2]]/obj[[1]][[3]];
		x2=obj[[2]][[1]]/obj[[2]][[3]];
		y2=obj[[2]][[2]]/obj[[2]][[3]];
		x3=obj[[3]][[1]]/obj[[3]][[3]];
		y3=obj[[3]][[2]]/obj[[3]][[3]];
		If[mysize=="single" || mysize=="double" || mysize=="dash" || mysize=="dashdouble" || mysize=="triple"  || mysize=="circle",
			pd=Append[pd,anglemark[{x1,y1},{x2,y2},{x3,y3},1]];
		];
		If[mysize=="double" || mysize=="dashdouble" || mysize=="triple", 
			pd=Append[pd,anglemark[{x1,y1},{x2,y2},{x3,y3},0.85]];
		];
		If[mysize=="triple", 
			pd=Append[pd,anglemark[{x1,y1},{x2,y2},{x3,y3},0.7]];
		];
		If[mysize=="dash",
			pd=Append[pd,listplotdata[{AngleMarkPosition[{x1,y1},{x2,y2},{x3,y3},0.6],AngleMarkPosition[{x1,y1},{x2,y2},{x3,y3},0.4]}]];
		];
		If[mysize=="dashdouble",
			pd=Append[pd,listplotdata[{AngleMarkPosition[{x1,y1},{x2,y2},{x3,y3},0.6],AngleMarkPosition[{x1,y1},{x2,y2},{x3,y3},0.34]}]];
		];
		If[mysize=="singlecircle" || mysize=="circle",
			pd=Append[pd,circledata[AngleMarkPosition[{x1,y1},{x2,y2},{x3,y3},0.5],0.085]];
		];
		If[mysize=="rightangle",
			pd=Append[pd, paraabsmark[{x1,y1},{x2,y2},{x3,y3},0.25]];
		];
		If[myname!="", 
			textdata=Append[textdata,Join[AngleMarkPosotion[{x1,y1},{x2,y2},{x3,y3},ptposition],{"",myname}]];
		];
	];
	If[args[[i]][[1]]=="Bow",
		option=args[[i]][[5]];
		bending=1;spacing=0;myname="";mysize="";
		For[j=1,j<=Length[option],j++,
			Switch[option[[j]][[1]],
				bend, bending=option[[j]][[2]],
				\:66f2\:304c\:308a, bending=option[[j]][[2]],
				space, spacing=option[[j]][[2]],
				\:7a7a\:304d, spacing=option[[j]][[2]],
				name, myname=option[[j]][[2]],
				\:540d\:524d, myname=option[[j]][[2]],
				bowshape,mysize=option[[j]][[2]],
				\:5f62,mysize=option[[j]][[2]]
			];
		];
		If[obj[[1]]!=obj[[3]] || obj[[2]]!=obj[[4]],
			pd=Append[pd,bowdata[{obj[[1]],obj[[2]]},{obj[[3]],obj[[4]]},bending,spacing]];
			ptposition=makeyumidata[{obj[[1]],obj[[2]]},{obj[[3]],obj[[4]]},0.1*bending*Norm[{obj[[1]]-obj[[3]],obj[[2]]-obj[[4]]}]];
			theta=(ptposition[[3]][[1]]+ptposition[[3]][[2]])*0.5;
			If[mysize=="dash2",
				(*Print[ptposition,",",theta];*)
				pd=Append[pd,listplotdata[{
{ptposition[[1]][[1]]+(ptposition[[2]]*0.97)*Cos[theta]+(ptposition[[2]]*0.01)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*0.97)*Sin[theta]-(ptposition[[2]]*0.01)*Cos[theta]},
{ptposition[[1]][[1]]+(ptposition[[2]]*1.03)*Cos[theta]+(ptposition[[2]]*0.01)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*1.03)*Sin[theta]-(ptposition[[2]]*0.01)*Cos[theta]}}]];
				pd=Append[pd,listplotdata[{
{ptposition[[1]][[1]]+(ptposition[[2]]*0.97)*Cos[theta]-(ptposition[[2]]*0.01)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*0.97)*Sin[theta]+(ptposition[[2]]*0.01)*Cos[theta]},
{ptposition[[1]][[1]]+(ptposition[[2]]*1.03)*Cos[theta]-(ptposition[[2]]*0.01)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*1.03)*Sin[theta]+(ptposition[[2]]*0.01)*Cos[theta]}}]];
			];
			If[mysize=="dash3",
				(*Print[ptposition,",",theta];*)
				pd=Append[pd,listplotdata[{
{ptposition[[1]][[1]]+(ptposition[[2]]*0.97)*Cos[theta]+(ptposition[[2]]*0.02)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*0.97)*Sin[theta]-(ptposition[[2]]*0.02)*Cos[theta]},
{ptposition[[1]][[1]]+(ptposition[[2]]*1.03)*Cos[theta]+(ptposition[[2]]*0.02)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*1.03)*Sin[theta]-(ptposition[[2]]*0.02)*Cos[theta]}}]];
				pd=Append[pd,listplotdata[{
{ptposition[[1]][[1]]+(ptposition[[2]]*0.97)*Cos[theta]-(ptposition[[2]]*0.02)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*0.97)*Sin[theta]+(ptposition[[2]]*0.02)*Cos[theta]},
{ptposition[[1]][[1]]+(ptposition[[2]]*1.03)*Cos[theta]-(ptposition[[2]]*0.02)*Sin[theta],ptposition[[1]][[2]]+(ptposition[[2]]*1.03)*Sin[theta]+(ptposition[[2]]*0.02)*Cos[theta]}}]];
			];
			If[mysize=="dash" || mysize=="dash3",
				(*Print[ptposition,",",theta];*)
				pd=Append[pd,listplotdata[{
{ptposition[[1]][[1]]+(ptposition[[2]]*0.97)*Cos[theta],ptposition[[1]][[2]]+(ptposition[[2]]*0.97)*Sin[theta]},
{ptposition[[1]][[1]]+(ptposition[[2]]*1.03)*Cos[theta],ptposition[[1]][[2]]+(ptposition[[2]]*1.03)*Sin[theta]}}]];
			];
			If[mysize=="circle",
				(*Print[ptposition,",",theta];*)
				pd=Append[pd,circledata[
{ptposition[[1]][[1]]+ptposition[[2]]*Cos[theta],ptposition[[1]][[2]]+ptposition[[2]]*Sin[theta]},0.085]];
			];
			If[myname!="",
				ptposition=yumichuuten[makeyumidata[{obj[[1]],obj[[2]]},{obj[[3]],obj[[4]]},0.1*bending*Norm[{obj[[1]]-obj[[3]],obj[[2]]-obj[[4]]}]]][[1]];
				textdata=Append[textdata,Join[ptposition,{"",myname}]];
			];
		];
	];
];
(* Print[windisp[pd]];*)
(*Print[{pd,pointdata,textdata}];*)
{pd,pointdata,textdata}
]


KETpic\:306b\:8ffd\:52a0[argseq__]:=Module[{},AddConstructionToKetpic[argseq]]
AddConstructionToKetpic[argseq__]:=Module[{pointdata,textdata,pd},
pd=MakePlotData[argseq];
pointdata=pd[[2]];
textdata=pd[[3]];
pd=pd[[1]];
If[Length[pd]>0, drwline[pd]];
For[i=1,i<=Length[textdata],i++,
	letter[{textdata[[i]][[1]],textdata[[i]][[2]]},textdata[[i]][[3]],textdata[[i]][[4]]];
];
For[i=1,i<=Length[pointdata],i++,
	setpt[pointdata[[i]][[3]]];
	drwpt[{pointdata[[i]][[1]],pointdata[[i]][[2]]}];
];
]


\:4f5c\:56f3[argseq__]:=Module[{},DrawConstruction[argseq]]
DrawConstruction[argseq__] := Module[{args,pd,pointdata,textdata}, 
args={argseq};
If[MyXYDomain, GetXYdomain[argseq];];(*\:30aa\:30d7\:30b7\:30e7\:30f3\:3067\:306f\:305a\:305b\:308b\:3088\:3046\:306b\:3059\:308b\:ff0e*)
pd=MakePlotData[argseq];
pointdata=pd[[2]];
textdata=pd[[3]];
pd=pd[[1]];
setwindow[{XMIN,XMAX},{YMIN,YMAX}];
(*If[Length[pd]>0, windisp[pd], windisp[]]; *)
Print["Save to ",MyTeXFileName];
openfile[MyTeXFileName];
beginpicture["1cm"];
If[Length[pd]>0, drwline[pd]];
For[i=1,i<=Length[textdata],i++,
	letter[{textdata[[i]][[1]],textdata[[i]][[2]]},textdata[[i]][[3]],textdata[[i]][[4]]];
];
For[i=1,i<=Length[pointdata],i++,
	setpt[pointdata[[i]][[3]]];
	drwpt[{pointdata[[i]][[1]],pointdata[[i]][[2]]}];
];
If[MyAxes, endpicture[1];, endpicture[0];];
closefile[];
]
