<div class="htmlarea"> <textarea id="runcode70496"> <style> *{margin:0;padding:0;} </style> <script> function a(x,y,color) {document.write("<img border='0' style="max-width:90%"+x+"; top: "+y+";background-color: "+color+"' src='px.gif' style="max-width:90%"js判断一点是否在一个三角形内_javascript技巧" >")} </script> <script> function line(x1,y1,x2,y2,color) { var tmp; if(x1>=x2) { tmp=x1; x1=x2; x2=tmp; tmp=y1; y1=y2; y2=tmp; } for(var i=x1;i<=x2;i++) { x = i; y = (y2 - y1) / (x2 - x1) * (x - x1) + y1; a(x,y,color); } } function rule(x,y) { x = x; y = y; r1 = y - 100 - (300-100)/(500-400)*(x-400); r2 = y - 300; r3 = y - 300 - (100-300)/(400-300)*(x-300); if (r1>0&&r2<0&&r3>0) { return "在三角形内!"; } else {return "不在三角形内!";} } line(400,100,500,300,"ff0000"); line(500,300,300,300,"ff0000"); line(300,300,400,100,"ff0000"); </script> </textarea><br><input onclick="runEx('runcode70496')" type="button" value="运行代码"> <input onclick="doCopy('runcode70496')" type="button" value="复制代码"> <input onclick="doSave(runcode70496)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>