(* ::Package:: *)

(* ::Section:: *)
(*stuff*)


SetDirectory[NotebookDirectory[]];
<<PluckerToolbox.m

PluckerLineToTwoPointsInAffinePatch[LineSkewSym4Matrix_]:=
Block[{GetInsidePoint,IntersectionPoints},
GetInsidePoint[Point[FourTuple_]]:=FourTuple;
If[Not[LineOnPlaneQ[LineSkewSym4Matrix,XYPlane]],
IntersectionPoints=Map[GetInsidePoint[IntersectionPoint[#,LineSkewSym4Matrix]]&,{XYPlane,ZLevel[1]}];
If[Not[MemberQ[Map[#[[4]]&,IntersectionPoints],0.]],
Return[Map[#[[{1,2,3}]]/#[[4]]&,IntersectionPoints]];
];
];
If[Not[LineOnPlaneQ[LineSkewSym4Matrix,YZPlane]],
IntersectionPoints=Map[GetInsidePoint[IntersectionPoint[#,LineSkewSym4Matrix]]&,{YZPlane,XLevel[1]}];
If[Not[MemberQ[Map[#[[4]]&,IntersectionPoints],0.]],
Return[Map[#[[{1,2,3}]]/#[[4]]&,IntersectionPoints]];
];
];
If[Not[LineOnPlaneQ[LineSkewSym4Matrix,ZXPlane]],
IntersectionPoints=Map[GetInsidePoint[IntersectionPoint[#,LineSkewSym4Matrix]]&,{ZXPlane,YLevel[1]}];
If[Not[MemberQ[Map[#[[4]]&,IntersectionPoints],0.]],
Return[Map[#[[{1,2,3}]]/#[[4]]&,IntersectionPoints]];
];
];
];

(**)
ExtendLineEndPoints[{Point1_,Point2_}, Scalar_]:=
Block[{MyDirection, MyMidpoint},
MyDirection=Point1-Point2; 
MyMidpoint=(Point1+Point2)/2.;
{MyMidpoint+(Scalar*MyDirection),MyMidpoint-(Scalar*MyDirection)}
];


(*assuming they already intersect*)
IntersectionPointInAffinePatch[PluckerLine1_,PluckerLine2_]:=
Block[{p1,p2,q1, q2,pDirection,qDirection,ConnectVector,NormOfPerp},
{p1,p2}=PluckerLineToTwoPointsInAffinePatch[PluckerLine1];
{q1,q2}=PluckerLineToTwoPointsInAffinePatch[PluckerLine2];
pDirection = p2-p1;
qDirection = q2-q1;
ConnectVector=q1-p1;
NormOfPerp=Norm[Cross[pDirection,qDirection]];
If[NormOfPerp==0,
(*if they are parallel*)
{},
p1+pDirection*(Cross[ConnectVector,qDirection].Cross[pDirection,qDirection]/NormOfPerp^2)]
];


(* ::Input:: *)
(**)
