From 844e1e9817a481f09fb5cb6e1c7d19bb522eb392 Mon Sep 17 00:00:00 2001 From: Yi-Ting Tu Date: Wed, 3 Jan 2024 03:26:03 +0800 Subject: [PATCH] Clean up comments --- simulator/js/editor.js | 144 +++++++++++++------------- simulator/js/graphs.js | 22 ++-- simulator/js/index.js | 20 ++-- simulator/js/objs/aperture.js | 46 ++++----- simulator/js/objs/arcmirror.js | 64 ++++++------ simulator/js/objs/beamsplitter.js | 13 ++- simulator/js/objs/blackcircle.js | 26 ++--- simulator/js/objs/blackline.js | 12 +-- simulator/js/objs/circlelens.js | 52 +++++----- simulator/js/objs/cropbox.js | 24 ++--- simulator/js/objs/curvedglass.js | 55 +++++----- simulator/js/objs/curvedmirror.js | 20 ++-- simulator/js/objs/drawing.js | 32 +++--- simulator/js/objs/grin_circlelens.js | 50 ++++----- simulator/js/objs/grin_refractor.js | 46 ++++----- simulator/js/objs/halfplane.js | 64 ++++++------ simulator/js/objs/handle.js | 12 +-- simulator/js/objs/idealmirror.js | 40 +++---- simulator/js/objs/laser.js | 12 +-- simulator/js/objs/led.js | 13 ++- simulator/js/objs/lens.js | 36 +++---- simulator/js/objs/line.js | 12 +-- simulator/js/objs/lineobj.js | 42 ++++---- simulator/js/objs/mirror.js | 13 ++- simulator/js/objs/parabolicmirror.js | 21 ++-- simulator/js/objs/parallel.js | 12 +-- simulator/js/objs/power.js | 14 +-- simulator/js/objs/protractor.js | 22 ++-- simulator/js/objs/radiant.js | 26 ++--- simulator/js/objs/refractor.js | 149 +++++++++++++-------------- simulator/js/objs/ruler.js | 8 +- simulator/js/objs/sphericallens.js | 11 +- simulator/js/objs/text.js | 23 ++--- simulator/js/simulator.js | 116 ++++++++++----------- 34 files changed, 631 insertions(+), 641 deletions(-) diff --git a/simulator/js/editor.js b/simulator/js/editor.js index a8850de9..1c07de4a 100644 --- a/simulator/js/editor.js +++ b/simulator/js/editor.js @@ -1,27 +1,27 @@ -var mouse; //滑鼠位置 Position of the mouse -var mouse_lastmousedown; //上一次按下滑鼠時的滑鼠位置 Position of the mouse the last time when the user clicked -var isConstructing = false; //正在建立新的物件 The user is constructing a new object -var constructionPoint; //建立物件的起始位置 The point where the user starts the construction -var draggingObj = -1; //拖曳中的物件編號(-1表示沒有拖曳,-3表示整個畫面,-4表示觀察者) Object index in drag (-1 for no drag, -3 for the entire picture, -4 for observer) -var positioningObj = -1; //輸入座標中的物件編號(-1表示沒有,-4表示觀察者) Object index in entering the coordinates (-1 for none, -4 for observer) -var draggingPart = {}; //拖曳的部份與滑鼠位置資訊 The part in drag and some mouse position data -var selectedObj = -1; //選取的物件編號(-1表示沒有選取) The index of the selected object (-1 for none) +var mouse; // Position of the mouse +var mouse_lastmousedown; // Position of the mouse the last time when the user clicked +var isConstructing = false; // The user is constructing a new object +var constructionPoint; // The point where the user starts the construction +var draggingObj = -1; // Object index in drag (-1 for no drag, -3 for the entire picture, -4 for observer) +var positioningObj = -1; // Object index in entering the coordinates (-1 for none, -4 for observer) +var draggingPart = {}; // The part in drag and some mouse position data +var selectedObj = -1; // The index of the selected object (-1 for none) var mouseObj = -1; var mousePart = {}; -var AddingObjType = ''; //拖曳空白處新增物件的類型 The type of the object to add when user click the canvas -var undoArr = []; //復原資料 Undo data -var undoIndex = 0; //目前復原的位置 Current undo position -var undoLimit = 20; //復原步數上限 Limit of undo -var undoUBound = 0; //目前復原資料上界 Current upper bound of undo data -var undoLBound = 0; //目前復原資料下界 Current lower bound of undo data -var snapToDirection_lockLimit_squared = 900; //拖曳物件且使用吸附至方向功能時鎖定吸附之方向所需的拖曳距離之平方 The square of the legnth needed to snap to a direction when dragging an object with snap-to-direction +var AddingObjType = ''; // The type of the object to add when user click the canvas +var undoArr = []; // Undo data +var undoIndex = 0; // Current undo position +var undoLimit = 20; // Limit of undo +var undoUBound = 0; // Current upper bound of undo data +var undoLBound = 0; // Current lower bound of undo data +var snapToDirection_lockLimit_squared = 900; // The square of the legnth needed to snap to a direction when dragging an object with snap-to-direction var clickExtent_line = 10; var clickExtent_point = 10; var clickExtent_point_construct = 10; var touchscreenExtentRatio = 2; -var gridSize = 20; //格線大小 Size of the grid -var origin = { x: 0, y: 0 }; //格線原點座標 Origin of the grid +var gridSize = 20; // Size of the grid +var origin = { x: 0, y: 0 }; // Origin of the grid var pendingControlPointSelection = false; var pendingControlPoints; @@ -57,23 +57,23 @@ function mouseOnPoint_construct(mouse, point) { } function mouseOnSegment(mouse, segment) { - var d_per = Math.pow((mouse.x - segment.p1.x) * (segment.p1.y - segment.p2.y) + (mouse.y - segment.p1.y) * (segment.p2.x - segment.p1.x), 2) / ((segment.p1.y - segment.p2.y) * (segment.p1.y - segment.p2.y) + (segment.p2.x - segment.p1.x) * (segment.p2.x - segment.p1.x)); //類似於滑鼠與直線垂直距離 Similar to the distance between the mouse and the line - var d_par = (segment.p2.x - segment.p1.x) * (mouse.x - segment.p1.x) + (segment.p2.y - segment.p1.y) * (mouse.y - segment.p1.y); //類似於滑鼠在直線上投影位置 Similar to the projected point of the mouse on the line + var d_per = Math.pow((mouse.x - segment.p1.x) * (segment.p1.y - segment.p2.y) + (mouse.y - segment.p1.y) * (segment.p2.x - segment.p1.x), 2) / ((segment.p1.y - segment.p2.y) * (segment.p1.y - segment.p2.y) + (segment.p2.x - segment.p1.x) * (segment.p2.x - segment.p1.x)); // Similar to the distance between the mouse and the line + var d_par = (segment.p2.x - segment.p1.x) * (mouse.x - segment.p1.x) + (segment.p2.y - segment.p1.y) * (mouse.y - segment.p1.y); // Similar to the projected point of the mouse on the line return d_per < getClickExtent() * getClickExtent() && d_par >= 0 && d_par <= graphs.length_segment_squared(segment); } function mouseOnLine(mouse, line) { - var d_per = Math.pow((mouse.x - line.p1.x) * (line.p1.y - line.p2.y) + (mouse.y - line.p1.y) * (line.p2.x - line.p1.x), 2) / ((line.p1.y - line.p2.y) * (line.p1.y - line.p2.y) + (line.p2.x - line.p1.x) * (line.p2.x - line.p1.x)); //類似於滑鼠與直線垂直距離 Similar to the distance between the mouse and the line + var d_per = Math.pow((mouse.x - line.p1.x) * (line.p1.y - line.p2.y) + (mouse.y - line.p1.y) * (line.p2.x - line.p1.x), 2) / ((line.p1.y - line.p2.y) * (line.p1.y - line.p2.y) + (line.p2.x - line.p1.x) * (line.p2.x - line.p1.x)); // Similar to the distance between the mouse and the line return d_per < getClickExtent() * getClickExtent(); } -//將滑鼠位置吸附至指定的方向中之最接近者(該方向直線上之投影點) Snap the mouse position to the direction nearest to the given directions +// Snap the mouse position to the direction nearest to the given directions function snapToDirection(mouse, basePoint, directions, snapData) { var x = mouse.x - basePoint.x; var y = mouse.y - basePoint.y; if (snapData && snapData.locked) { - //已經鎖定吸附對象 The snap has been locked + // The snap has been locked var k = (directions[snapData.i0].x * x + directions[snapData.i0].y * y) / (directions[snapData.i0].x * directions[snapData.i0].x + directions[snapData.i0].y * directions[snapData.i0].y); return graphs.point(basePoint.x + k * directions[snapData.i0].x, basePoint.y + k * directions[snapData.i0].y); } @@ -90,7 +90,7 @@ function snapToDirection(mouse, basePoint, directions, snapData) { } if (snapData && x * x + y * y > snapToDirection_lockLimit_squared) { - //鎖定吸附對象 lock the snap + // lock the snap snapData.locked = true; snapData.i0 = i0; } @@ -106,7 +106,7 @@ function canvas_onmousedown(e) { } else { var et = e; } - var mouse_nogrid = graphs.point((et.pageX - e.target.offsetLeft - origin.x) / scale, (et.pageY - e.target.offsetTop - origin.y) / scale); //滑鼠實際位置 The real position of the mouse + var mouse_nogrid = graphs.point((et.pageX - e.target.offsetLeft - origin.x) / scale, (et.pageY - e.target.offsetTop - origin.y) / scale); // The real position of the mouse mouse_lastmousedown = mouse_nogrid; if (positioningObj != -1) { confirmPositioning(e.ctrlKey, e.shiftKey); @@ -131,8 +131,8 @@ function canvas_onmousedown(e) { if (isConstructing) { if ((e.which && e.which == 1) || (e.changedTouches)) { - //只有滑鼠左鍵才反應 Only react for left click - //若有一個物件正在被建立,則將動作直接傳給它 If an obj is being created, pass the action to it + // Only react for left click + // If an obj is being created, pass the action to it objTypes[objs[objs.length - 1].type].c_mousedown(objs[objs.length - 1], mouse, e.ctrlKey, e.shiftKey); draw(!(objTypes[objs[objs.length - 1].type].shoot || objTypes[objs[objs.length - 1].type].rayIntersection), true); } @@ -145,12 +145,12 @@ function canvas_onmousedown(e) { if (mode == 'observer') { if (graphs.length_squared(mouse_nogrid, observer.c) < observer.r * observer.r) { - //滑鼠按到觀察者 The mouse clicked the observer + // The mouse clicked the observer draggingObj = -4; draggingPart = {}; //draggingPart.part=0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return; } @@ -166,7 +166,7 @@ function canvas_onmousedown(e) { } selectObj(ret.targetObj_index); draggingPart = ret.mousePart; - draggingPart.originalObj = JSON.parse(JSON.stringify(objs[ret.targetObj_index])); //暫存拖曳前的物件狀態 Store the obj status before dragging + draggingPart.originalObj = JSON.parse(JSON.stringify(objs[ret.targetObj_index])); // Store the obj status before dragging draggingPart.hasDuplicated = false; draggingObj = ret.targetObj_index; if (e.ctrlKey && draggingPart.targetPoint) { @@ -178,30 +178,30 @@ function canvas_onmousedown(e) { } if (draggingObj == -1) { - //滑鼠按到了空白處 The mouse clicked the blank area + // The mouse clicked the blank area if (objs.length > 0 && objs[0].type == "handle" && objs[0].notDone) { // User is creating a handle finishHandleCreation(mouse); return; } if ((AddingObjType == '') || (e.which == 3)) { - //準備平移整個畫面 To drag the entire scene + // To drag the entire scene draggingObj = -3; draggingPart = {}; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.mouse2 = origin; //Original origin. draggingPart.snapData = {}; selectObj(-1); } else { - //建立新的物件 Create a new object + // Create a new object objs[objs.length] = objTypes[AddingObjType].create(mouse); isConstructing = true; constructionPoint = mouse; if (objs[selectedObj]) { if (hasSameAttrType(objs[selectedObj], objs[objs.length - 1]) && objs[selectedObj].p) { - objs[objs.length - 1].p = objs[selectedObj].p; //讓此物件的附加屬性與上一個選取的物件相同(若類型相同) Let the property of this obj to be the same as the previously selected obj (if of the same type) + objs[objs.length - 1].p = objs[selectedObj].p; // Let the property of this obj to be the same as the previously selected obj (if of the same type) // TODO: Generalized this to other properties. } } @@ -230,17 +230,17 @@ function selectionSearch(mouse_nogrid) { if (typeof objs[i] != 'undefined') { mousePart_ = {}; if (objTypes[objs[i].type].clicked(objs[i], mouse_nogrid, mouse, mousePart_)) { - //clicked()回傳true表示滑鼠按到了該物件 click(() returns true means the mouse clicked the object + // click(() returns true means the mouse clicked the object if (mousePart_.targetPoint || mousePart_.targetPoint_) { - //滑鼠按到一個點 The mouse clicked a point + // The mouse clicked a point if (!targetIsPoint) { - targetIsPoint = true; //一旦發現能夠按到點,就必須按到點 If the mouse can click a point, then it must click a point + targetIsPoint = true; // If the mouse can click a point, then it must click a point results = []; } var click_lensq_temp = graphs.length_squared(mouse_nogrid, (mousePart_.targetPoint || mousePart_.targetPoint_)); if (click_lensq_temp <= click_lensq || targetObj_index == selectedObj) { - //按到點的情況下,選擇最接近滑鼠的 In case of clicking a point, choose the one nearest to the mouse + // In case of clicking a point, choose the one nearest to the mouse // But if the object is the selected object, the points from this object have the highest priority. targetObj_index = i; click_lensq = click_lensq_temp; @@ -253,8 +253,8 @@ function selectionSearch(mouse_nogrid) { if (targetObj_index == selectedObj) targetIsSelected = true; } } else if (!targetIsPoint) { - //滑鼠按到的不是點,且到目前為止未按到點 If not clicking a point, and until now not clicking any point - targetObj_index = i; //按到非點的情況下,選擇最後建立的 If clicking non-point, choose the most newly created one + // If not clicking a point, and until now not clicking any point + targetObj_index = i; // If clicking non-point, choose the most newly created one mousePart = mousePart_; results.unshift({mousePart: mousePart, targetObj_index: targetObj_index}); } @@ -276,7 +276,7 @@ function canvas_onmousemove(e) { } else { var et = e; } - var mouse_nogrid = graphs.point((et.pageX - e.target.offsetLeft - origin.x) / scale, (et.pageY - e.target.offsetTop - origin.y) / scale); //滑鼠實際位置 The real position of the mouse + var mouse_nogrid = graphs.point((et.pageX - e.target.offsetLeft - origin.x) / scale, (et.pageY - e.target.offsetTop - origin.y) / scale); // The real position of the mouse var mouse2; if (document.getElementById('grid').checked && !(e.altKey && !isConstructing)) { mouse2 = graphs.point(Math.round(((et.pageX - e.target.offsetLeft - origin.x) / scale) / gridSize) * gridSize, Math.round(((et.pageY - e.target.offsetTop - origin.y) / scale) / gridSize) * gridSize); @@ -323,7 +323,7 @@ function canvas_onmousemove(e) { // highlight object being constructed mouseObj = objs[objs.length - 1]; - //若有一個物件正在被建立,則將動作直接傳給它 If some object is being created, pass the action to it + // If some object is being created, pass the action to it objTypes[objs[objs.length - 1].type].c_mousemove(objs[objs.length - 1], mouse, e.ctrlKey, e.shiftKey); draw(!(objTypes[objs[objs.length - 1].type].shoot || objTypes[objs[objs.length - 1].type].rayIntersection), true); } @@ -335,26 +335,26 @@ function canvas_onmousemove(e) { } else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = (mouse_snapped.x - draggingPart.mouse1.x); //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = (mouse_snapped.y - draggingPart.mouse1.y); //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment + var mouseDiffX = (mouse_snapped.x - draggingPart.mouse1.x); // The X difference between the mouse position now and at the previous moment + var mouseDiffY = (mouse_snapped.y - draggingPart.mouse1.y); // The Y difference between the mouse position now and at the previous moment observer.c.x += mouseDiffX; observer.c.y += mouseDiffY; - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; draw(false, true); } var returndata; if (draggingObj >= 0) { - //此時,代表滑鼠正在拖曳一個物件 Here the mouse is dragging an object + // Here the mouse is dragging an object objTypes[objs[draggingObj].type].dragging(objs[draggingObj], mouse, draggingPart, e.ctrlKey, e.shiftKey); - //如果正在拖曳整個物件,則按Ctrl鍵時複製原物件 If dragging an entire object, then when Ctrl is hold, clone the object + // If dragging an entire object, then when Ctrl is hold, clone the object if (draggingPart.part == 0) { if (e.ctrlKey && !draggingPart.hasDuplicated) { @@ -375,19 +375,19 @@ function canvas_onmousemove(e) { } if (draggingObj == -3) { - //平移整個畫面 Move the entire scene - //此時mouse為目前滑鼠位置,draggingPart.mouse1為上一次的滑鼠位置 Here mouse is the currect mouse position, draggingPart.mouse1 is the mouse position at the previous moment + // Move the entire scene + // Here mouse is the currect mouse position, draggingPart.mouse1 is the mouse position at the previous moment if (e.shiftKey) { var mouse_snapped = snapToDirection(mouse_nogrid, draggingPart.mouse0, [{ x: 1, y: 0 }, { x: 0, y: 1 }], draggingPart.snapData); } else { var mouse_snapped = mouse_nogrid; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = (mouse_snapped.x - draggingPart.mouse1.x); //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = (mouse_snapped.y - draggingPart.mouse1.y); //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment + var mouseDiffX = (mouse_snapped.x - draggingPart.mouse1.x); // The X difference between the mouse position now and at the previous moment + var mouseDiffY = (mouse_snapped.y - draggingPart.mouse1.y); // The Y difference between the mouse position now and at the previous moment origin.x = mouseDiffX * scale + draggingPart.mouse2.x; origin.y = mouseDiffY * scale + draggingPart.mouse2.y; draw(); @@ -400,11 +400,11 @@ function canvas_onmousemove(e) { function canvas_onmouseup(e) { if (isConstructing) { if ((e.which && e.which == 1) || (e.changedTouches)) { - //若有一個物件正在被建立,則將動作直接傳給它 If an object is being created, pass the action to it + // If an object is being created, pass the action to it objTypes[objs[objs.length - 1].type].c_mouseup(objs[objs.length - 1], mouse, e.ctrlKey, e.shiftKey); draw(!(objTypes[objs[objs.length - 1].type].shoot || objTypes[objs[objs.length - 1].type].rayIntersection), true); if (!isConstructing) { - //該物件已經表示建立完畢 The object says the contruction is done + // The object says the contruction is done createUndoPoint(); if (document.getElementById('lockobjs').checked) { mouseObj = -1; @@ -467,7 +467,7 @@ function finishHandleCreation(point) { function canvas_ondblclick(e) { //console.log("dblclick"); - var mouse = graphs.point((e.pageX - e.target.offsetLeft - origin.x) / scale, (e.pageY - e.target.offsetTop - origin.y) / scale); //滑鼠實際位置(一律不使用格線) The real position of the mouse (never use grid here) + var mouse = graphs.point((e.pageX - e.target.offsetLeft - origin.x) / scale, (e.pageY - e.target.offsetTop - origin.y) / scale); // The real position of the mouse (never use grid here) if (isConstructing) { } else if (mouseOnPoint(mouse, mouse_lastmousedown)) { @@ -475,7 +475,7 @@ function canvas_ondblclick(e) { if (mode == 'observer') { if (graphs.length_squared(mouse, observer.c) < observer.r * observer.r) { - //滑鼠按到觀察者 The mouse clicked the observer + // The mouse clicked the observer positioningObj = -4; draggingPart = {}; draggingPart.targetPoint = graphs.point(observer.c.x, observer.c.y); @@ -499,7 +499,7 @@ function canvas_ondblclick(e) { if (ret.targetObj_index != -1 && ret.mousePart.targetPoint) { selectObj(ret.targetObj_index); draggingPart = ret.mousePart; - draggingPart.originalObj = JSON.parse(JSON.stringify(objs[ret.targetObj_index])); //暫存拖曳前的物件狀態 Store the obj status before dragging + draggingPart.originalObj = JSON.parse(JSON.stringify(objs[ret.targetObj_index])); // Store the obj status before dragging draggingPart.hasDuplicated = false; positioningObj = ret.targetObj_index; @@ -552,7 +552,7 @@ function selectObj(index) { } if (index < 0 || index >= objs.length) { - //若此物件不存在 If this object does not exist + // If this object does not exist selectedObj = -1; document.getElementById('obj_settings').style.display = 'none'; showAdvancedOn = false; @@ -574,7 +574,7 @@ function selectObj(index) { if (document.getElementById('p_box').innerHTML != '') { for (var i = 0; i < objs.length; i++) { if (i != selectedObj && hasSameAttrType(objs[i], objs[selectedObj])) { - //若有另一個相同type的物件,則顯示"套用全部"選項 If there is an object with the same type, then show "Apply to All" + // If there is an object with the same type, then show "Apply to All" document.getElementById('setAttrAll_box').style.display = ''; document.getElementById('applytoall_mobile_container').style.display = ''; break; @@ -601,16 +601,16 @@ function selectObj(index) { function confirmPositioning(ctrl, shift) { var xyData = JSON.parse('[' + document.getElementById('xybox').value.replace(/\(|\)/g, '') + ']'); - //只有當輸入兩個數值(座標)時才進行動作 Only do the action when the user enter two numbers (coordinates) + // Only do the action when the user enter two numbers (coordinates) if (xyData.length == 2) { if (positioningObj == -4) { - //觀察者 Observer + // Observer observer.c.x = xyData[0]; observer.c.y = xyData[1]; draw(false, true); } else { - //物件 Object + // Object objTypes[objs[positioningObj].type].dragging(objs[positioningObj], graphs.point(xyData[0], xyData[1]), draggingPart, ctrl, shift); draw(!(objTypes[objs[positioningObj].type].shoot || objTypes[objs[positioningObj].type].rayIntersection), true); } @@ -680,7 +680,7 @@ function createUndoPoint() { document.getElementById('redo_mobile').disabled = true; undoArr[undoIndex] = document.getElementById('textarea1').value; if (undoUBound == undoLBound) { - //復原步數已達上限 The limit of undo is reached + // The limit of undo is reached undoLBound = (undoLBound + 1) % undoLimit; } hasUnsavedChange = true; @@ -688,7 +688,7 @@ function createUndoPoint() { function undo() { if (isConstructing && !(objs.length > 0 && objs[objs.length - 1].type == 'drawing')) { - //假如按下復原時,使用者正在建立一個物件,則此時只將建立動作終止,而不做真正的復原 If the user is constructing an object when clicked the undo, then only stop the consturction rather than do the real undo + // If the user is constructing an object when clicked the undo, then only stop the consturction rather than do the real undo isConstructing = false; objs.length--; @@ -698,12 +698,12 @@ function undo() { return; } if (positioningObj != -1) { - //假如按下復原時,使用者正在輸入座標,則此時只將輸入座標動作終止,而不做真正的復原 If the user is entering coordinates when clicked the undo, then only stop the coordinates entering rather than do the real undo + // If the user is entering coordinates when clicked the undo, then only stop the coordinates entering rather than do the real undo endPositioning(); return; } if (undoIndex == undoLBound) - //已達復原資料下界 The lower bound of undo data is reached + // The lower bound of undo data is reached return; undoIndex = (undoIndex + (undoLimit - 1)) % undoLimit; document.getElementById('textarea1').value = undoArr[undoIndex]; @@ -711,7 +711,7 @@ function undo() { document.getElementById('redo').disabled = false; document.getElementById('redo_mobile').disabled = false; if (undoIndex == undoLBound) { - //已達復原資料下界 The lower bound of undo data is reached + // The lower bound of undo data is reached document.getElementById('undo').disabled = true; document.getElementById('undo_mobile').disabled = true; } @@ -722,7 +722,7 @@ function redo() { isConstructing = false; endPositioning(); if (undoIndex == undoUBound) - //已達復原資料下界 The lower bound of undo data is reached + // The lower bound of undo data is reached return; undoIndex = (undoIndex + 1) % undoLimit; document.getElementById('textarea1').value = undoArr[undoIndex]; @@ -730,7 +730,7 @@ function redo() { document.getElementById('undo').disabled = false; document.getElementById('undo_mobile').disabled = false; if (undoIndex == undoUBound) { - //已達復原資料下界 The lower bound of undo data is reached + // The lower bound of undo data is reached document.getElementById('redo').disabled = true; document.getElementById('redo_mobile').disabled = true; } diff --git a/simulator/js/graphs.js b/simulator/js/graphs.js index 73a1eb7a..c10f568a 100644 --- a/simulator/js/graphs.js +++ b/simulator/js/graphs.js @@ -1,6 +1,6 @@ var graphs = { /** - * 基本圖型 Basic geometric figures + * Basic geometric figures **/ point: function(x, y) {return {type: 1, x: x, y: y, exist: true}}, @@ -43,7 +43,7 @@ var graphs = { }, /** - * 求交點 Find intersection + * Find intersection * @method intersection * @param {graph} obj1 * @param {graph} obj2 @@ -65,7 +65,7 @@ var graphs = { }, /** - * 兩直線交點 Intersection of two lines + * Intersection of two lines * @method intersection_2line * @param {graph.line} l1 * @param {graph.line} l2 @@ -82,7 +82,7 @@ var graphs = { }, /** - * 直線與圓的交點 Intersection of a line and a circle + * Intersection of a line and a circle * @method intersection_line_circle * @param {graph.line} l1 * @param {graph.circle} c2 @@ -138,7 +138,7 @@ var graphs = { }, /** - * 線段長度 Length of a segment + * Length of a segment * @method length_segment * @param {graph.segment} seg * @return {Number} @@ -148,7 +148,7 @@ var graphs = { }, /** - * 線段長度平方 Square of the length of a segment + * Square of the length of a segment * @method length_segment_squared * @param {graph.segment} seg * @return {Number} @@ -158,7 +158,7 @@ var graphs = { }, /** - * 兩點距離 Distance between two points + * Distance between two points * @method length * @param {graph.point} p1 * @param {graph.point} p2 @@ -169,7 +169,7 @@ var graphs = { }, /** - * 兩點距離平方 Square of the distance between two points + * Square of the distance between two points * @method length_squared * @param {graph.point} p1 * @param {graph.point} p2 @@ -183,11 +183,11 @@ var graphs = { /* - * 基本作圖函數 Basic geometric constructions + * Basic geometric constructions */ /** - * 線段中點 Midpoint of a line segment + * Midpoint of a line segment * @method midpoint * @param {graph.line} l1 * @return {graph.point} @@ -212,7 +212,7 @@ var graphs = { }, /** - * 線段中垂線 Perpendicular bisector of a line segment + * Perpendicular bisector of a line segment * @method perpendicular_bisector * @param {graph.segment} l1 * @return {graph.line} diff --git a/simulator/js/index.js b/simulator/js/index.js index a33f8bbf..675c105e 100644 --- a/simulator/js/index.js +++ b/simulator/js/index.js @@ -8,8 +8,8 @@ var ctx0; var ctxLight; var ctxGrid; var dpr = 1; -var objs = []; //物件 The objects -var objCount = 0; //物件數量 Number of the objects +var objs = []; // The objects +var objCount = 0; // Number of the objects var observer; var xyBox_cancelContextMenu = false; var scale = 1; @@ -366,7 +366,7 @@ window.onload = function (e) { document.getElementById('rayDensity_mobile').oninput = document.getElementById('rayDensity').oninput; document.getElementById('rayDensity').onmouseup = function () { - setRayDensity(Math.exp(this.value)); //為了讓不支援oninput的瀏覽器可使用 For browsers not supporting oninput + setRayDensity(Math.exp(this.value)); // For browsers not supporting oninput document.getElementById('rayDensity').value = this.value; document.getElementById('rayDensity_more').value = this.value; document.getElementById('rayDensity_mobile').value = this.value; @@ -378,7 +378,7 @@ window.onload = function (e) { document.getElementById('rayDensity_mobile').onmouseup = document.getElementById('rayDensity').onmouseup; document.getElementById('rayDensity').ontouchend = function () { - setRayDensity(Math.exp(this.value)); //為了讓不支援oninput的瀏覽器可使用 For browsers not supporting oninput + setRayDensity(Math.exp(this.value)); // For browsers not supporting oninput document.getElementById('rayDensity').value = this.value; document.getElementById('rayDensity_more').value = this.value; document.getElementById('rayDensity_mobile').value = this.value; @@ -632,8 +632,8 @@ function initParameters() { objs.length = 0; selectObj(-1); - rayDensity_light = 0.1; //光線密度(光線相關模式) The Ray Density when View is Rays or Extended rays - rayDensity_images = 1; //光線密度(像相關模式) The Ray Density when View is All Images or Seen by Observer + rayDensity_light = 0.1; // The Ray Density when View is Rays or Extended rays + rayDensity_images = 1; // The Ray Density when View is All Images or Seen by Observer document.getElementById("rayDensity").value = rayDensity_light; document.getElementById("rayDensity_more").value = rayDensity_light; document.getElementById("rayDensity_mobile").value = rayDensity_light; @@ -872,7 +872,7 @@ function JSONInput() { var jsonData = JSON.parse(document.getElementById('textarea1').value); if (typeof jsonData != 'object') return; if (!jsonData.version) { - //為"線光學模擬1.0"或之前的格式 Earlier than "Ray Optics Simulation 1.0" + // Earlier than "Ray Optics Simulation 1.0" var str1 = document.getElementById('textarea1').value.replace(/"point"|"xxa"|"aH"/g, '1').replace(/"circle"|"xxf"/g, '5').replace(/"k"/g, '"objs"').replace(/"L"/g, '"p1"').replace(/"G"/g, '"p2"').replace(/"F"/g, '"p3"').replace(/"bA"/g, '"exist"').replace(/"aa"/g, '"parallel"').replace(/"ba"/g, '"mirror"').replace(/"bv"/g, '"lens"').replace(/"av"/g, '"notDone"').replace(/"bP"/g, '"lightAlpha"').replace(/"ab"|"observed_light"|"observed_images"/g, '"observer"'); jsonData = JSON.parse(str1); if (!jsonData.objs) { @@ -893,11 +893,11 @@ function JSONInput() { jsonData.version = 1; } if (jsonData.version == 1) { - //"線光學模擬1.1"至"線光學模擬1.2" "Ray Optics Simulation 1.1" to "Ray Optics Simulation 1.2" + // "Ray Optics Simulation 1.1" to "Ray Optics Simulation 1.2" jsonData.origin = { x: 0, y: 0 }; } if (jsonData.version > 2) { - //為比此版本新的檔案版本 Newer than the current version + // Newer than the current version return; } //TODO: Create new version. @@ -1015,7 +1015,7 @@ function modebtn_clicked(mode1) { document.getElementById("rayDensity_mobile").value = Math.log(rayDensity_light); } if (mode == 'observer' && !observer) { - //初始化觀察者 Initialize the observer + // Initialize the observer observer = graphs.circle(graphs.point((canvas.width * 0.5 / dpr - origin.x) / scale, (canvas.height * 0.5 / dpr - origin.y) / scale), parseFloat(document.getElementById('observer_size').value) * 0.5); } diff --git a/simulator/js/objs/aperture.js b/simulator/js/objs/aperture.js index a408555b..f4768e05 100644 --- a/simulator/js/objs/aperture.js +++ b/simulator/js/objs/aperture.js @@ -1,12 +1,12 @@ // Blocker objTypes['aperture'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'aperture', p1: mouse, p2: mouse, p3: mouse, p4: mouse}; }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { if (shift) @@ -23,7 +23,7 @@ objTypes['aperture'] = { }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { if (shift) @@ -41,7 +41,7 @@ objTypes['aperture'] = { obj.p4 = graphs.point(obj.p1.x * 0.4 + obj.p2.x * 0.6, obj.p1.y * 0.4 + obj.p2.y * 0.6); }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { if (!mouseOnPoint_construct(mouse, obj.p1)) @@ -51,12 +51,12 @@ objTypes['aperture'] = { } }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { - //移動線段的第一點 Move the first point + // Move the first point obj.p1.x = obj.p1.x + diffX; obj.p1.y = obj.p1.y + diffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x + diffX; obj.p2.y = obj.p2.y + diffY; @@ -68,7 +68,7 @@ objTypes['aperture'] = { }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { @@ -104,15 +104,15 @@ objTypes['aperture'] = { if (mouseOnSegment(mouse_nogrid, segment1) || mouseOnSegment(mouse_nogrid, segment2)) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { var basePoint; @@ -121,7 +121,7 @@ objTypes['aperture'] = { { if (draggingPart.part == 1) { - //正在拖曳第一個端點 Dragging the first endpoint Dragging the first endpoint + // Dragging the first endpoint Dragging the first endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p2; obj.p1 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse; @@ -129,7 +129,7 @@ objTypes['aperture'] = { } else { - //正在拖曳第二個端點 Dragging the second endpoint Dragging the second endpoint + // Dragging the second endpoint Dragging the second endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p1; obj.p2 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse; @@ -159,7 +159,7 @@ objTypes['aperture'] = { } else if (draggingPart.part == 0) { - //正在拖曳整條線 Dragging the entire line + // Dragging the entire line if (shift) { @@ -168,15 +168,15 @@ objTypes['aperture'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment The Y difference between the mouse position now and at the previous moment - //移動線段的第一點 Move the first point + var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment + var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment + // Move the first point obj.p1.x = obj.p1.x - mouseDiffX; obj.p1.y = obj.p1.y - mouseDiffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x - mouseDiffX; obj.p2.y = obj.p2.y - mouseDiffY; @@ -186,12 +186,12 @@ objTypes['aperture'] = { obj.p4.x = obj.p4.x - mouseDiffX; obj.p4.y = obj.p4.y - mouseDiffY; - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; } }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.strokeStyle = getMouseStyle(obj, (colorMode && obj.wavelength && obj.isDichroic) ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(70,35,10)'); ctx.lineWidth = 3; @@ -212,7 +212,7 @@ objTypes['aperture'] = { } }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { var originalDiameter = graphs.length(obj.p3, obj.p4); @@ -243,7 +243,7 @@ objTypes['aperture'] = { return false; }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp) { ray.exist = false; } diff --git a/simulator/js/objs/arcmirror.js b/simulator/js/objs/arcmirror.js index d28ca936..1f632202 100644 --- a/simulator/js/objs/arcmirror.js +++ b/simulator/js/objs/arcmirror.js @@ -1,17 +1,17 @@ // Mirrors -> Circular Arc objTypes['arcmirror'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'arcmirror', p1: mouse}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { dichroicSettings(obj,elem); }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { if (!obj.p2 && !obj.p3) @@ -33,7 +33,7 @@ objTypes['arcmirror'] = { return; } }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { if (!obj.p3 && !mouseOnPoint_construct(mouse, obj.p1)) @@ -57,7 +57,7 @@ objTypes['arcmirror'] = { return; } }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { if (obj.p2 && !obj.p3 && !mouseOnPoint_construct(mouse, obj.p1)) @@ -73,7 +73,7 @@ objTypes['arcmirror'] = { } }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.fillStyle = 'rgb(255,0,255)'; if (obj.p3 && obj.p2) @@ -98,7 +98,7 @@ objTypes['arcmirror'] = { } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. ctx.strokeStyle = getMouseStyle(obj, (colorMode && obj.wavelength && obj.isDichroic) ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(168,168,168)'); ctx.beginPath(); ctx.moveTo(obj.p1.x, obj.p1.y); @@ -124,12 +124,12 @@ objTypes['arcmirror'] = { } }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { - //移動線段的第一點 Move the first point + // Move the first point obj.p1.x = obj.p1.x + diffX; obj.p1.y = obj.p1.y + diffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x + diffX; obj.p2.y = obj.p2.y + diffY; @@ -139,7 +139,7 @@ objTypes['arcmirror'] = { }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p3)) { @@ -170,22 +170,22 @@ objTypes['arcmirror'] = { var a_m = Math.atan2(mouse_nogrid.y - center.y, mouse_nogrid.x - center.x); if (Math.abs(graphs.length(center, mouse_nogrid) - r) < getClickExtent() && (((a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2)) == ((a2 < a_m && a_m < a1) || (a1 < a2 && a2 < a_m) || (a_m < a1 && a1 < a2)))) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. if (mouseOnSegment(mouse_nogrid, obj)) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -193,12 +193,12 @@ objTypes['arcmirror'] = { return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { var basePoint; if (draggingPart.part == 1) { - //正在拖曳第一個端點 Dragging the first endpoint + // Dragging the first endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p2; obj.p1 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse; @@ -206,7 +206,7 @@ objTypes['arcmirror'] = { } if (draggingPart.part == 2) { - //正在拖曳第二個端點 Dragging the second endpoint + // Dragging the second endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p1; @@ -215,13 +215,13 @@ objTypes['arcmirror'] = { } if (draggingPart.part == 3) { - //正在拖曳弧形控制點 Dragging the control point of the arc + // Dragging the control point of the arc obj.p3 = mouse; } if (draggingPart.part == 0) { - //正在拖曳整個物件 Dragging the entire obj + // Dragging the entire obj if (shift) { @@ -230,29 +230,29 @@ objTypes['arcmirror'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment - //移動線段的第一點 Move the first point + var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment + var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment + // Move the first point obj.p1.x = obj.p1.x - mouseDiffX; obj.p1.y = obj.p1.y - mouseDiffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x - mouseDiffX; obj.p2.y = obj.p2.y - mouseDiffY; obj.p3.x = obj.p3.x - mouseDiffX; obj.p3.y = obj.p3.y - mouseDiffY; - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; } }, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(mirror, ray) { if (!mirror.p3 || !wavelengthInteraction(mirror, ray)) {return;} var center = graphs.intersection_2line(graphs.perpendicular_bisector(graphs.line(mirror.p1, mirror.p3)), graphs.perpendicular_bisector(graphs.line(mirror.p2, mirror.p3))); @@ -276,12 +276,12 @@ objTypes['arcmirror'] = { } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. return objTypes['lineobj'].rayIntersection(mirror, ray); } }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(mirror, ray, rayIndex, rp) { var rx = ray.p1.x - rp.x; var ry = ray.p1.y - rp.y; @@ -299,7 +299,7 @@ objTypes['arcmirror'] = { } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. return objTypes['mirror'].shot(mirror, ray, rayIndex, rp); } diff --git a/simulator/js/objs/beamsplitter.js b/simulator/js/objs/beamsplitter.js index 869be4a8..92f06473 100644 --- a/simulator/js/objs/beamsplitter.js +++ b/simulator/js/objs/beamsplitter.js @@ -1,15 +1,14 @@ -// Mirrors -> Beam Splitter -// Originally contributed by Paul Falstad (pfalstad) +// Mirror -> Beam Splitter objTypes['beamsplitter'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'beamsplitter', p1: mouse, p2: mouse, p: .5, isDichroic: false, isDichroicFilter: false}; }, dichroicSettings: objTypes['mirror'].dichroicSettings, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('transmissionratio'), 0, 1, 0.01, obj.p, function(obj, value) { obj.p = value; @@ -17,7 +16,7 @@ objTypes['beamsplitter'] = { dichroicSettings(obj,elem); }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -26,7 +25,7 @@ objTypes['beamsplitter'] = { dragging: objTypes['lineobj'].dragging, rayIntersection: objTypes['lineobj'].rayIntersection, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.strokeStyle = getMouseStyle(obj, 'rgb(100,100,168)'); ctx.beginPath(); @@ -45,7 +44,7 @@ objTypes['beamsplitter'] = { return objTypes['mirror'].rayIntersection(obj, ray); }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(mirror, ray, rayIndex, rp) { var rx = ray.p1.x - rp.x; var ry = ray.p1.y - rp.y; diff --git a/simulator/js/objs/blackcircle.js b/simulator/js/objs/blackcircle.js index aad531a7..0ea7646c 100644 --- a/simulator/js/objs/blackcircle.js +++ b/simulator/js/objs/blackcircle.js @@ -1,12 +1,12 @@ -// Blocker +// Blocker -> Circle Blocker objTypes['blackcircle'] = { - //建立物件 Create the obj + // Create the obj create: function (mouse) { return {type: 'blackcircle', p1: mouse, p2: mouse}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: function (obj, mouse, ctrl, shift) { objTypes['lineobj'].c_mousemove(obj, mouse, false, shift) @@ -14,7 +14,7 @@ objTypes['blackcircle'] = { c_mouseup: objTypes['lineobj'].c_mouseup, move: objTypes['lineobj'].move, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function (obj, ctx, aboveLight) { ctx.beginPath(); @@ -34,7 +34,7 @@ objTypes['blackcircle'] = { } }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) // When the drawing area is pressed (to determine the part of the object being pressed) clicked: function (obj, mouse_nogrid, mouse, draggingPart) { // clicking on p1 (center)? @@ -52,23 +52,23 @@ objTypes['blackcircle'] = { // clicking on outer edge of circle? then drag entire circle if (Math.abs(graphs.length(obj.p1, mouse_nogrid) - graphs.length_segment(obj)) < getClickExtent()) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { dichroicSettings(obj,elem); }, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function (obj, ray) { if (obj.p <= 0 || !wavelengthInteraction(obj,ray)) return; - var rp_temp = graphs.intersection_line_circle(graphs.line(ray.p1, ray.p2), graphs.circle(obj.p1, obj.p2)); //求光(的延長線)與鏡子的交點 + var rp_temp = graphs.intersection_line_circle(graphs.line(ray.p1, ray.p2), graphs.circle(obj.p1, obj.p2)); var rp_exist = []; var rp_lensq = []; for (var i = 1; i <= 2; i++) { @@ -76,7 +76,7 @@ objTypes['blackcircle'] = { rp_exist[i] = graphs.intersection_is_on_ray(rp_temp[i], ray) && graphs.length_squared(rp_temp[i], ray.p1) > minShotLength_squared; - rp_lensq[i] = graphs.length_squared(ray.p1, rp_temp[i]); //光線射到第i交點的距離 + rp_lensq[i] = graphs.length_squared(ray.p1, rp_temp[i]); } if (rp_exist[1] && ((!rp_exist[2]) || rp_lensq[1] < rp_lensq[2])) { @@ -88,12 +88,12 @@ objTypes['blackcircle'] = { }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function (obj, mouse, draggingPart, ctrl, shift) { objTypes['lineobj'].dragging(obj, mouse, draggingPart, false, shift) }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function (obj, ray, rayIndex, rp) { ray.exist = false; } diff --git a/simulator/js/objs/blackline.js b/simulator/js/objs/blackline.js index 85600fa5..76beb743 100644 --- a/simulator/js/objs/blackline.js +++ b/simulator/js/objs/blackline.js @@ -1,12 +1,12 @@ -// Blocker +// Blocker -> Line Blocker objTypes['blackline'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'blackline', p1: mouse, p2: mouse}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -14,7 +14,7 @@ objTypes['blackline'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.strokeStyle = getMouseStyle(obj, (colorMode && obj.wavelength && obj.isDichroic) ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(70,35,10)'); ctx.lineWidth = 3; @@ -26,7 +26,7 @@ objTypes['blackline'] = { ctx.lineWidth = 1; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { dichroicSettings(obj,elem); }, @@ -38,7 +38,7 @@ objTypes['blackline'] = { } }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp) { ray.exist = false; } diff --git a/simulator/js/objs/circlelens.js b/simulator/js/objs/circlelens.js index 333d43df..a1c31f63 100644 --- a/simulator/js/objs/circlelens.js +++ b/simulator/js/objs/circlelens.js @@ -1,22 +1,22 @@ -// Glasses -> Circle +// Glass -> Circle objTypes['circlelens'] = { - supportSurfaceMerging: true, //支援界面融合 Surface merging + supportSurfaceMerging: true, // Surface merging - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'circlelens', p1: mouse, p2: mouse, p: 1.5}; }, p_box: objTypes['refractor'].p_box, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: function(obj, mouse, ctrl, shift) {objTypes['lineobj'].c_mousemove(obj, mouse, false, shift)}, c_mouseup: objTypes['lineobj'].c_mouseup, move: objTypes['lineobj'].move, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) // When the drawing area is pressed (to determine the part of the object being pressed) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { // clicking on p1 (center)? @@ -39,21 +39,21 @@ objTypes['circlelens'] = { //if (Math.abs(graphs.length(obj.p1, mouse_nogrid) < graphs.length_segment(obj))) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) {objTypes['lineobj'].dragging(obj, mouse, draggingPart, false, shift)}, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { if (obj.p <= 0)return; - var rp_temp = graphs.intersection_line_circle(graphs.line(ray.p1, ray.p2), graphs.circle(obj.p1, obj.p2)); //求光(的延長線)與鏡子的交點 + var rp_temp = graphs.intersection_line_circle(graphs.line(ray.p1, ray.p2), graphs.circle(obj.p1, obj.p2)); var rp_exist = []; var rp_lensq = []; for (var i = 1; i <= 2; i++) @@ -62,7 +62,7 @@ objTypes['circlelens'] = { rp_exist[i] = graphs.intersection_is_on_ray(rp_temp[i], ray) && graphs.length_squared(rp_temp[i], ray.p1) > minShotLength_squared; - rp_lensq[i] = graphs.length_squared(ray.p1, rp_temp[i]); //光線射到第i交點的距離 + rp_lensq[i] = graphs.length_squared(ray.p1, rp_temp[i]); } @@ -72,7 +72,7 @@ objTypes['circlelens'] = { zIndex: objTypes['refractor'].zIndex, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.beginPath(); @@ -92,56 +92,56 @@ objTypes['circlelens'] = { }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp, surfaceMerging_objs) { var midpoint = graphs.midpoint(graphs.line_segment(ray.p1, rp)); var d = graphs.length_squared(obj.p1, obj.p2) - graphs.length_squared(obj.p1, midpoint); if (d > 0) { - //從內部射向外部 Shot from inside to outside - var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); //來源介質的折射率(目的介質假設為1) The refractive index of the source material (assuming the destination has 1) + // Shot from inside to outside + var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); // The refractive index of the source material (assuming the destination has 1) var normal = {x: obj.p1.x - rp.x, y: obj.p1.y - rp.y}; } else if (d < 0) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside var n1 = 1 / ((!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001))); var normal = {x: rp.x - obj.p1.x, y: rp.y - obj.p1.y}; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } var shotType; - //界面融合 Surface merging + // Surface merging for (var i = 0; i < surfaceMerging_objs.length; i++) { shotType = objTypes[surfaceMerging_objs[i].type].getShotType(surfaceMerging_objs[i], ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside + // Shot from inside to outside n1 *= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside n1 /= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) //n1=n1; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -158,11 +158,11 @@ objTypes['circlelens'] = { if (d > 0) { - return 1; //由內向外 From inside to outside + return 1; // From inside to outside } if (d < 0) { - return -1; //由外向內 From outside to inside + return -1; // From outside to inside } return 2; } diff --git a/simulator/js/objs/cropbox.js b/simulator/js/objs/cropbox.js index 16f33d3e..3b4914a6 100644 --- a/simulator/js/objs/cropbox.js +++ b/simulator/js/objs/cropbox.js @@ -1,7 +1,7 @@ - +// The crop box appear when using File > Export as PNG/SVG objTypes['cropbox'] = { - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { var width = graphs.length(obj.p1, obj.p2); var height = graphs.length(obj.p1, obj.p3); @@ -44,7 +44,7 @@ objTypes['cropbox'] = { }, elem); }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { obj.p1.x = obj.p1.x + diffX; obj.p1.y = obj.p1.y + diffY; @@ -58,7 +58,7 @@ objTypes['cropbox'] = { }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (!cropMode) return false; @@ -125,15 +125,15 @@ objTypes['cropbox'] = { // Inside if ((obj.p1.x < mouse_nogrid.x && mouse_nogrid.x < obj.p2.x) && (obj.p1.y < mouse_nogrid.y && mouse_nogrid.y < obj.p3.y)) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { // Top left if (draggingPart.part == 1) { @@ -192,11 +192,11 @@ objTypes['cropbox'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment + var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment + var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment obj.p1.x -= mouseDiffX; @@ -208,13 +208,13 @@ objTypes['cropbox'] = { obj.p4.x -= mouseDiffX; obj.p4.y -= mouseDiffY; - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; } }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { if (!cropMode) return; diff --git a/simulator/js/objs/curvedglass.js b/simulator/js/objs/curvedglass.js index 4cd53875..8b6d24dd 100644 --- a/simulator/js/objs/curvedglass.js +++ b/simulator/js/objs/curvedglass.js @@ -3,12 +3,12 @@ objTypes['curvedglass'] = { supportSurfaceMerging: true, - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'curvedglass', p1: mouse, p2: mouse, eqn1: "0", eqn2: "0.5\\cdot\\sqrt{1-x^2}", p: 1.5}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createEquationAttr('', obj.eqn1, function(obj, value) { obj.eqn1 = value; @@ -23,7 +23,7 @@ objTypes['curvedglass'] = { c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { if (aboveLight && obj.tmp_glass) { objTypes['refractor'].draw(obj.tmp_glass, ctx, true); @@ -107,7 +107,7 @@ objTypes['curvedglass'] = { move: objTypes['lineobj'].move, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2)) { @@ -124,10 +124,10 @@ objTypes['curvedglass'] = { if (!obj.tmp_glass) return false; if (objTypes['refractor'].clicked(obj.tmp_glass, mouse_nogrid, mouse, {})) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -137,7 +137,7 @@ objTypes['curvedglass'] = { dragging: objTypes['lineobj'].dragging, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { if (!obj.tmp_glass) return; @@ -162,12 +162,11 @@ objTypes['curvedglass'] = { { s_point_temp = null; //Line segment i->i+1 - var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.tmp_glass.path[i % obj.tmp_glass.path.length], obj.tmp_glass.path[(i + 1) % obj.tmp_glass.path.length])); //求光(的延長線)與物件(的延長線)的交點 + var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.tmp_glass.path[i % obj.tmp_glass.path.length], obj.tmp_glass.path[(i + 1) % obj.tmp_glass.path.length])); if (graphs.intersection_is_on_segment(rp_temp, graphs.segment(obj.tmp_glass.path[i % obj.tmp_glass.path.length], obj.tmp_glass.path[(i + 1) % obj.tmp_glass.path.length])) && graphs.intersection_is_on_ray(rp_temp, ray) && graphs.length_squared(ray.p1, rp_temp) > minShotLength_squared) { - //↑若rp_temp在ray上且rp_temp在obj上(即ray真的有射到obj,不是ray的延長線射到或射到obj的延長線上) - s_lensq_temp = graphs.length_squared(ray.p1, rp_temp); //交點到[光線的頭]的距離 + s_lensq_temp = graphs.length_squared(ray.p1, rp_temp); s_point_temp = rp_temp; } @@ -191,57 +190,57 @@ objTypes['curvedglass'] = { }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp, surfaceMerging_objs) { var shotData = this.getShotData(obj, ray); var shotType = shotData.shotType; if (shotType == 1) { - //從內部射向外部 Shot from inside to outside - var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); //來源介質的折射率(目的介質假設為1) The refractive index of the source material (assuming the destination has 1) + // Shot from inside to outside + var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); // The refractive index of the source material (assuming the destination has 1) } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside var n1 = 1 / ((!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001))); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) var n1 = 1; } else { - //可能導致Bug的狀況(如射到邊界點) The situation that may cause a bug (e.g. shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // The situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } - //界面融合 Surface merging + // Surface merging for (var i = 0; i < surfaceMerging_objs.length; i++) { shotType = objTypes[surfaceMerging_objs[i].type].getShotType(surfaceMerging_objs[i], ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside + // Shot from inside to outside n1 *= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside n1 /= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) //n1=n1; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // The situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -250,14 +249,14 @@ objTypes['curvedglass'] = { objTypes['refractor'].refract(ray, rayIndex, shotData.s_point, shotData.normal, n1); }, - //判斷光線內部/外部射出 Test if the ray is shot from inside or outside + // Test if the ray is shot from inside or outside getShotType: function(obj, ray) { return this.getShotData(obj, ray).shotType; }, getShotData: function(obj, ray) { - //判斷光射到物件的何處 Test where in the obj does the ray shoot on + // Test where in the obj does the ray shoot on var i = obj.tmp_i; var pts = obj.tmp_glass.path; @@ -275,11 +274,11 @@ objTypes['curvedglass'] = { if (rcrosss < 0) { - var shotType = 1; //從內部射向外部 Shot from inside to outside + var shotType = 1; // Shot from inside to outside } else { - var shotType = -1; //從外部射向內部 Shot from outside to inside + var shotType = -1; // Shot from outside to inside } // Use a simple trick to smooth out the normal vector so that image detection works. diff --git a/simulator/js/objs/curvedmirror.js b/simulator/js/objs/curvedmirror.js index ce37e2b8..b557f25e 100644 --- a/simulator/js/objs/curvedmirror.js +++ b/simulator/js/objs/curvedmirror.js @@ -1,7 +1,7 @@ -// Mirrors -> Custom equation +// Mirror -> Custom equation objTypes['curvedmirror'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'curvedmirror', p1: mouse, p2: mouse, p: "0.5\\cdot\\sqrt{1-x^2}"}; }, @@ -9,7 +9,7 @@ objTypes['curvedmirror'] = { dichroicSettings: objTypes['mirror'].dichroicSettings, wavelengthInteraction: objTypes['mirror'].wavelengthInteraction, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createEquationAttr('y = ', obj.p, function(obj, value) { obj.p = value; @@ -21,7 +21,7 @@ objTypes['curvedmirror'] = { c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { var fn; try { @@ -95,7 +95,7 @@ objTypes['curvedmirror'] = { move: objTypes['lineobj'].move, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2)) { @@ -118,10 +118,10 @@ objTypes['curvedmirror'] = { var seg = graphs.segment(pts[i], pts[i+1]); if (mouseOnSegment(mouse_nogrid, seg)) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -131,7 +131,7 @@ objTypes['curvedmirror'] = { dragging: objTypes['lineobj'].dragging, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(mirror, ray) { if (!mirror.tmp_points || !wavelengthInteraction(mirror,ray)) return; var i,j; @@ -155,7 +155,7 @@ objTypes['curvedmirror'] = { if (rp) return rp; }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(mirror, ray, rayIndex, rp) { var rx = ray.p1.x - rp.x; var ry = ray.p1.y - rp.y; diff --git a/simulator/js/objs/drawing.js b/simulator/js/objs/drawing.js index 4b8d4b91..9687b883 100644 --- a/simulator/js/objs/drawing.js +++ b/simulator/js/objs/drawing.js @@ -1,12 +1,12 @@ -// Mirrors -> Circular Arc +// Other -> Drawing objTypes['drawing'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'drawing', points: [], tmp_isMouseDown: false}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { if (isConstructing) { createButton(getMsg('stop_drawing'), function(obj) { @@ -17,27 +17,27 @@ objTypes['drawing'] = { } }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { obj.points.push([mouse.x, mouse.y]); obj.tmp_isMouseDown = true; selectObj(objs.length - 1); }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { if (!obj.tmp_isMouseDown) return; obj.points[obj.points.length - 1].push(mouse.x, mouse.y); }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { obj.tmp_isMouseDown = false; createUndoPoint(); }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.strokeStyle = getMouseStyle(obj, "white"); ctx.beginPath(); @@ -50,7 +50,7 @@ objTypes['drawing'] = { ctx.stroke(); }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { for (var i = 0; i < obj.points.length; i++) { for (var j = 0; j < obj.points[i].length; j += 2) { @@ -62,14 +62,14 @@ objTypes['drawing'] = { }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { for (var i = 0; i < obj.points.length; i++) { for (var j = 0; j < obj.points[i].length - 2; j += 2) { if (mouseOnSegment(mouse_nogrid, graphs.segment(graphs.point(obj.points[i][j], obj.points[i][j + 1]), graphs.point(obj.points[i][j + 2], obj.points[i][j + 3])))) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -78,7 +78,7 @@ objTypes['drawing'] = { return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { if (shift) { @@ -87,11 +87,11 @@ objTypes['drawing'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment + var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment + var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment if (draggingPart.part == 0) { for (var i = 0; i < obj.points.length; i++) { @@ -102,7 +102,7 @@ objTypes['drawing'] = { } } - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; } diff --git a/simulator/js/objs/grin_circlelens.js b/simulator/js/objs/grin_circlelens.js index 09a310fc..466e08dd 100644 --- a/simulator/js/objs/grin_circlelens.js +++ b/simulator/js/objs/grin_circlelens.js @@ -1,9 +1,9 @@ -// Glasses -> ? +// Glass -> Gradient-index circle objTypes['grin_circlelens'] = { - supportSurfaceMerging: true, //支援界面融合 Surface merging + supportSurfaceMerging: true, // Surface merging - //建立物件 Create the obj + // Create the obj create: function(mouse) { const p = '1 + e ^ (-((x ^ 2 + y ^ 2) / 50 ^ 2))'; const p_tex = '1+e^{-\\frac{x^2+y^2}{50^2}}'; @@ -15,7 +15,7 @@ objTypes['grin_circlelens'] = { return {type: 'grin_circlelens', p1: mouse, p2: mouse, origin: origin, p: p, p_tex: p_tex, p_der_x: p_der_x, p_der_x_tex: p_der_x_tex, p_der_y: p_der_y, p_der_y_tex: p_der_y_tex, fn_p: evaluateLatex(p_tex) ,fn_p_der_x: evaluateLatex(p_der_x_tex), fn_p_der_y: evaluateLatex(p_der_y_tex), step_size: 1, eps: 1e-3}; // Note that in this object, eps has units of [length]^2 }, }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { if (!obj.fn_p) { // to maintain the ctrl+z functionality @@ -73,7 +73,7 @@ objTypes['grin_circlelens'] = { } }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mouseup: objTypes['lineobj'].c_mouseup, c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: function(obj, mouse, ctrl, shift) {objTypes['lineobj'].c_mousemove(obj, mouse, false, shift)}, @@ -101,7 +101,7 @@ objTypes['grin_circlelens'] = { ctx.globalAlpha = 1; }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { if (obj.error) { @@ -129,7 +129,7 @@ objTypes['grin_circlelens'] = { }, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { if (!obj.fn_p) { // to maintain the ctrl+z functionality @@ -156,7 +156,7 @@ objTypes['grin_circlelens'] = { return objTypes[obj.type.substring(obj.type.indexOf('_') + 1)].rayIntersection(obj, ray); }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp, surfaceMerging_objs) { try { if ( (objTypes[obj.type].isInsideGlass(obj, ray.p1) || objTypes[obj.type].isOutsideGlass(obj, ray.p1) ) && objTypes[obj.type].isOnBoundary(obj, rp) ) // if the ray is hitting the circle from the outside, or from the inside (meaning that the point rp is on the boundary of the circle, and the point ray.p1 is inside/outside the circle) @@ -166,20 +166,20 @@ objTypes['grin_circlelens'] = { let p = obj.fn_p({x: rp.x - obj.origin.x, y: rp.y - obj.origin.y}); // refractive index at the intersection point - rp if (d > 0) { - //從內部射向外部 Shot from inside to outside - var n1 = (!colorMode)?p:(p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); //來源介質的折射率(目的介質假設為1) The refractive index of the source material (assuming the destination has 1) + // Shot from inside to outside + var n1 = (!colorMode)?p:(p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); // The refractive index of the source material (assuming the destination has 1) var normal = {x: obj.p1.x - rp.x, y: obj.p1.y - rp.y}; } else if (d < 0) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside var n1 = 1 / ((!colorMode)?p:(p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001))); var normal = {x: rp.x - obj.p1.x, y: rp.y - obj.p1.y}; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -197,30 +197,30 @@ objTypes['grin_circlelens'] = { { var shotType; - //界面融合 Surface merging + // Surface merging for (var i = 0; i < surfaceMerging_objs.length; i++) { let p = surfaceMerging_objs[i].fn_p({x: rp.x - surfaceMerging_objs[i].origin.x, y: rp.y - surfaceMerging_objs[i].origin.y}) // refractive index at the intersection point - rp shotType = objTypes[surfaceMerging_objs[i].type].getShotType(surfaceMerging_objs[i], ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside + // Shot from inside to outside n1 *= (!colorMode)?p:(p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside n1 /= (!colorMode)?p:(p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) //n1=n1; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -274,7 +274,7 @@ objTypes['grin_circlelens'] = { var ray_y = (ray.p2.y - ray.p1.y) / ray_len; - //參考 Reference http://en.wikipedia.org/wiki/Snell%27s_law#Vector_form + // Reference http://en.wikipedia.org/wiki/Snell%27s_law#Vector_form var cos1 = -normal_x * ray_x - normal_y * ray_y; var sq1 = 1 - n1 * n1 * (1 - cos1 * cos1); @@ -282,7 +282,7 @@ objTypes['grin_circlelens'] = { if (sq1 < 0) { - //全反射 Total internal reflection + // Total internal reflection ray.p1 = s_point; ray.p2 = graphs.point(s_point.x + ray_x + 2 * cos1 * normal_x, s_point.y + ray_y + 2 * cos1 * normal_y); @@ -290,14 +290,14 @@ objTypes['grin_circlelens'] = { } else { - //折射 Refraction + // Refraction var cos2 = Math.sqrt(sq1); var R_s = Math.pow((n1 * cos1 - cos2) / (n1 * cos1 + cos2), 2); var R_p = Math.pow((n1 * cos2 - cos1) / (n1 * cos2 + cos1), 2); - //參考 Reference http://en.wikipedia.org/wiki/Fresnel_equations#Definitions_and_power_equations + // Reference http://en.wikipedia.org/wiki/Fresnel_equations#Definitions_and_power_equations - //處理反射光 Handle the reflected ray + // Handle the reflected ray var ray2 = graphs.ray(s_point, graphs.point(s_point.x + ray_x + 2 * cos1 * normal_x, s_point.y + ray_y + 2 * cos1 * normal_y)); ray2.brightness_s = ray.brightness_s * R_s; ray2.brightness_p = ray.brightness_p * R_p; @@ -323,7 +323,7 @@ objTypes['grin_circlelens'] = { } } - //處理折射光 Handle the refracted ray + // Handle the refracted ray ray.p1 = s_point; ray.p2 = graphs.point(s_point.x + n1 * ray_x + (n1 * cos1 - cos2) * normal_x, s_point.y + n1 * ray_y + (n1 * cos1 - cos2) * normal_y); ray.brightness_s = ray.brightness_s * (1 - R_s); diff --git a/simulator/js/objs/grin_refractor.js b/simulator/js/objs/grin_refractor.js index 15b298d6..de1d5099 100644 --- a/simulator/js/objs/grin_refractor.js +++ b/simulator/js/objs/grin_refractor.js @@ -1,9 +1,9 @@ -// Glasses -> ? +// Glass -> Gradient-index polygon objTypes['grin_refractor'] = { supportSurfaceMerging: true, - //建立物件 Create the obj + // Create the obj create: function(mouse) { const p = '1.1 + 0.1 * cos(0.1 * y)'; const p_tex = '1.1+0.1\\cdot\\cos\\left(0.1\\cdot y\\right)'; @@ -41,16 +41,16 @@ objTypes['grin_refractor'] = { { if (obj.path.length > 3 && mouseOnPoint(mouse, obj.path[0])) { - //滑鼠按了第一點 Clicked the first point + // Clicked the first point obj.path.length--; obj.notDone = false; return; } - obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; //移動最後一點 Move the last point + obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; // Move the last point } }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp, surfaceMerging_objs) { try { if ( (objTypes[obj.type].isInsideGlass(obj, ray.p1) || objTypes[obj.type].isOutsideGlass(obj, ray.p1) ) && objTypes[obj.type].isOnBoundary(obj, rp) ) // if the ray is hitting the circle from the outside, or from the inside (meaning that the point rp is on the boundary of the circle, and the point ray.p1 is inside/outside the circle) @@ -61,23 +61,23 @@ objTypes['grin_refractor'] = { var p = obj.fn_p({x: rp.x - obj.origin.x, y: rp.y - obj.origin.y}) // refractive index at the intersection point - rp if (shotType == 1) { - //從內部射向外部 Shot from inside to outside - var n1 = (!colorMode)?p:(p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); //來源介質的折射率(目的介質假設為1) The refractive index of the source material (assuming the destination has 1) + // Shot from inside to outside + var n1 = (!colorMode)?p:(p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); // The refractive index of the source material (assuming the destination has 1) } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside var n1 = 1 / ((!colorMode)?p:(p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001))); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) var n1 = 1; } else { - //可能導致Bug的狀況(如射到邊界點) The situation that may cause a bug (e.g. shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // The situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -93,30 +93,30 @@ objTypes['grin_refractor'] = { let r_bodyMerging_obj; // save the current bodyMerging_obj of the ray, to pass it later to the reflected ray in the 'refract' function if (surfaceMerging_objs.length) { - //界面融合 Surface merging + // Surface merging for (var i = 0; i < surfaceMerging_objs.length; i++) { let p = surfaceMerging_objs[i].fn_p({x: rp.x - surfaceMerging_objs[i].origin.x, y: rp.y - surfaceMerging_objs[i].origin.y}) // refractive index at the intersection point - rp shotType = objTypes[surfaceMerging_objs[i].type].getShotType(surfaceMerging_objs[i], ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside + // Shot from inside to outside n1 *= (!colorMode)?p:(p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside n1 /= (!colorMode)?p:(p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) //n1=n1; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // The situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -177,7 +177,7 @@ objTypes['grin_refractor'] = { if (obj.notDone) { - //使用者尚未畫完物件 The user has not finish drawing the obj yet + // The user has not finish drawing the obj yet ctx.beginPath(); ctx.moveTo(obj.path[0].x, obj.path[0].y); @@ -196,13 +196,13 @@ objTypes['grin_refractor'] = { a1 = Math.atan2(p1.y - center.y, p1.x - center.x); a2 = Math.atan2(p2.y - center.y, p2.x - center.x); a3 = Math.atan2(p3.y - center.y, p3.x - center.x); - acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); //p1->p3->p2之旋轉方向,逆時針為true The rotation direction of p1->p3->p2. True indicates counterclockwise + acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); // The rotation direction of p1->p3->p2. True indicates counterclockwise ctx.arc(center.x, center.y, r, a1, a2, acw); } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. ctx.lineTo(obj.path[(i + 2)].x, obj.path[(i + 2)].y); } @@ -220,7 +220,7 @@ objTypes['grin_refractor'] = { } else { - //物件已經畫完 The user has completed drawing the obj + // The user has completed drawing the obj ctx.beginPath(); ctx.moveTo(obj.path[0].x, obj.path[0].y); @@ -238,13 +238,13 @@ objTypes['grin_refractor'] = { a1 = Math.atan2(p1.y - center.y, p1.x - center.x); a2 = Math.atan2(p2.y - center.y, p2.x - center.x); a3 = Math.atan2(p3.y - center.y, p3.x - center.x); - acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); //p1->p3->p2之旋轉方向,逆時針為true The rotation direction of p1->p3->p2. True indicates counterclockwise + acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); // The rotation direction of p1->p3->p2. True indicates counterclockwise ctx.arc(center.x, center.y, r, a1, a2, acw); } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. ctx.lineTo(obj.path[(i + 2) % obj.path.length].x, obj.path[(i + 2) % obj.path.length].y); } diff --git a/simulator/js/objs/halfplane.js b/simulator/js/objs/halfplane.js index a3c5c5ca..4d4b1996 100644 --- a/simulator/js/objs/halfplane.js +++ b/simulator/js/objs/halfplane.js @@ -1,22 +1,22 @@ -// Glasses -> Half-plane +// Glass -> Half-plane objTypes['halfplane'] = { supportSurfaceMerging: true, - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'halfplane', p1: mouse, p2: mouse, p: 1.5}; }, p_box: objTypes['refractor'].p_box, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, move: objTypes['lineobj'].move, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2)) { @@ -33,20 +33,20 @@ objTypes['halfplane'] = { if (mouseOnLine(mouse_nogrid, obj)) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { var basePoint; if (draggingPart.part == 1) { - //正在拖曳第一個端點 Dragging the first endpoint + // Dragging the first endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p2; obj.p1 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse; @@ -54,7 +54,7 @@ objTypes['halfplane'] = { } if (draggingPart.part == 2) { - //正在拖曳第二個端點 Dragging the second endpoint + // Dragging the second endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p1; @@ -63,7 +63,7 @@ objTypes['halfplane'] = { } if (draggingPart.part == 0) { - //正在拖曳整條線 Dragging the entire line + // Dragging the entire line if (shift) { @@ -72,23 +72,23 @@ objTypes['halfplane'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment - //移動線段的第一點 Move the first point + var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment + var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment + // Move the first point obj.p1.x = obj.p1.x - mouseDiffX; obj.p1.y = obj.p1.y - mouseDiffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x - mouseDiffX; obj.p2.y = obj.p2.y - mouseDiffY; - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; } }, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { if (obj.p <= 0)return; var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.p1, obj.p2)); @@ -101,7 +101,7 @@ objTypes['halfplane'] = { zIndex: objTypes['refractor'].zIndex, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { var len = Math.sqrt((obj.p2.x - obj.p1.x) * (obj.p2.x - obj.p1.x) + (obj.p2.y - obj.p1.y) * (obj.p2.y - obj.p1.y)); @@ -129,7 +129,7 @@ objTypes['halfplane'] = { }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp, surfaceMerging_objs) { var rdots = (ray.p2.x - ray.p1.x) * (obj.p2.x - obj.p1.x) + (ray.p2.y - ray.p1.y) * (obj.p2.y - obj.p1.y); var ssq = (obj.p2.x - obj.p1.x) * (obj.p2.x - obj.p1.x) + (obj.p2.y - obj.p1.y) * (obj.p2.y - obj.p1.y); @@ -138,46 +138,46 @@ objTypes['halfplane'] = { var shotType = this.getShotType(obj, ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside - var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); //來源介質的折射率(目的介質假設為1) The refractive index of the source material (assuming the destination has 1) + // Shot from inside to outside + var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); // The refractive index of the source material (assuming the destination has 1) } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside var n1 = 1 / ((!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001))); } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } - //界面融合 Surface merging + // Surface merging //if(surfaceMerging_obj) for (var i = 0; i < surfaceMerging_objs.length; i++) { shotType = objTypes[surfaceMerging_objs[i].type].getShotType(surfaceMerging_objs[i], ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside + // Shot from inside to outside n1 *= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside n1 /= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) //n1=n1; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -191,11 +191,11 @@ objTypes['halfplane'] = { var rcrosss = (ray.p2.x - ray.p1.x) * (obj.p2.y - obj.p1.y) - (ray.p2.y - ray.p1.y) * (obj.p2.x - obj.p1.x); if (rcrosss > 0) { - return 1; //由內向外 From inside to outside + return 1; // From inside to outside } if (rcrosss < 0) { - return -1; //由外向內 From outside to inside + return -1; // From outside to inside } return 2; } diff --git a/simulator/js/objs/handle.js b/simulator/js/objs/handle.js index 09356866..60cb2a26 100644 --- a/simulator/js/objs/handle.js +++ b/simulator/js/objs/handle.js @@ -1,7 +1,7 @@ // The handle created when holding ctrl and click several points objTypes['handle'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'handle', controlPoints: [], notDone: true}; }, @@ -32,7 +32,7 @@ objTypes['handle'] = { return -Infinity; }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { /* @@ -71,12 +71,12 @@ objTypes['handle'] = { } }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { objTypes['handle'].dragging(obj, graphs.point(obj.p1.x + diffX, obj.p1.y + diffY), {targetPoint_: obj.p1, part: 1}); }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (obj.notDone) return; if (mouseOnPoint(mouse_nogrid, obj.p1)) @@ -98,7 +98,7 @@ objTypes['handle'] = { return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { if (obj.notDone) return; if (shift) @@ -108,7 +108,7 @@ objTypes['handle'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } if (draggingPart.part == 1) { diff --git a/simulator/js/objs/idealmirror.js b/simulator/js/objs/idealmirror.js index 64f9b422..7713c3bf 100644 --- a/simulator/js/objs/idealmirror.js +++ b/simulator/js/objs/idealmirror.js @@ -1,14 +1,14 @@ -// Mirrors -> Ideal Curved +// Mirror -> Ideal curved mirror objTypes['idealmirror'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'idealmirror', p1: mouse, p2: graphs.point(mouse.x + gridSize, mouse.y), p: 100}; }, dichroicSettings: objTypes['mirror'].dichroicSettings, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('focallength'), -1000, 1000, 1, obj.p * (cartesianSign?-1:1), function(obj, value) { obj.p = value * (cartesianSign?-1:1); @@ -25,7 +25,7 @@ objTypes['idealmirror'] = { dichroicSettings(obj,elem); }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -33,7 +33,7 @@ objTypes['idealmirror'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { var len = Math.sqrt((obj.p2.x - obj.p1.x) * (obj.p2.x - obj.p1.x) + (obj.p2.y - obj.p1.y) * (obj.p2.y - obj.p1.y)); var par_x = (obj.p2.x - obj.p1.x) / len; @@ -45,7 +45,7 @@ objTypes['idealmirror'] = { var arrow_size_par = 5; var center_size = 1; - //畫線 Draw the line segment + // Draw the line segment ctx.strokeStyle = getMouseStyle(obj, (colorMode && obj.wavelength && obj.isDichroic) ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(168,168,168)'); ctx.globalAlpha = 1; ctx.lineWidth = 1; @@ -56,7 +56,7 @@ objTypes['idealmirror'] = { ctx.lineWidth = 1; - //畫面鏡中心點 Draw the center point of the mirror + // Draw the center point of the mirror var center = graphs.midpoint(obj); ctx.strokeStyle = 'rgb(255,255,255)'; ctx.beginPath(); @@ -67,18 +67,18 @@ objTypes['idealmirror'] = { ctx.fillStyle = 'rgb(255,0,0)'; - //單面版畫箭頭(兩方向焦距相反) Draw the arrow for one-sided version (the focal lengths on the two sides are opposite) + // Draw the arrow for one-sided version (the focal lengths on the two sides are opposite) /* if(obj.p>0) { - //畫箭頭(p1) Draw the arrow (p1) + // Draw the arrow (p1) ctx.beginPath(); ctx.moveTo(obj.p1.x+per_x*arrow_size_per2,obj.p1.y+per_y*arrow_size_per2); ctx.lineTo(obj.p1.x-per_x*arrow_size_per,obj.p1.y-per_y*arrow_size_per); ctx.lineTo(obj.p1.x+per_x*arrow_size_per2+par_x*arrow_size_par,obj.p1.y+per_y*arrow_size_per2+par_y*arrow_size_par); ctx.fill(); - //畫箭頭(p2) Draw the arrow (p2) + // Draw the arrow (p2) ctx.beginPath(); ctx.moveTo(obj.p2.x+per_x*arrow_size_per2,obj.p2.y+per_y*arrow_size_per2); ctx.lineTo(obj.p2.x-per_x*arrow_size_per,obj.p2.y-per_y*arrow_size_per); @@ -87,14 +87,14 @@ objTypes['idealmirror'] = { } if(obj.p<0) { - //畫箭頭(p1) Draw the arrow (p1) + // Draw the arrow (p1) ctx.beginPath(); ctx.moveTo(obj.p1.x-per_x*arrow_size_per2,obj.p1.y-per_y*arrow_size_per2); ctx.lineTo(obj.p1.x+per_x*arrow_size_per,obj.p1.y+per_y*arrow_size_per); ctx.lineTo(obj.p1.x-per_x*arrow_size_per2+par_x*arrow_size_par,obj.p1.y-per_y*arrow_size_per2+par_y*arrow_size_par); ctx.fill(); - //畫箭頭(p2) Draw the arrow (p2) + // Draw the arrow (p2) ctx.beginPath(); ctx.moveTo(obj.p2.x-per_x*arrow_size_per2,obj.p2.y-per_y*arrow_size_per2); ctx.lineTo(obj.p2.x+per_x*arrow_size_per,obj.p2.y+per_y*arrow_size_per); @@ -103,17 +103,17 @@ objTypes['idealmirror'] = { } */ - //雙面版畫箭頭 Draw the arrow for the two-sided version + // Draw the arrow for the two-sided version if (obj.p < 0) { - //畫箭頭(p1) Draw the arrow (p1) + // Draw the arrow (p1) ctx.beginPath(); ctx.moveTo(obj.p1.x - par_x * arrow_size_par, obj.p1.y - par_y * arrow_size_par); ctx.lineTo(obj.p1.x + par_x * arrow_size_par + per_x * arrow_size_per, obj.p1.y + par_y * arrow_size_par + per_y * arrow_size_per); ctx.lineTo(obj.p1.x + par_x * arrow_size_par - per_x * arrow_size_per, obj.p1.y + par_y * arrow_size_par - per_y * arrow_size_per); ctx.fill(); - //畫箭頭(p2) Draw the arrow (p2) + // Draw the arrow (p2) ctx.beginPath(); ctx.moveTo(obj.p2.x + par_x * arrow_size_par, obj.p2.y + par_y * arrow_size_par); ctx.lineTo(obj.p2.x - par_x * arrow_size_par + per_x * arrow_size_per, obj.p2.y - par_y * arrow_size_par + per_y * arrow_size_per); @@ -122,14 +122,14 @@ objTypes['idealmirror'] = { } if (obj.p > 0) { - //畫箭頭(p1) Draw the arrow (p1) + // Draw the arrow (p1) ctx.beginPath(); ctx.moveTo(obj.p1.x + par_x * arrow_size_par, obj.p1.y + par_y * arrow_size_par); ctx.lineTo(obj.p1.x - par_x * arrow_size_par + per_x * arrow_size_per, obj.p1.y - par_y * arrow_size_par + per_y * arrow_size_per); ctx.lineTo(obj.p1.x - par_x * arrow_size_par - per_x * arrow_size_per, obj.p1.y - par_y * arrow_size_par - per_y * arrow_size_per); ctx.fill(); - //畫箭頭(p2) Draw the arrow (p2) + // Draw the arrow (p2) ctx.beginPath(); ctx.moveTo(obj.p2.x - par_x * arrow_size_par, obj.p2.y - par_y * arrow_size_par); ctx.lineTo(obj.p2.x + par_x * arrow_size_par + per_x * arrow_size_per, obj.p2.y + par_y * arrow_size_par + per_y * arrow_size_per); @@ -143,12 +143,12 @@ objTypes['idealmirror'] = { return objTypes['mirror'].rayIntersection(mirror, ray); }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(mirror, ray, rayIndex, shootPoint) { - //當成理想透鏡與平面鏡的結合 Treat as a combination of an ideal lens and a planar mirror + // Treat as a combination of an ideal lens and a planar mirror objTypes['lens'].shot(mirror, ray, rayIndex, graphs.point(shootPoint.x, shootPoint.y)); - //將光線往後拉 Pull the ray backwards + // Pull the ray backwards ray.p1.x = 2 * ray.p1.x - ray.p2.x; ray.p1.y = 2 * ray.p1.y - ray.p2.y; diff --git a/simulator/js/objs/laser.js b/simulator/js/objs/laser.js index aec4f74e..a6d72fcd 100644 --- a/simulator/js/objs/laser.js +++ b/simulator/js/objs/laser.js @@ -1,12 +1,12 @@ -// Ray +// Light source -> Single ray objTypes['laser'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'laser', p1: mouse, p2: mouse, p: 1}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -14,7 +14,7 @@ objTypes['laser'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('brightness'), 0, 1, 0.01, obj.p || 1, function(obj, value) { obj.p = value; @@ -26,7 +26,7 @@ objTypes['laser'] = { } }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.fillStyle = getMouseStyle(obj, colorMode ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(255,0,0)'); ctx.fillRect(obj.p1.x - 2.5, obj.p1.y - 2.5, 5, 5); @@ -35,7 +35,7 @@ objTypes['laser'] = { }, - //射出光線 Shoot rays + // Shoot rays shoot: function(obj) { var ray1 = graphs.ray(obj.p1, obj.p2); ray1.brightness_s = 0.5 * (obj.p || 1); diff --git a/simulator/js/objs/led.js b/simulator/js/objs/led.js index 3d8ed4a6..92c99cfd 100644 --- a/simulator/js/objs/led.js +++ b/simulator/js/objs/led.js @@ -1,13 +1,12 @@ -// Point source -> Finite angle -// Originally contributed by GLmontanari +// Light source -> Point source (<360deg) objTypes['led'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'led', p1: mouse, p2: mouse, p : 36.001, symmetric : true}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('brightness'), 0, 1, 0.01, obj.brightness || 0.5, function(obj, value) { obj.brightness = value; @@ -27,7 +26,7 @@ objTypes['led'] = { } }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -35,7 +34,7 @@ objTypes['led'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.fillStyle = colorMode? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : getMouseStyle(obj, 'rgb(0,255,0)'); ctx.fillRect(obj.p1.x - 2.5, obj.p1.y - 2.5, 5, 5); @@ -48,7 +47,7 @@ objTypes['led'] = { }, - //射出光線 Shoot rays + // Shoot rays shoot: function(obj) { var s = Math.PI * 2 / parseInt(getRayDensity() * 500); var i0 = (mode == 'observer') ? (-s * 2 + 1e-6) : 0; diff --git a/simulator/js/objs/lens.js b/simulator/js/objs/lens.js index 5c3bcdfd..71c3ec2e 100644 --- a/simulator/js/objs/lens.js +++ b/simulator/js/objs/lens.js @@ -1,19 +1,19 @@ -// Glasses -> Ideal Lens +// Glass -> Ideal Lens objTypes['lens'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'lens', p1: mouse, p2: mouse, p: 100}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('focallength'), -1000, 1000, 1, obj.p, function(obj, value) { obj.p = value; }, elem); }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -22,7 +22,7 @@ objTypes['lens'] = { dragging: objTypes['lineobj'].dragging, rayIntersection: objTypes['lineobj'].rayIntersection, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { var len = Math.sqrt((obj.p2.x - obj.p1.x) * (obj.p2.x - obj.p1.x) + (obj.p2.y - obj.p1.y) * (obj.p2.y - obj.p1.y)); var par_x = (obj.p2.x - obj.p1.x) / len; @@ -34,7 +34,7 @@ objTypes['lens'] = { var arrow_size_par = 5; var center_size = 2; - //畫線 Draw the line segment + // Draw the line segment ctx.strokeStyle = getMouseStyle(obj, 'rgb(128,128,128)'); ctx.globalAlpha = 1 / ((Math.abs(obj.p) / 100) + 1); ctx.lineWidth = 4; @@ -47,7 +47,7 @@ objTypes['lens'] = { ctx.globalAlpha = 1; ctx.fillStyle = 'rgb(255,0,0)'; - //畫透鏡中心點 Draw the center point of the lens + // Draw the center point of the lens var center = graphs.midpoint(obj); ctx.strokeStyle = 'rgb(255,255,255)'; ctx.beginPath(); @@ -57,14 +57,14 @@ objTypes['lens'] = { if (obj.p > 0) { - //畫箭頭(p1) Draw the arrow (p1) + // Draw the arrow (p1) ctx.beginPath(); ctx.moveTo(obj.p1.x - par_x * arrow_size_par, obj.p1.y - par_y * arrow_size_par); ctx.lineTo(obj.p1.x + par_x * arrow_size_par + per_x * arrow_size_per, obj.p1.y + par_y * arrow_size_par + per_y * arrow_size_per); ctx.lineTo(obj.p1.x + par_x * arrow_size_par - per_x * arrow_size_per, obj.p1.y + par_y * arrow_size_par - per_y * arrow_size_per); ctx.fill(); - //畫箭頭(p2) Draw the arrow (p2) + // Draw the arrow (p2) ctx.beginPath(); ctx.moveTo(obj.p2.x + par_x * arrow_size_par, obj.p2.y + par_y * arrow_size_par); ctx.lineTo(obj.p2.x - par_x * arrow_size_par + per_x * arrow_size_per, obj.p2.y - par_y * arrow_size_par + per_y * arrow_size_per); @@ -73,14 +73,14 @@ objTypes['lens'] = { } if (obj.p < 0) { - //畫箭頭(p1) Draw the arrow (p1) + // Draw the arrow (p1) ctx.beginPath(); ctx.moveTo(obj.p1.x + par_x * arrow_size_par, obj.p1.y + par_y * arrow_size_par); ctx.lineTo(obj.p1.x - par_x * arrow_size_par + per_x * arrow_size_per, obj.p1.y - par_y * arrow_size_par + per_y * arrow_size_per); ctx.lineTo(obj.p1.x - par_x * arrow_size_par - per_x * arrow_size_per, obj.p1.y - par_y * arrow_size_par - per_y * arrow_size_per); ctx.fill(); - //畫箭頭(p2) Draw the arrow (p2) + // Draw the arrow (p2) ctx.beginPath(); ctx.moveTo(obj.p2.x - par_x * arrow_size_par, obj.p2.y - par_y * arrow_size_par); ctx.lineTo(obj.p2.x + par_x * arrow_size_par + per_x * arrow_size_per, obj.p2.y + par_y * arrow_size_par + per_y * arrow_size_per); @@ -99,7 +99,7 @@ objTypes['lens'] = { - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(lens, ray, rayIndex, shootPoint) { var lens_length = graphs.length_segment(lens); @@ -107,19 +107,19 @@ objTypes['lens'] = { var main_line_unitvector_y = (lens.p1.x - lens.p2.x) / lens_length; var mid_point = graphs.midpoint(lens); - var twoF_point_1 = graphs.point(mid_point.x + main_line_unitvector_x * 2 * lens.p, mid_point.y + main_line_unitvector_y * 2 * lens.p); //兩倍焦距點1 The first point at two focal lengths - var twoF_point_2 = graphs.point(mid_point.x - main_line_unitvector_x * 2 * lens.p, mid_point.y - main_line_unitvector_y * 2 * lens.p); //兩倍焦距點2 The second point at two focal lengths + var twoF_point_1 = graphs.point(mid_point.x + main_line_unitvector_x * 2 * lens.p, mid_point.y + main_line_unitvector_y * 2 * lens.p); // The first point at two focal lengths + var twoF_point_2 = graphs.point(mid_point.x - main_line_unitvector_x * 2 * lens.p, mid_point.y - main_line_unitvector_y * 2 * lens.p); // The second point at two focal lengths var twoF_line_near, twoF_line_far; if (graphs.length_squared(ray.p1, twoF_point_1) < graphs.length_squared(ray.p1, twoF_point_2)) { - //兩倍焦距點1和光線在同一側 The first point at two focal lengths is on the same side as the ray + // The first point at two focal lengths is on the same side as the ray twoF_line_near = graphs.parallel(lens, twoF_point_1); twoF_line_far = graphs.parallel(lens, twoF_point_2); } else { - //兩倍焦距點2和光線在同一側 The second point at two focal lengths is on the same side as the ray + // The second point at two focal lengths is on the same side as the ray twoF_line_near = graphs.parallel(lens, twoF_point_2); twoF_line_far = graphs.parallel(lens, twoF_point_1); } @@ -127,13 +127,13 @@ objTypes['lens'] = { if (lens.p > 0) { - //匯聚透鏡 Converging lens + // Converging lens ray.p2 = graphs.intersection_2line(twoF_line_far, graphs.line(mid_point, graphs.intersection_2line(twoF_line_near, ray))); ray.p1 = shootPoint; } else { - //發散透鏡 Diverging lens + // Diverging lens ray.p2 = graphs.intersection_2line(twoF_line_far, graphs.line(shootPoint, graphs.intersection_2line(twoF_line_near, graphs.line(mid_point, graphs.intersection_2line(twoF_line_far, ray))))); ray.p1 = shootPoint; } diff --git a/simulator/js/objs/line.js b/simulator/js/objs/line.js index 2ae68b2e..05581343 100644 --- a/simulator/js/objs/line.js +++ b/simulator/js/objs/line.js @@ -1,12 +1,12 @@ - +// Other -> Line / Arrow objTypes['line'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'line', p1: mouse, p2: mouse, arrow1: false, arrow2: false}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -14,7 +14,7 @@ objTypes['line'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.strokeStyle = getMouseStyle(obj, "white"); ctx.beginPath(); @@ -29,7 +29,7 @@ objTypes['line'] = { } }, - //畫箭頭 Draw the arrow + // Draw the arrow drawArrow: function(ctx, p1, p2) { var angle = Math.atan2(p2.y - p1.y, p2.x - p1.x); var len = 10; @@ -41,7 +41,7 @@ objTypes['line'] = { ctx.stroke(); }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createBooleanAttr(getMsg('arrow1'), obj.arrow1, function(obj, value) { obj.arrow1 = value; diff --git a/simulator/js/objs/lineobj.js b/simulator/js/objs/lineobj.js index edde3f09..8870b8b0 100644 --- a/simulator/js/objs/lineobj.js +++ b/simulator/js/objs/lineobj.js @@ -1,7 +1,7 @@ -//線段物件之原型 the prototype of linear objects +// the prototype of linear objects objTypes['lineobj'] = { - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { if (shift) @@ -14,7 +14,7 @@ objTypes['lineobj'] = { } }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { if (shift) @@ -28,7 +28,7 @@ objTypes['lineobj'] = { obj.p1 = ctrl ? graphs.point(2 * constructionPoint.x - obj.p2.x, 2 * constructionPoint.y - obj.p2.y) : constructionPoint; }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { if (!mouseOnPoint_construct(mouse, obj.p1)) @@ -37,18 +37,18 @@ objTypes['lineobj'] = { } }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { - //移動線段的第一點 Move the first point + // Move the first point obj.p1.x = obj.p1.x + diffX; obj.p1.y = obj.p1.y + diffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x + diffX; obj.p2.y = obj.p2.y + diffY; }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2)) { @@ -65,20 +65,20 @@ objTypes['lineobj'] = { if (mouseOnSegment(mouse_nogrid, obj)) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { var basePoint; if (draggingPart.part == 1) { - //正在拖曳第一個端點 Dragging the first endpoint Dragging the first endpoint + // Dragging the first endpoint Dragging the first endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p2; obj.p1 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse; @@ -86,7 +86,7 @@ objTypes['lineobj'] = { } if (draggingPart.part == 2) { - //正在拖曳第二個端點 Dragging the second endpoint Dragging the second endpoint + // Dragging the second endpoint Dragging the second endpoint basePoint = ctrl ? graphs.midpoint(draggingPart.originalObj) : draggingPart.originalObj.p1; obj.p2 = shift ? snapToDirection(mouse, basePoint, [{x: 1, y: 0},{x: 0, y: 1},{x: 1, y: 1},{x: 1, y: -1},{x: (draggingPart.originalObj.p2.x - draggingPart.originalObj.p1.x), y: (draggingPart.originalObj.p2.y - draggingPart.originalObj.p1.y)}]) : mouse; @@ -94,7 +94,7 @@ objTypes['lineobj'] = { } if (draggingPart.part == 0) { - //正在拖曳整條線 Dragging the entire line + // Dragging the entire line if (shift) { @@ -103,23 +103,23 @@ objTypes['lineobj'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } - var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; //目前滑鼠位置與上一次的滑鼠位置的X軸差 The X difference between the mouse position now and at the previous moment - var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; //目前滑鼠位置與上一次的滑鼠位置的Y軸差 The Y difference between the mouse position now and at the previous moment The Y difference between the mouse position now and at the previous moment - //移動線段的第一點 Move the first point + var mouseDiffX = draggingPart.mouse1.x - mouse_snapped.x; // The X difference between the mouse position now and at the previous moment + var mouseDiffY = draggingPart.mouse1.y - mouse_snapped.y; // The Y difference between the mouse position now and at the previous moment The Y difference between the mouse position now and at the previous moment + // Move the first point obj.p1.x = obj.p1.x - mouseDiffX; obj.p1.y = obj.p1.y - mouseDiffY; - //移動線段的第二點 Move the second point + // Move the second point obj.p2.x = obj.p2.x - mouseDiffX; obj.p2.y = obj.p2.y - mouseDiffY; - //更新滑鼠位置 Update the mouse position + // Update the mouse position draggingPart.mouse1 = mouse_snapped; } }, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.p1, obj.p2)); diff --git a/simulator/js/objs/mirror.js b/simulator/js/objs/mirror.js index dd2161f6..7ecd0f14 100644 --- a/simulator/js/objs/mirror.js +++ b/simulator/js/objs/mirror.js @@ -1,13 +1,12 @@ - -// Mirrors -> Segment +// Mirror -> Segment objTypes['mirror'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'mirror', p1: mouse, p2: mouse}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -15,7 +14,7 @@ objTypes['mirror'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.strokeStyle = getMouseStyle(obj, (colorMode && obj.wavelength && obj.isDichroic) ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(168,168,168)'); ctx.beginPath(); @@ -24,7 +23,7 @@ objTypes['mirror'] = { ctx.stroke(); }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { dichroicSettings(obj,elem); }, @@ -36,7 +35,7 @@ objTypes['mirror'] = { } }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(mirror, ray, rayIndex, rp) { var rx = ray.p1.x - rp.x; var ry = ray.p1.y - rp.y; diff --git a/simulator/js/objs/parabolicmirror.js b/simulator/js/objs/parabolicmirror.js index 5ad92ae3..43f608cf 100644 --- a/simulator/js/objs/parabolicmirror.js +++ b/simulator/js/objs/parabolicmirror.js @@ -1,15 +1,14 @@ -// Mirrors -> Parabolic -// Originally contributed by Paul Falstad (pfalstad) +// Mirror -> Parabolic objTypes['parabolicmirror'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'parabolicmirror', p1: mouse}; }, dichroicSettings: objTypes['mirror'].dichroicSettings, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { dichroicSettings(obj,elem); }, @@ -18,7 +17,7 @@ objTypes['parabolicmirror'] = { c_mousemove: objTypes['arcmirror'].c_mousemove, c_mouseup: objTypes['arcmirror'].c_mouseup, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.fillStyle = 'rgb(255,0,255)'; if (obj.p3 && obj.p2) @@ -75,7 +74,7 @@ objTypes['parabolicmirror'] = { move: objTypes['arcmirror'].move, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p3)) { @@ -104,10 +103,10 @@ objTypes['parabolicmirror'] = { var seg = graphs.segment(pts[i], pts[i+1]); if (mouseOnSegment(mouse_nogrid, seg)) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -117,13 +116,13 @@ objTypes['parabolicmirror'] = { dragging: objTypes['arcmirror'].dragging, - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { if (!obj.p3) {return;} return objTypes['curvedmirror'].rayIntersection(obj, ray); }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp) { return objTypes['curvedmirror'].shot(obj, ray, rayIndex, rp); } diff --git a/simulator/js/objs/parallel.js b/simulator/js/objs/parallel.js index 35258fbb..de6d3f83 100644 --- a/simulator/js/objs/parallel.js +++ b/simulator/js/objs/parallel.js @@ -1,14 +1,14 @@ -// Beam +// Light Souce -> Beam objTypes['parallel'] = { tmp_randomNumbers: [], - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'parallel', p1: mouse, p2: mouse, p: 0.5, divergence: 0.0, lambert: false, random: false}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('brightness'), 0, 1, 0.01, obj.p || 1, function(obj, value) { obj.p = value; @@ -41,7 +41,7 @@ objTypes['parallel'] = { } }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -49,7 +49,7 @@ objTypes['parallel'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { var a_l = Math.atan2(obj.p1.x - obj.p2.x, obj.p1.y - obj.p2.y) - Math.PI / 2; ctx.strokeStyle = getMouseStyle(obj, colorMode ? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : 'rgb(0,255,0)'); @@ -105,7 +105,7 @@ objTypes['parallel'] = { addRay(ray1); }, - //射出光線 Shoot rays + // Shoot rays shoot: function(obj) { var n = graphs.length_segment(obj) * getRayDensity(); var stepX = (obj.p2.x - obj.p1.x) / n; diff --git a/simulator/js/objs/power.js b/simulator/js/objs/power.js index 504f5b9b..8250c154 100644 --- a/simulator/js/objs/power.js +++ b/simulator/js/objs/power.js @@ -1,12 +1,12 @@ -// Detector +// Other -> Detector objTypes['power'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'power', p1: mouse, p2: mouse, power: 0, normal: 0, shear: 0}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createBooleanAttr(getMsg('irradiance_map'), !!obj.irradianceMap, function(obj, value) { obj.irradianceMap = value; @@ -49,7 +49,7 @@ objTypes['power'] = { } }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -58,7 +58,7 @@ objTypes['power'] = { dragging: objTypes['lineobj'].dragging, rayIntersection: objTypes['lineobj'].rayIntersection, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { if (!aboveLight) { ctx.globalCompositeOperation = 'lighter'; @@ -145,7 +145,7 @@ objTypes['power'] = { }, - //射出光線 Shoot rays + // Shoot rays shoot: function(obj) { obj.power = 0; obj.normal = 0; @@ -162,7 +162,7 @@ objTypes['power'] = { } }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, shootPoint) { var rcrosss = (ray.p2.x - ray.p1.x) * (obj.p2.y - obj.p1.y) - (ray.p2.y - ray.p1.y) * (obj.p2.x - obj.p1.x); var sint = rcrosss / Math.sqrt((ray.p2.x - ray.p1.x) * (ray.p2.x - ray.p1.x) + (ray.p2.y - ray.p1.y) * (ray.p2.y - ray.p1.y)) / Math.sqrt((obj.p2.x - obj.p1.x) * (obj.p2.x - obj.p1.x) + (obj.p2.y - obj.p1.y) * (obj.p2.y - obj.p1.y)); diff --git a/simulator/js/objs/protractor.js b/simulator/js/objs/protractor.js index f920bd5e..ca2bc71b 100644 --- a/simulator/js/objs/protractor.js +++ b/simulator/js/objs/protractor.js @@ -1,18 +1,18 @@ -// Protractor +// Other -> Protractor objTypes['protractor'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'protractor', p1: mouse, p2: mouse}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: function(obj, mouse, ctrl, shift) {objTypes['lineobj'].c_mousemove(obj, mouse, false, shift)}, c_mouseup: objTypes['lineobj'].c_mouseup, move: objTypes['lineobj'].move, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj.p1) && graphs.length_squared(mouse_nogrid, obj.p1) <= graphs.length_squared(mouse_nogrid, obj.p2)) { @@ -29,18 +29,18 @@ objTypes['protractor'] = { if (Math.abs(graphs.length(obj.p1, mouse_nogrid) - graphs.length_segment(obj)) < getClickExtent()) { draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) {objTypes['lineobj'].dragging(obj, mouse, draggingPart, false, shift)}, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { if (!aboveLight) { @@ -61,14 +61,14 @@ objTypes['protractor'] = { if (r * scale_step * Math.PI / 180 < scale_width_limit) { - //刻度太小 The scale is too small + // The scale is too small scale_step = 2; scale_step_mid = 10; scale_step_long = 30; } if (r * scale_step * Math.PI / 180 < scale_width_limit) { - //刻度太小 The scale is too small + // The scale is too small scale_step = 5; scale_step_mid = 10; scale_step_long = 30; @@ -79,7 +79,7 @@ objTypes['protractor'] = { } if (r * scale_step * Math.PI / 180 < scale_width_limit) { - //刻度太小 The scale is too small + // The scale is too small scale_step = 10; scale_step_mid = 30; scale_step_long = 90; diff --git a/simulator/js/objs/radiant.js b/simulator/js/objs/radiant.js index 15ec868b..110116ce 100644 --- a/simulator/js/objs/radiant.js +++ b/simulator/js/objs/radiant.js @@ -1,12 +1,12 @@ -// Point source -> 360 degrees +// Light Source -> Point source (360deg) objTypes['radiant'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'radiant', x: mouse.x, y: mouse.y, p: 0.5}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createNumberAttr(getMsg('brightness'), 0, 1, 0.01, obj.p || 1, function(obj, value) { obj.p = value; @@ -18,23 +18,23 @@ objTypes['radiant'] = { } }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { isConstructing = false; }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { ctx.fillStyle = colorMode? wavelengthToColor(obj.wavelength || GREEN_WAVELENGTH, 1) : getMouseStyle(obj, 'rgb(0,255,0)'); ctx.fillRect(obj.x - 2.5, obj.y - 2.5, 5, 5); @@ -44,14 +44,14 @@ objTypes['radiant'] = { } }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { obj.x = obj.x + diffX; obj.y = obj.y + diffY; return obj; }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { if (mouseOnPoint(mouse_nogrid, obj)) { @@ -64,7 +64,7 @@ objTypes['radiant'] = { return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { if (shift) { @@ -73,17 +73,17 @@ objTypes['radiant'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } obj.x = mouse_snapped.x; obj.y = mouse_snapped.y; }, - //射出光線 Shoot rays + // Shoot rays shoot: function(obj) { var s = Math.PI * 2 / parseInt(getRayDensity() * 500); - var i0 = (mode == 'observer') ? (-s * 2 + 1e-6) : 0; //為避免使用觀察者時出現黑色間格 To avoid black gap when using the observer + var i0 = (mode == 'observer') ? (-s * 2 + 1e-6) : 0; // To avoid black gap when using the observer for (var i = i0; i < (Math.PI * 2 - 1e-5); i = i + s) { var ray1 = graphs.ray(graphs.point(obj.x, obj.y), graphs.point(obj.x + Math.sin(i), obj.y + Math.cos(i))); diff --git a/simulator/js/objs/refractor.js b/simulator/js/objs/refractor.js index 90e48e0b..f7c90563 100644 --- a/simulator/js/objs/refractor.js +++ b/simulator/js/objs/refractor.js @@ -1,14 +1,14 @@ -// Glasses -> Free-shape +// Glass -> Polygon / Circular Arcs objTypes['refractor'] = { supportSurfaceMerging: true, - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'refractor', path: [{x: mouse.x, y: mouse.y, arc: false}], notDone: true, p: 1.5}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { if (colorMode) { createNumberAttr(getMsg('cauchycoeff') + " A", 1, 3, 0.01, obj.p, function(obj, value) { @@ -24,23 +24,23 @@ objTypes['refractor'] = { } }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { if (obj.path.length > 1) { if (obj.path.length > 3 && mouseOnPoint(mouse, obj.path[0])) { - //滑鼠按了第一點 Clicked the first point + // Clicked the first point obj.path.length--; obj.notDone = false; return; } - obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; //移動最後一點 Move the last point + obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; // Move the last point obj.path[obj.path.length - 1].arc = true; } }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { if (!obj.notDone) {return;} @@ -53,10 +53,10 @@ objTypes['refractor'] = { } else { - obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; //移動最後一點 Move the last point + obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; // Move the last point } }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { if (!obj.notDone) { @@ -65,7 +65,7 @@ objTypes['refractor'] = { } if (obj.path.length > 3 && mouseOnPoint(mouse, obj.path[0])) { - //滑鼠在第一點處放開 Mouse released at the first point + // Mouse released at the first point obj.path.length--; obj.notDone = false; isConstructing = false; @@ -77,9 +77,9 @@ objTypes['refractor'] = { } else { - obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; //移動最後一點 Move the last point + obj.path[obj.path.length - 1] = {x: mouse.x, y: mouse.y}; // Move the last point obj.path[obj.path.length - 1].arc = false; - obj.path[obj.path.length] = {x: mouse.x, y: mouse.y}; //建立新的一點 Create a new point + obj.path[obj.path.length] = {x: mouse.x, y: mouse.y}; // Create a new point } }, @@ -88,7 +88,7 @@ objTypes['refractor'] = { return obj.p * (-1); // The material with (relative) refractive index < 1 should be draw after the one with > 1 so that the color subtraction in fillGlass works. }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { var p1; var p2; @@ -102,7 +102,7 @@ objTypes['refractor'] = { if (obj.notDone) { - //使用者尚未畫完物件 The user has not finish drawing the obj yet + // The user has not finish drawing the obj yet ctx.beginPath(); ctx.moveTo(obj.path[0].x, obj.path[0].y); @@ -121,13 +121,13 @@ objTypes['refractor'] = { a1 = Math.atan2(p1.y - center.y, p1.x - center.x); a2 = Math.atan2(p2.y - center.y, p2.x - center.x); a3 = Math.atan2(p3.y - center.y, p3.x - center.x); - acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); //p1->p3->p2之旋轉方向,逆時針為true The rotation direction of p1->p3->p2. True indicates counterclockwise + acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); // The rotation direction of p1->p3->p2. True indicates counterclockwise ctx.arc(center.x, center.y, r, a1, a2, acw); } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. ctx.lineTo(obj.path[(i + 2)].x, obj.path[(i + 2)].y); } @@ -145,7 +145,7 @@ objTypes['refractor'] = { } else { - //物件已經畫完 The user has completed drawing the obj + // The user has completed drawing the obj ctx.beginPath(); ctx.moveTo(obj.path[0].x, obj.path[0].y); @@ -163,13 +163,13 @@ objTypes['refractor'] = { a1 = Math.atan2(p1.y - center.y, p1.x - center.x); a2 = Math.atan2(p2.y - center.y, p2.x - center.x); a3 = Math.atan2(p3.y - center.y, p3.x - center.x); - acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); //p1->p3->p2之旋轉方向,逆時針為true The rotation direction of p1->p3->p2. True indicates counterclockwise + acw = (a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2); // The rotation direction of p1->p3->p2. True indicates counterclockwise ctx.arc(center.x, center.y, r, a1, a2, acw); } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. ctx.lineTo(obj.path[(i + 2) % obj.path.length].x, obj.path[(i + 2) % obj.path.length].y); } @@ -279,7 +279,7 @@ objTypes['refractor'] = { }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { for (var i = 0; i < obj.path.length; i++) { @@ -289,7 +289,7 @@ objTypes['refractor'] = { }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { var p1; @@ -342,23 +342,23 @@ objTypes['refractor'] = { var a_m = Math.atan2(mouse_nogrid.y - center.y, mouse_nogrid.x - center.x); if (Math.abs(graphs.length(center, mouse_nogrid) - r) < getClickExtent() && (((a2 < a3 && a3 < a1) || (a1 < a2 && a2 < a3) || (a3 < a1 && a1 < a2)) == ((a2 < a_m && a_m < a1) || (a1 < a2 && a2 < a_m) || (a_m < a1 && a1 < a2)))) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. + // The three points on the arc is colinear. Treat as a line segment. if (mouseOnSegment(mouse_nogrid, graphs.segment(obj.path[(i) % obj.path.length], obj.path[(i + 2) % obj.path.length]))) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -369,10 +369,10 @@ objTypes['refractor'] = { { if (mouseOnSegment(mouse_nogrid, graphs.segment(obj.path[(i) % obj.path.length], obj.path[(i + 1) % obj.path.length]))) { - //拖曳整個物件 Dragging the entire obj + // Dragging the entire obj draggingPart.part = 0; - draggingPart.mouse0 = mouse; //開始拖曳時的滑鼠位置 Mouse position when the user starts dragging - draggingPart.mouse1 = mouse; //拖曳時上一點的滑鼠位置 Mouse position at the last moment during dragging + draggingPart.mouse0 = mouse; // Mouse position when the user starts dragging + draggingPart.mouse1 = mouse; // Mouse position at the last moment during dragging draggingPart.snapData = {}; return true; } @@ -381,7 +381,7 @@ objTypes['refractor'] = { }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { if (draggingPart.part == 1) { @@ -398,7 +398,7 @@ objTypes['refractor'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } this.move(obj, mouse_snapped.x - draggingPart.mouse1.x, mouse_snapped.y - draggingPart.mouse1.y); draggingPart.mouse1 = mouse_snapped; @@ -407,7 +407,7 @@ objTypes['refractor'] = { - //判斷一道光是否會射到此物件(若是,則回傳交點) Test if a ray may shoot on this object (if yes, return the intersection) + // Test if a ray may shoot on this object (if yes, return the intersection) rayIntersection: function(obj, ray) { if (obj.notDone || obj.p <= 0)return; @@ -431,7 +431,7 @@ objTypes['refractor'] = { s_point_temp = null; if (obj.path[(i + 1) % obj.path.length].arc && !obj.path[i % obj.path.length].arc) { - //圓弧i->i+1->i+2 The arc i->i+1->i+2 + // The arc i->i+1->i+2 p1 = graphs.point(obj.path[i % obj.path.length].x, obj.path[i % obj.path.length].y); p2 = graphs.point(obj.path[(i + 2) % obj.path.length].x, obj.path[(i + 2) % obj.path.length].y); p3 = graphs.point(obj.path[(i + 1) % obj.path.length].x, obj.path[(i + 1) % obj.path.length].y); @@ -458,8 +458,7 @@ objTypes['refractor'] = { } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. - //線段i->i+2 + // The three points on the arc is colinear. Treat as a line segment. var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.path[i % obj.path.length], obj.path[(i + 2) % obj.path.length])); if (graphs.intersection_is_on_segment(rp_temp, graphs.segment(obj.path[i % obj.path.length], obj.path[(i + 2) % obj.path.length])) && graphs.intersection_is_on_ray(rp_temp, ray) && graphs.length_squared(ray.p1, rp_temp) > minShotLength_squared) @@ -472,12 +471,11 @@ objTypes['refractor'] = { else if (!obj.path[(i + 1) % obj.path.length].arc && !obj.path[i % obj.path.length].arc) { //Line segment i->i+1 - var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.path[i % obj.path.length], obj.path[(i + 1) % obj.path.length])); //求光(的延長線)與物件(的延長線)的交點 + var rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.path[i % obj.path.length], obj.path[(i + 1) % obj.path.length])); if (graphs.intersection_is_on_segment(rp_temp, graphs.segment(obj.path[i % obj.path.length], obj.path[(i + 1) % obj.path.length])) && graphs.intersection_is_on_ray(rp_temp, ray) && graphs.length_squared(ray.p1, rp_temp) > minShotLength_squared) { - //↑若rp_temp在ray上且rp_temp在obj上(即ray真的有射到obj,不是ray的延長線射到或射到obj的延長線上) - s_lensq_temp = graphs.length_squared(ray.p1, rp_temp); //交點到[光線的頭]的距離 + s_lensq_temp = graphs.length_squared(ray.p1, rp_temp); s_point_temp = rp_temp; } } @@ -497,7 +495,7 @@ objTypes['refractor'] = { }, - //當物件被光射到時 When the obj is shot by a ray + // When the obj is shot by a ray shot: function(obj, ray, rayIndex, rp, surfaceMerging_objs) { if (obj.notDone) {return;} @@ -505,50 +503,50 @@ objTypes['refractor'] = { var shotType = shotData.shotType; if (shotType == 1) { - //從內部射向外部 Shot from inside to outside - var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); //來源介質的折射率(目的介質假設為1) The refractive index of the source material (assuming the destination has 1) + // Shot from inside to outside + var n1 = (!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); // The refractive index of the source material (assuming the destination has 1) } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside var n1 = 1 / ((!colorMode)?obj.p:(obj.p + (obj.cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001))); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) var n1 = 1; } else { - //可能導致Bug的狀況(如射到邊界點) The situation that may cause a bug (e.g. shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // The situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } - //界面融合 Surface merging + // Surface merging for (var i = 0; i < surfaceMerging_objs.length; i++) { shotType = objTypes[surfaceMerging_objs[i].type].getShotType(surfaceMerging_objs[i], ray); if (shotType == 1) { - //從內部射向外部 Shot from inside to outside + // Shot from inside to outside n1 *= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == -1) { - //從外部射向內部 Shot from outside to inside + // Shot from outside to inside n1 /= (!colorMode)?surfaceMerging_objs[i].p:(surfaceMerging_objs[i].p + (surfaceMerging_objs[i].cauchyCoeff || 0.004) / (ray.wavelength*ray.wavelength*0.000001)); } else if (shotType == 0) { - //等同於沒射到 Equivalent to not shot on the obj(例如兩界面重合) + // Equivalent to not shot on the obj (e.g. two interfaces overlap) //n1=n1; } else { - //可能導致Bug的狀況(如射到邊界點 Shot at an edge point) - //為防止光線射向錯誤方向導致誤解,將光線吸收 To prevent shooting the ray to a wrong direction, absorb the ray + // Situation that may cause bugs (e.g. shot at an edge point) + // To prevent shooting the ray to a wrong direction, absorb the ray ray.exist = false; return; } @@ -557,21 +555,21 @@ objTypes['refractor'] = { this.refract(ray, rayIndex, shotData.s_point, shotData.normal, n1); }, - //判斷光線內部/外部射出 Test if the ray is shot from inside or outside + // Test if the ray is shot from inside or outside getShotType: function(obj, ray) { return this.getShotData(obj, ray).shotType; }, getShotData: function(obj, ray) { - //判斷光射到物件的何處 Test where in the obj does the ray shoot on + // Test where in the obj does the ray shoot on var s_lensq = Infinity; var s_lensq_temp; var s_point = null; var s_point_temp = null; var s_point_index; - var surfaceMultiplicity = 1; //界面重合次數 How many time the surfaces coincide + var surfaceMultiplicity = 1; // How many time the surfaces coincide var rp_on_ray = []; var rp_exist = []; @@ -598,8 +596,8 @@ objTypes['refractor'] = { var p2; var p3; var center; - var ray2 = graphs.ray(ray.p1, graphs.point(ray.p2.x + Math.random() * 1e-5, ray.p2.y + Math.random() * 1e-5)); //用來作為內外判斷的光線(測試光線) The ray to test the inside/outside (the test ray) - var ray_intersect_count = 0; //測試光線與物件的相交次數(奇數表示光線來自內部) The intersection count (odd means from outside) + var ray2 = graphs.ray(ray.p1, graphs.point(ray.p2.x + Math.random() * 1e-5, ray.p2.y + Math.random() * 1e-5)); // The ray to test the inside/outside (the test ray) + var ray_intersect_count = 0; // The intersection count (odd means from outside) for (var i = 0; i < obj.path.length; i++) { @@ -607,7 +605,7 @@ objTypes['refractor'] = { nearEdge_temp = false; if (obj.path[(i + 1) % obj.path.length].arc && !obj.path[i % obj.path.length].arc) { - //圓弧i->i+1->i+2 The arc i->i+1->i+2 + // The arc i->i+1->i+2 p1 = graphs.point(obj.path[i % obj.path.length].x, obj.path[i % obj.path.length].y); p2 = graphs.point(obj.path[(i + 2) % obj.path.length].x, obj.path[(i + 2) % obj.path.length].y); p3 = graphs.point(obj.path[(i + 1) % obj.path.length].x, obj.path[(i + 1) % obj.path.length].y); @@ -667,7 +665,7 @@ objTypes['refractor'] = { ray_intersect_count++; } - //太靠近邊界的判斷 Test if too close to an edge + // Test if too close to an edge if (s_point_temp && (graphs.length_squared(s_point_temp, p1) < minShotLength_squared || graphs.length_squared(s_point_temp, p2) < minShotLength_squared)) { nearEdge_temp = true; @@ -676,8 +674,7 @@ objTypes['refractor'] = { } else { - //圓弧三點共線,當作線段處理 The three points on the arc is colinear. Treat as a line segment. - //線段i->i+2 + // The three points on the arc is colinear. Treat as a line segment. rp_temp = graphs.intersection_2line(graphs.line(ray.p1, ray.p2), graphs.line(obj.path[i % obj.path.length], obj.path[(i + 2) % obj.path.length])); rp2_temp = graphs.intersection_2line(graphs.line(ray2.p1, ray2.p2), graphs.line(obj.path[i % obj.path.length], obj.path[(i + 2) % obj.path.length])); @@ -700,7 +697,7 @@ objTypes['refractor'] = { ray_intersect_count++; } - //太靠近邊界的判斷 Test if too close to an edge + // Test if too close to an edge if (s_point_temp && (graphs.length_squared(s_point_temp, obj.path[i % obj.path.length]) < minShotLength_squared || graphs.length_squared(s_point_temp, obj.path[(i + 2) % obj.path.length]) < minShotLength_squared)) { nearEdge_temp = true; @@ -732,7 +729,7 @@ objTypes['refractor'] = { ray_intersect_count++; } - //太靠近邊界的判斷 Test if too close to an edge + // Test if too close to an edge if (s_point_temp && (graphs.length_squared(s_point_temp, obj.path[i % obj.path.length]) < minShotLength_squared || graphs.length_squared(s_point_temp, obj.path[(i + 1) % obj.path.length]) < minShotLength_squared)) { nearEdge_temp = true; @@ -742,7 +739,7 @@ objTypes['refractor'] = { { if (s_point && graphs.length_squared(s_point_temp, s_point) < minShotLength_squared) { - //自我界面融合 Self surface merging + // Self surface merging surfaceMultiplicity++; } else if (s_lensq_temp < s_lensq) @@ -761,25 +758,25 @@ objTypes['refractor'] = { if (nearEdge) { - var shotType = 2; //射到邊界點 Shot at an edge point + var shotType = 2; // Shot at an edge point } else if (surfaceMultiplicity % 2 == 0) { - var shotType = 0; //等同於沒射到 Equivalent to not shot on the obj + var shotType = 0; // Equivalent to not shot on the obj } else if (ray_intersect_count % 2 == 1) { - var shotType = 1; //從內部射向外部 Shot from inside to outside + var shotType = 1; // Shot from inside to outside } else { - var shotType = -1; //從外部射向內部 Shot from outside to inside + var shotType = -1; // Shot from outside to inside } return {s_point: s_point, normal: {x: normal_x, y: normal_y},shotType: shotType}; }, - //折射處理 Do the refraction + // Do the refraction refract: function(ray, rayIndex, s_point, normal, n1) { var normal_len = Math.sqrt(normal.x * normal.x + normal.y * normal.y); @@ -792,7 +789,7 @@ objTypes['refractor'] = { var ray_y = (ray.p2.y - ray.p1.y) / ray_len; - //參考 Reference http://en.wikipedia.org/wiki/Snell%27s_law#Vector_form + // Reference http://en.wikipedia.org/wiki/Snell%27s_law#Vector_form var cos1 = -normal_x * ray_x - normal_y * ray_y; var sq1 = 1 - n1 * n1 * (1 - cos1 * cos1); @@ -800,7 +797,7 @@ objTypes['refractor'] = { if (sq1 < 0) { - //全反射 Total internal reflection + // Total internal reflection ray.p1 = s_point; ray.p2 = graphs.point(s_point.x + ray_x + 2 * cos1 * normal_x, s_point.y + ray_y + 2 * cos1 * normal_y); @@ -808,14 +805,14 @@ objTypes['refractor'] = { } else { - //折射 Refraction + // Refraction var cos2 = Math.sqrt(sq1); var R_s = Math.pow((n1 * cos1 - cos2) / (n1 * cos1 + cos2), 2); var R_p = Math.pow((n1 * cos2 - cos1) / (n1 * cos2 + cos1), 2); - //參考 Reference http://en.wikipedia.org/wiki/Fresnel_equations#Definitions_and_power_equations + // Reference http://en.wikipedia.org/wiki/Fresnel_equations#Definitions_and_power_equations - //處理反射光 Handle the reflected ray + // Handle the reflected ray var ray2 = graphs.ray(s_point, graphs.point(s_point.x + ray_x + 2 * cos1 * normal_x, s_point.y + ray_y + 2 * cos1 * normal_y)); ray2.brightness_s = ray.brightness_s * R_s; ray2.brightness_p = ray.brightness_p * R_p; @@ -840,7 +837,7 @@ objTypes['refractor'] = { } } - //處理折射光 Handle the refracted ray + // Handle the refracted ray ray.p1 = s_point; ray.p2 = graphs.point(s_point.x + n1 * ray_x + (n1 * cos1 - cos2) * normal_x, s_point.y + n1 * ray_y + (n1 * cos1 - cos2) * normal_y); ray.brightness_s = ray.brightness_s * (1 - R_s); diff --git a/simulator/js/objs/ruler.js b/simulator/js/objs/ruler.js index b2ce8ba0..5862b2f7 100644 --- a/simulator/js/objs/ruler.js +++ b/simulator/js/objs/ruler.js @@ -1,12 +1,12 @@ -// Ruler +// Other -> Ruler objTypes['ruler'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'ruler', p1: mouse, p2: mouse}; }, - //使用lineobj原型 Use the prototype lineobj + // Use the prototype lineobj c_mousedown: objTypes['lineobj'].c_mousedown, c_mousemove: objTypes['lineobj'].c_mousemove, c_mouseup: objTypes['lineobj'].c_mouseup, @@ -14,7 +14,7 @@ objTypes['ruler'] = { clicked: objTypes['lineobj'].clicked, dragging: objTypes['lineobj'].dragging, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx, aboveLight) { if (aboveLight)return; ctx.globalCompositeOperation = 'lighter'; diff --git a/simulator/js/objs/sphericallens.js b/simulator/js/objs/sphericallens.js index e1950815..686853b0 100644 --- a/simulator/js/objs/sphericallens.js +++ b/simulator/js/objs/sphericallens.js @@ -1,5 +1,4 @@ -// Glasses -> Spherical Lens -// Originally contributed by Paul Falstad (pfalstad) +// Glass -> Spherical Lens objTypes['sphericallens'] = { supportSurfaceMerging: true, @@ -8,7 +7,7 @@ objTypes['sphericallens'] = { return {type: 'sphericallens', p1: mouse, p2: mouse, p: 1.5, tmp_params: {r1: NaN, r2: NaN, d: 40}}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { createDropdownAttr(getMsg('defined_by'), obj.definedBy || 'DR1R2', { @@ -103,7 +102,7 @@ objTypes['sphericallens'] = { }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { if (shift) @@ -118,7 +117,7 @@ objTypes['sphericallens'] = { this.createLens(obj); }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { if (shift) @@ -134,7 +133,7 @@ objTypes['sphericallens'] = { this.createLens(obj); }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { if (!mouseOnPoint_construct(mouse, obj.p1)) diff --git a/simulator/js/objs/text.js b/simulator/js/objs/text.js index 7a62b6f7..ca2689f6 100644 --- a/simulator/js/objs/text.js +++ b/simulator/js/objs/text.js @@ -1,5 +1,4 @@ -// Text -// Originally contributed by Paul Falstad (pfalstad) +// Other -> Text // generic list of web safe fonts fonts = [ @@ -33,12 +32,12 @@ fontAlignments = { objTypes['text'] = { - //建立物件 Create the obj + // Create the obj create: function(mouse) { return {type: 'text', x: mouse.x, y: mouse.y, p: getMsg("text_here"), fontSize: 24, fontName: 'Serif', fontStyle: 'Normal', fontAlignment: 'left', fontSmallCaps: false, fontAngle: 0}; }, - //顯示屬性方塊 Show the property box + // Show the property box p_box: function(obj, elem) { // createStringAttr('', obj.p, function(obj, value) { // obj.p = value; @@ -69,26 +68,26 @@ objTypes['text'] = { } }, - //建立物件過程滑鼠按下 Mousedown when the obj is being constructed by the user + // Mousedown when the obj is being constructed by the user c_mousedown: function(obj, mouse, ctrl, shift) { }, - //建立物件過程滑鼠移動 Mousemove when the obj is being constructed by the user + // Mousemove when the obj is being constructed by the user c_mousemove: function(obj, mouse, ctrl, shift) { obj.x=mouse.x; obj.y=mouse.y; }, - //建立物件過程滑鼠放開 Mouseup when the obj is being constructed by the user + // Mouseup when the obj is being constructed by the user c_mouseup: function(obj, mouse, ctrl, shift) { isConstructing = false; }, - //將物件畫到Canvas上 Draw the obj on canvas + // Draw the obj on canvas draw: function(obj, ctx ,aboveLight) { ctx.fillStyle = getMouseStyle(obj, 'white'); ctx.textAlign = obj.fontAlignment || 'left'; @@ -127,14 +126,14 @@ objTypes['text'] = { obj.tmp_cos_angle = Math.cos((obj.fontAngle||0)/180*Math.PI); }, - //平移物件 Move the object + // Move the object move: function(obj, diffX, diffY) { obj.x = obj.x + diffX; obj.y = obj.y + diffY; return obj; }, - //繪圖區被按下時(判斷物件被按下的部分) When the drawing area is clicked (test which part of the obj is clicked) + // When the drawing area is clicked (test which part of the obj is clicked) clicked: function(obj, mouse_nogrid, mouse, draggingPart) { // translate and rotate the mouse point into the text's reference frame for easy comparison @@ -154,7 +153,7 @@ objTypes['text'] = { return false; }, - //拖曳物件時 When the user is dragging the obj + // When the user is dragging the obj dragging: function(obj, mouse, draggingPart, ctrl, shift) { if (shift) { @@ -163,7 +162,7 @@ objTypes['text'] = { else { var mouse_snapped = mouse; - draggingPart.snapData = {}; //放開shift時解除原先之拖曳方向鎖定 Unlock the dragging direction when the user release the shift key + draggingPart.snapData = {}; // Unlock the dragging direction when the user release the shift key } // 'mouse' current mouse position, snapped to grid diff --git a/simulator/js/simulator.js b/simulator/js/simulator.js index 8e5c5337..df0ffe2f 100644 --- a/simulator/js/simulator.js +++ b/simulator/js/simulator.js @@ -1,7 +1,7 @@ -var waitingRays = []; //待處理光線 The rays waiting for shooting -var waitingRayCount = 0; //待處理光線數量 Number of rays waiting for shooting -var rayDensity_light = 0.1; //光線密度(光線相關模式) The Ray Density when View is Rays or Extended rays -var rayDensity_images = 1; //光線密度(像相關模式) The Ray Density when View is All Images or Seen by Observer +var waitingRays = []; // The rays waiting for shooting +var waitingRayCount = 0; // Number of rays waiting for shooting +var rayDensity_light = 0.1; // The Ray Density when View is Rays or Extended rays +var rayDensity_images = 1; // The Ray Density when View is All Images or Seen by Observer var mode = 'light'; var extendLight = false; var showLight = true; @@ -15,8 +15,8 @@ var hasExceededTime = false; var forceStop = false; var lastDrawTime = -1; var drawBeginTime = -1; -var stateOutdated = false; //上次繪圖完後狀態已經變更 The state has changed since last draw -var minShotLength = 1e-6; //光線兩次作用的最短距離(小於此距離的光線作用會被忽略) The minimal length between two interactions with rays (when smaller than this, the interaction will be ignored) +var stateOutdated = false; // The state has changed since last draw +var minShotLength = 1e-6; // The minimal length between two interactions with rays (when smaller than this, the interaction will be ignored) var minShotLength_squared = minShotLength * minShotLength; var totalTruncation = 0; var canvasPainter; @@ -43,7 +43,7 @@ function draw(skipLight, skipGrid) if (!skipLight && timerID != -1) { - //若程式正在處理上一次的繪圖,則停止處理 If still handling the last draw, then stop + // If still handling the last draw, then stop clearTimeout(timerID); timerID = -1; } @@ -93,7 +93,7 @@ function draw_(skipLight, skipGrid) { canvasPainterGrid.cls(); if (document.getElementById('showgrid').checked) { - //畫出格線 Draw the grid + // Draw the grid ctxGrid.save(); ctxGrid.setTransform((scale*dpr), 0, 0, (scale*dpr), 0, 0); @@ -146,14 +146,14 @@ function draw_(skipLight, skipGrid) { mapped.sort(function(a, b) { return a.value - b.value; }); - //畫出物件 Draw the objects + // Draw the objects for (var j = 0; j < objs.length; j++) { var i = mapped[j].index; objTypes[objs[i].type].draw(objs[i], ctx0, false); if (!skipLight && objTypes[objs[i].type].shoot) { - objTypes[objs[i].type].shoot(objs[i]); //若objs[i]能射出光線,讓它射出 If objs[i] can shoot rays, shoot them. + objTypes[objs[i].type].shoot(objs[i]); // If objs[i] can shoot rays, shoot them. } } } @@ -173,11 +173,11 @@ function draw_(skipLight, skipGrid) { for (var i = 0; i < objs.length; i++) { - objTypes[objs[i].type].draw(objs[i], ctx, true); //畫出objs[i] Draw objs[i] + objTypes[objs[i].type].draw(objs[i], ctx, true); // Draw objs[i] } if (mode == 'observer') { - //畫出即時觀察者 Draw the observer + // Draw the observer ctx.globalAlpha = 1; ctx.beginPath(); ctx.fillStyle = 'blue'; @@ -250,8 +250,8 @@ function shootWaitingRays() { while (true) { if (new Date() - st_time > 50 && !isExporting) { - //若已計算超過200ms If already run for 200ms - //先休息10ms後再繼續(防止程式沒有回應) Pause for 10ms and continue (prevent not responding) + // If already run for 200ms + // Pause for 10ms and continue (prevent not responding) hasExceededTime = true; timerID = setTimeout(shootWaitingRays, firstBreak ? 100:1); firstBreak = false; @@ -287,41 +287,41 @@ function shootWaitingRays() { var j = waitingRaysIndex; if (waitingRays[j] && waitingRays[j].exist) { - //開始射出waitingRays[j](等待區的最後一條光線) Start handling waitingRays[j] - //判斷這道光射出後,會先撞到哪一個物件 Test which object will this ray shoot on first + // Start handling waitingRays[j] + // Test which object will this ray shoot on first - //↓搜尋每一個"與這道光相交的物件",尋找"[物件與光線的交點]離[光線的頭]最近的物件" Search every object intersected with the ray, and find which intersection is the nearest - s_obj = null; //"到目前為止,已檢查的物件中[與光線的交點]離[光線的頭]最近的物件" The current nearest object in search + // Search every object intersected with the ray, and find which intersection is the nearest + s_obj = null; // The current nearest object in search s_obj_index = -1; - s_point = null; //s_obj與光線的交點 The intersection - surfaceMerging_objs = []; //要與射到的物件進行界面融合的物件 The objects whose surface is to be merged with s_obj + s_point = null; // The intersection + surfaceMerging_objs = []; // The objects whose surface is to be merged with s_obj s_lensq = Infinity; - observed = false; //waitingRays[j]是否被觀察者看到 Whether waitingRays[j] is observed by the observer + observed = false; // Whether waitingRays[j] is observed by the observer for (var i = 0; i < objs.length; i++) { - //↓若objs[i]會影響到光 if objs[i] can affect the ray + // if objs[i] can affect the ray if (objTypes[objs[i].type].rayIntersection) { - //↓判斷objs[i]是否與這道光相交 Test whether objs[i] intersects with the ray + // Test whether objs[i] intersects with the ray s_point_temp = objTypes[objs[i].type].rayIntersection(objs[i], waitingRays[j]); if (s_point_temp) { - //此時代表objs[i]是"與這道光相交的物件",交點是s_point_temp Here objs[i] intersects with the ray at s_point_temp + // Here objs[i] intersects with the ray at s_point_temp s_lensq_temp = graphs.length_squared(waitingRays[j].p1, s_point_temp); if (s_point && graphs.length_squared(s_point_temp, s_point) < minShotLength_squared && (objTypes[objs[i].type].supportSurfaceMerging || objTypes[s_obj.type].supportSurfaceMerging)) { - //這道光同時射到兩個物件,且至少有一個支援界面融合 The ray is shot on two objects at the same time, and at least one of them supports surface merging + // The ray is shot on two objects at the same time, and at least one of them supports surface merging if (objTypes[s_obj.type].supportSurfaceMerging) { if (objTypes[objs[i].type].supportSurfaceMerging) { - //兩個都支援界面融合(例如兩個折射鏡以一條邊相連) Both of them supports surface merging (e.g. two glasses with one common edge + // Both of them supports surface merging (e.g. two glasses with one common edge surfaceMerging_objs[surfaceMerging_objs.length] = objs[i]; } else { - //只有先射到的界面支援界面融合 Only the first shot object supports surface merging - //將擬定射到的物件設為不支援界面融合者(如折射鏡邊界與一遮光片重合,則只執行遮光片的動作) Set the object to be shot to be the one not supporting surface merging (e.g. if one surface of a glass coincides with a blocker, then only block the ray) + // Only the first shot object supports surface merging + // Set the object to be shot to be the one not supporting surface merging (e.g. if one surface of a glass coincides with a blocker, then only block the ray) s_obj = objs[i]; s_obj_index = i; s_point = s_point_temp; @@ -333,7 +333,7 @@ function shootWaitingRays() { } else if (s_lensq_temp < s_lensq && s_lensq_temp > minShotLength_squared) { - s_obj = objs[i]; //更新"到目前為止,已檢查的物件中[物件與光線的交點]離[光線的頭]最近的物件" Update the object to be shot + s_obj = objs[i]; // Update the object to be shot s_obj_index = i; s_point = s_point_temp; s_lensq = s_lensq_temp; @@ -348,25 +348,25 @@ function shootWaitingRays() { } else { ctxLight.globalAlpha = alpha0 * (waitingRays[j].brightness_s + waitingRays[j].brightness_p); } - //↓若光線沒有射到任何物件 If not shot on any object + // If not shot on any object if (s_lensq == Infinity) { if (mode == 'light' || mode == 'extended_light') { if (colorMode) { - canvasPainter.draw(waitingRays[j], color); //畫出這條光線 Draw the ray + canvasPainter.draw(waitingRays[j], color); // Draw the ray } else { - canvasPainter.draw(waitingRays[j], 'rgb(255,255,128)'); //畫出這條光線 Draw the ray + canvasPainter.draw(waitingRays[j], 'rgb(255,255,128)'); // Draw the ray } } if (mode == 'extended_light' && !waitingRays[j].isNew) { if (colorMode) { ctxLight.setLineDash([2, 2]); - canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), color); //畫出這條光的延長線 Draw the extension of the ray + canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), color); // Draw the extension of the ray ctxLight.setLineDash([]); } else { - canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), 'rgb(255,128,0)'); //畫出這條光的延長線 Draw the extension of the ray + canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), 'rgb(255,128,0)'); // Draw the extension of the ray } } @@ -384,26 +384,26 @@ function shootWaitingRays() { } else { - //此時,代表光線會在射出經過s_len(距離)後,在s_point(位置)撞到s_obj(物件) Here the ray will be shot on s_obj at s_point after traveling for s_len + // Here the ray will be shot on s_obj at s_point after traveling for s_len if (mode == 'light' || mode == 'extended_light') { if (colorMode) { - canvasPainter.draw(graphs.segment(waitingRays[j].p1, s_point), color); //畫出這條光線 Draw the ray + canvasPainter.draw(graphs.segment(waitingRays[j].p1, s_point), color); // Draw the ray } else { - canvasPainter.draw(graphs.segment(waitingRays[j].p1, s_point), 'rgb(255,255,128)'); //畫出這條光線 Draw the ray + canvasPainter.draw(graphs.segment(waitingRays[j].p1, s_point), 'rgb(255,255,128)'); // Draw the ray } } if (mode == 'extended_light' && !waitingRays[j].isNew) { if (colorMode) { ctxLight.setLineDash([2, 2]); - canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), color); //畫出這條光的延長線 Draw the backward extension of the ray + canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), color); // Draw the backward extension of the ray ctxLight.setLineDash([1, 5]); - canvasPainter.draw(graphs.ray(s_point, graphs.point(s_point.x * 2 - waitingRays[j].p1.x, s_point.y * 2 - waitingRays[j].p1.y)), color); //畫出這條光向前的延長線 Draw the forward extension of the ray + canvasPainter.draw(graphs.ray(s_point, graphs.point(s_point.x * 2 - waitingRays[j].p1.x, s_point.y * 2 - waitingRays[j].p1.y)), color); // Draw the forward extension of the ray ctxLight.setLineDash([]); } else { - canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), 'rgb(255,128,0)'); //畫出這條光的延長線 Draw the backward extension of the ray - canvasPainter.draw(graphs.ray(s_point, graphs.point(s_point.x * 2 - waitingRays[j].p1.x, s_point.y * 2 - waitingRays[j].p1.y)), 'rgb(80,80,80)'); //畫出這條光向前的延長線 Draw the forward extension of the ray + canvasPainter.draw(graphs.ray(waitingRays[j].p1, graphs.point(waitingRays[j].p1.x * 2 - waitingRays[j].p2.x, waitingRays[j].p1.y * 2 - waitingRays[j].p2.y)), 'rgb(255,128,0)'); // Draw the backward extension of the ray + canvasPainter.draw(graphs.ray(s_point, graphs.point(s_point.x * 2 - waitingRays[j].p1.x, s_point.y * 2 - waitingRays[j].p1.y)), 'rgb(80,80,80)'); // Draw the forward extension of the ray } } @@ -426,13 +426,13 @@ function shootWaitingRays() { { if (!waitingRays[j].gap) { - observed_intersection = graphs.intersection_2line(waitingRays[j], last_ray); //觀察到的光線之交點 The intersection of the observed rays + observed_intersection = graphs.intersection_2line(waitingRays[j], last_ray); // The intersection of the observed rays if (observed) { if (last_intersection && graphs.length_squared(last_intersection, observed_intersection) < 25) { - //當交點彼此相當靠近 If the intersections are near each others + // If the intersections are near each others if (graphs.intersection_is_on_ray(observed_intersection, graphs.ray(observed_point, waitingRays[j].p1)) && graphs.length_squared(observed_point, waitingRays[j].p1) > 1e-5) { @@ -452,21 +452,21 @@ function shootWaitingRays() { } if (rpd < 0) { - //虛像 Virtual image + // Virtual image if (colorMode) { ctxLight.fillStyle = color; ctxLight.fillRect(observed_intersection.x - 1.5, observed_intersection.y - 1.5, 3, 3); } else { - canvasPainter.draw(observed_intersection, 'rgb(255,128,0)'); //畫出像 Draw the image + canvasPainter.draw(observed_intersection, 'rgb(255,128,0)'); // Draw the image } } else if (rpd < s_lensq) { - //實像 Real image + // Real image if (colorMode) { - canvasPainter.draw(observed_intersection, color); //畫出像 Draw the image + canvasPainter.draw(observed_intersection, color); // Draw the image } else { - canvasPainter.draw(observed_intersection, 'rgb(255,255,128)'); //畫出像 Draw the image + canvasPainter.draw(observed_intersection, 'rgb(255,255,128)'); // Draw the image } } if (colorMode) { @@ -481,10 +481,10 @@ function shootWaitingRays() { { if (colorMode) { ctxLight.setLineDash([1, 2]); - canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), color); //畫出觀察到的光線(射線) // Draw the observed ray + canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), color); // Draw the observed ray ctxLight.setLineDash([]); } else { - canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), 'rgb(0,0,255)'); //畫出觀察到的光線(射線) // Draw the observed ray + canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), 'rgb(0,0,255)'); // Draw the observed ray } } } @@ -494,10 +494,10 @@ function shootWaitingRays() { { if (colorMode) { ctxLight.setLineDash([1, 2]); - canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), color); //畫出觀察到的光線(射線) // Draw the observed ray + canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), color); // Draw the observed ray ctxLight.setLineDash([]); } else { - canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), 'rgb(0,0,255)'); //畫出觀察到的光線(射線) // Draw the observed ray + canvasPainter.draw(graphs.ray(observed_point, waitingRays[j].p1), 'rgb(0,0,255)'); // Draw the observed ray } } } @@ -535,26 +535,26 @@ function shootWaitingRays() { if (rpd < 0) { - //虛像 Virtual image + // Virtual image if (colorMode) { ctxLight.fillStyle = color; ctxLight.fillRect(observed_intersection.x - 1.5, observed_intersection.y - 1.5, 3, 3); } else { - canvasPainter.draw(observed_intersection, 'rgb(255,128,0)'); //畫出像 Draw the image + canvasPainter.draw(observed_intersection, 'rgb(255,128,0)'); // Draw the image } } else if (rpd < s_lensq) { - //實像 Real image + // Real image if (colorMode) { - canvasPainter.draw(observed_intersection, color); //畫出像 Draw the image + canvasPainter.draw(observed_intersection, color); // Draw the image } else { - canvasPainter.draw(observed_intersection, 'rgb(255,255,128)'); //畫出像 Draw the image + canvasPainter.draw(observed_intersection, 'rgb(255,255,128)'); // Draw the image } } else { - //虛物 Virtual object + // Virtual object if (colorMode) { ctxLight.fillStyle = color; ctxLight.fillRect(observed_intersection.x - 0.5, observed_intersection.y - 0.5, 1, 1);