↓リンク(実際の動きを見れます)
http://hirohirosystem.com/1002robot/wRobotV501.html
ix,iyが手首の座標。ix2,iy2が肘の座標。(マウスで動かす)
function zahyokeisan(){
for(i = 0; i if(kindsl===jointbl[i].kinds.substr(1,1)){
if(jointbl[i].kinds.substr(2,1)==="1"){
x0 = jointbl[i].realadx;
y0 = jointbl[i].realady;
}
if(jointbl[i].kinds.substr(2,1)==="2"){
al = jointbl[i].flength;
}
if(jointbl[i].kinds.substr(2,1)==="3"){
bl = jointbl[i].flength;
}
}
}
if(ix >= x0){ xflg = 3;}else { xflg = 1;}
if(iy >= y0){ yflg = 3;}else { yflg = 1;}
lx = Math.abs(ix - x0);
ly = Math.abs(iy - y0);
l = Math.sqrt(Math.pow(lx,2) + Math.pow(ly,2));
//移動マウスの長さを調整する。
if(l>(al+bl)){
//lx,lyを算出する。
//マウスポイントから角度を求める
l = al + bl;
la = Math.ceil(l*al/(al+bl));
if(Math.abs(lx)<Math.abs(ly)){
r3 = Math.atan(Math.abs(lx)/Math.abs(ly));
lx = Math.ceil(l*Math.sin(r3));
ly = Math.ceil(l*Math.cos(r3));
lax = al*Math.sin(r3);
lay = al*Math.cos(r3);
}else{
r3 = Math.atan(Math.abs(ly)/Math.abs(lx));
ly = Math.ceil(l*Math.sin(r3));
lx = Math.ceil(l*Math.cos(r3));
lay = al*Math.sin(r3);
lax = al*Math.cos(r3);
}
if(xflg===3){
ix = x0 + lx;
}else{
ix = x0 - lx;
}
if(yflg===3){
iy = y0 + ly;
}else{
iy = y0 - ly;
}
if(xflg===3){
ix2 = x0 + lax;
}else{
ix2 = x0 - lax;
}
if(yflg===3){
iy2 = y0 + lay;
}else{
iy2 = y0 - lay;
}
}else{
la = Math.ceil(l*al/(al+bl));
lb = Math.ceil(l*bl/(al+bl));
r1 = Math.acos(la/al);
r2 = Math.atan(ly/lx);
ra = 90*Math.PI/180 - r1 - r2;
if(xflg ===3){
ix2 = Math.ceil(x0 + al*Math.sin(ra));
}else{
ix2 = Math.ceil(x0 - al*Math.sin(ra));
}
if(yflg ===3){
iy2 = Math.ceil(y0 + al*Math.cos(ra));
}else{
iy2 = Math.ceil(y0 - al*Math.cos(ra));
}
}
}