diff --git a/app/script/charge.ts b/app/script/charge.ts index 9868418..64dcd41 100644 --- a/app/script/charge.ts +++ b/app/script/charge.ts @@ -54,6 +54,9 @@ export abstract class Charge { /// @brief 指定座標における、この電荷からの電界ベクトルを返す abstract electricFieldVector: (position: THREE.Vector3) => THREE.Vector3; + /// @brief 電界ベクトルの描画開始座標の配列を返す + abstract electricFieldVectorBeginPositions: () => { vector: THREE.Vector3, opacity: number }[]; + /// @brief 任意の座標における電荷との距離^2を返す abstract distanceSqFrom: (position: THREE.Vector3) => number; @@ -102,6 +105,39 @@ export class PointCharge extends Charge { } + /// @brief 電界ベクトルの描画開始座標の配列を返す + override electricFieldVectorBeginPositions = () => { + const result: { vector: THREE.Vector3, opacity: number }[] = []; + + const count = 4; + + for (let x = -count; x <= count; x++) { + for (let y = -count; y <= count; y++) { + for (let z = -count; z <= count; z++) { + + const length_sq = x ** 2 + y ** 2 + z ** 2; + if (length_sq > count ** 2) { + continue; + } + + if (x === 0 && y === 0 && z === 0) { + continue; + } + + const opacity = Math.abs(1 - length_sq / (count ** 2)); + + result.push({ + vector: new THREE.Vector3(20 * x, 20 * y, 20 * z), + opacity: opacity + }); + + } + } + } + + return result; + } + /// @brief 任意の座標における電荷との距離を返す /// @param position 観測点の座標 override distanceSqFrom = (position: THREE.Vector3) => { @@ -162,6 +198,15 @@ export class LineCharge extends Charge { } + + /// @brief 電界ベクトルの描画開始座標の配列を返す + override electricFieldVectorBeginPositions = () => { + + // TODO + return new Array<{ vector: THREE.Vector3, opacity: number }>(); + + } + /// @brief 任意の座標における電荷との距離を返す /// @param position 観測点の座標 override distanceSqFrom = (position: THREE.Vector3) => { @@ -264,6 +309,39 @@ export class SphereSurfaceCharge extends Charge { } } + + /// @brief 電界ベクトルの描画開始座標の配列を返す + override electricFieldVectorBeginPositions = () => { + const result: { vector: THREE.Vector3, opacity: number }[] = []; + + const count = 4; + + for (let x = -count; x <= count; x++) { + for (let y = -count; y <= count; y++) { + for (let z = -count; z <= count; z++) { + + const length_sq = x ** 2 + y ** 2 + z ** 2; + if (length_sq > count ** 2) { + continue; + } + + if (x === 0 && y === 0 && z === 0) { + continue; + } + + const opacity = Math.abs(1 - length_sq / (count ** 2)); + + result.push({ + vector: new THREE.Vector3(20 * x, 20 * y, 20 * z), + opacity: opacity + }); + + } + } + } + + return result; + } /// @brief 任意の座標における電荷との距離を返す(外周との距離) /// @param position 観測点の座標 @@ -345,6 +423,41 @@ export class SphereVolumeCharge extends Charge } + + /// @brief 電界ベクトルの描画開始座標の配列を返す + override electricFieldVectorBeginPositions = () => { + const result: { vector: THREE.Vector3, opacity: number }[] = []; + + const count = 4; + + for (let x = -count; x <= count; x++) { + for (let y = -count; y <= count; y++) { + for (let z = -count; z <= count; z++) { + + const length_sq = x ** 2 + y ** 2 + z ** 2; + if (length_sq > count ** 2) { + continue; + } + + if (x === 0 && y === 0 && z === 0) { + continue; + } + + const opacity = Math.abs(1 - length_sq / (count ** 2)); + + result.push({ + vector: new THREE.Vector3(20 * x, 20 * y, 20 * z), + opacity: opacity + }); + + } + } + } + + return result; + } + + /// @brief 任意の座標における電荷との距離を返す(外周との距離) /// @param position 観測点の座標 override distanceSqFrom = (position: THREE.Vector3) => { diff --git a/app/script/field3d.ts b/app/script/field3d.ts index 283b2b0..2d6020a 100644 --- a/app/script/field3d.ts +++ b/app/script/field3d.ts @@ -177,31 +177,16 @@ class ElectricFieldVectors3D extends THREE.Object3D { } - const count = 4; - for (let charge of this.charges) { + for (const charge of this.charges) { if (charge.getChargeType() === ChargeType.Neutral) { continue; } - for (let x = -count; x <= count; x++) { - for (let y = -count; y <= count; y++) { - for (let z = -count; z <= count; z++) { - - const length_sq = x ** 2 + y ** 2 + z ** 2; - if (length_sq > count ** 2) { - continue; - } - - if (x === 0 && y === 0 && z === 0) { - continue; - } - - const opacity = Math.abs(1 - length_sq / (count ** 2)); - AddArrow(new THREE.Vector3(x * 20, y * 20, z * 20).add(charge.position), opacity); - - } - } + const points = charge.electricFieldVectorBeginPositions(); + for (const point of points) + { + AddArrow(point.vector.add(charge.position), point.opacity); } } diff --git a/app/script/main.ts b/app/script/main.ts index b68dd88..2c34bc3 100644 --- a/app/script/main.ts +++ b/app/script/main.ts @@ -68,9 +68,9 @@ const start = () => { lineDensity.value = lineCharge.lineDensity.toFixed(3); // 線電荷は長さを変更できる - const lineLength = document.getElementById("charge_length") as HTMLInputElement; - lineLength.labels![0]!.style.display = "block"; - lineLength.value = lineCharge.length.toFixed(3); + // const lineLength = document.getElementById("charge_length") as HTMLInputElement; + // lineLength.labels![0]!.style.display = "block"; + // lineLength.value = lineCharge.length.toFixed(3); } else if (charge instanceof SphereSurfaceCharge) { const sphereSurfaceCharge = charge as SphereSurfaceCharge; diff --git a/app/style/control.css b/app/style/control.css index ab7358c..b6a1866 100644 --- a/app/style/control.css +++ b/app/style/control.css @@ -69,7 +69,7 @@ input[type="number"] { width: 80px; text-align: right; padding-right: 10px; - font-size: 20px; + font-size: 17px; color: #e3e3e3; background-color: #38393b; border: 2px solid #4f4f4f;