原文章
https://math.pro/db/viewthread.php?tid=1876&page=1#pid10303
https://help.geogebra.org/topic/geogebra-demo#comment-26361
這次我使用GeoGebra的JavaScript程式語言做出Lattice Reduction功能。
以下是原始碼
var u1x=ggbApplet.getValue("v_1x");
var u1y=ggbApplet.getValue("v_1y");
var u2x=ggbApplet.getValue("v_2x");
var u2y=ggbApplet.getValue("v_2y");
var temp,k,End;
do{End=true;
if(u1x*u1x+u1y*u1y > u2x*u2x+u2y*u2y)
{temp=u1x; u1x=u2x; u2x=temp;
temp=u1y; u1y=u2y; u2y=temp;
End=false;
}
k=Math.round((u1x*u2x+u1y*u2y)/(u1x*u1x+u1y*u1y));
if(k!=0)
{u2x=u2x-k*u1x;
u2y=u2y-k*u1y;
End=false;
}
}
while (End==false);
ggbApplet.setValue("u_1x",u1x);
ggbApplet.setValue("u_1y",u1y);
ggbApplet.setValue("u_2x",u2x);
ggbApplet.setValue("u_2y",u2y);
ggbApplet.evalCommand("u1=Vector[(u_1x,u_1y)]");
ggbApplet.evalCommand("u2=Vector[(u_2x,u_2y)]");
附加檔案:
2DimensionLatticeReduction.ggb