From 740b31018380575a23922f79b7c2067d72379a2c Mon Sep 17 00:00:00 2001 From: monman53 Date: Sat, 22 Jun 2024 23:17:45 +0900 Subject: [PATCH 01/53] Multiple lens mock --- src/SVG/Lens.vue | 105 +++++++++++++++++++++++++++++++++++++++++++++++ src/SVG/SVG.vue | 30 ++++++++------ src/globals.ts | 13 ++++++ src/handlers.ts | 11 +++-- 4 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 src/SVG/Lens.vue diff --git a/src/SVG/Lens.vue b/src/SVG/Lens.vue new file mode 100644 index 0000000..8ff631e --- /dev/null +++ b/src/SVG/Lens.vue @@ -0,0 +1,105 @@ + + + \ No newline at end of file diff --git a/src/SVG/SVG.vue b/src/SVG/SVG.vue index 792a76b..328707b 100644 --- a/src/SVG/SVG.vue +++ b/src/SVG/SVG.vue @@ -1,13 +1,14 @@ \ No newline at end of file diff --git a/src/SVG/SVG.vue b/src/SVG/SVG.vue index 66101a9..63a97c7 100644 --- a/src/SVG/SVG.vue +++ b/src/SVG/SVG.vue @@ -1,7 +1,7 @@ @@ -107,20 +124,20 @@ const rightX = computed(() => { - - + + - - + + - - + + + @@ -128,9 +145,9 @@ const rightX = computed(() => { - + - + @@ -139,56 +156,56 @@ const rightX = computed(() => { - + - + - - - + + - - + - - + + - - + + - + - - + + - - + + - diff --git a/src/globals.ts b/src/globals.ts index ff632f8..2605332 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -1,6 +1,6 @@ import { ref, computed } from "vue" -import { Vec, vec, calcLensR } from "./math" -import { Light } from "./type" +import { Vec, vec } from "./math" +import { type Lens, Light } from "./type" //================================ // States @@ -41,10 +41,10 @@ export const lights = ref(lights0()) // Items //-------------------------------- -export const items0 = () => { +export const items0 = (): Lens[] => { return [ - { x: -50, r: 10, f: 50, n: 1.5, d: 5, aperture: 1 }, - { x: 0, r: 10, f: 50, n: 1.5, d: 5, aperture: 1 }, + { x1: 0, x2: 6, R1: 25, R2: -50, r: 10, n: 1.5, aperture: 1 }, + { x1: -106, x2: -100, R1: 50, R2: -25, r: 10, n: 1.5, aperture: 1 }, ] } export const items = ref(items0()) @@ -207,7 +207,8 @@ export const infR = computed(() => { export const minLensX = computed(() => { let minX = infR.value for (const lens of items.value) { - minX = Math.min(minX, lens.x - lens.d / 2) + const left = Math.min(lens.x1, lens.x1) + minX = Math.min(minX, left) } return minX }) @@ -215,7 +216,7 @@ export const minLensX = computed(() => { export const maxLensX = computed(() => { let maxX = -infR.value for (const lens of items.value) { - maxX = Math.min(maxX, lens.x) + maxX = Math.min(maxX, lens.x2) } return maxX }) diff --git a/src/math.ts b/src/math.ts index e8df8ca..d7073e0 100644 --- a/src/math.ts +++ b/src/math.ts @@ -217,9 +217,11 @@ export const fGaussian = (f: number, px: number, py: number) => { return vec(qx, qy) } -export const calcLensR = (f: number, n: number, d: number) => { - const a = n - const b = -2 * f * n * (n - 1) - const c = d * f * (n - 1) * (n - 1) - return (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a) -} \ No newline at end of file +export const calcLensF = (lens: any) => { + const d = lens.x2 - lens.x1 + const R1 = lens.R1 + const R2 = lens.R2 + const n = lens.n + const inv = (n - 1) * (1 / R1 - 1 / R2) + (d / n) * ((n - 1) * (n - 1) / (R1 * R2)) + return 1 / inv +} diff --git a/src/type.ts b/src/type.ts index c130759..93c2a46 100644 --- a/src/type.ts +++ b/src/type.ts @@ -1,4 +1,15 @@ +// TODO: "Light" -> "LightType" export enum Light { Point, Parallel +} + +export type Lens = { + x1: number, + x2: number, + R1: number, + R2: number, + r: number, + n: number, + aperture: number, } \ No newline at end of file From c2fa614b89a0f470842319a4404b848974e5ddea Mon Sep 17 00:00:00 2001 From: monman53 Date: Sun, 23 Jun 2024 17:35:24 +0900 Subject: [PATCH 09/53] Lens move --- src/SVG/Lens.vue | 78 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/SVG/Lens.vue b/src/SVG/Lens.vue index 454c6da..e633f67 100644 --- a/src/SVG/Lens.vue +++ b/src/SVG/Lens.vue @@ -23,15 +23,57 @@ const xm = computed(() => { return (props.lens.x1 + props.lens.x2) / 2 }) +const fNumber = computed(() => { + if (options.value.aperture) { + return f.value / (2 * props.lens.r * props.lens.aperture) + } else { + return f.value / (2 * props.lens.r) + } +}) + +// const rMax = computed(() => { +// const d = props.lens.d +// return Math.sqrt(R.value * R.value - (R.value - d / 2) * (R.value - d / 2)) +// }) + +const r = computed(() => { + // return Math.min(rMax.value, props.lens.r) + return props.lens.r +}) + +const leftX = computed(() => { + const x = props.lens.x1 + const R1 = Math.abs(props.lens.R1) + const d = R1 - Math.sqrt(R1 * R1 - r.value * r.value) + return x + d +}) + +const rightX = computed(() => { + const x = props.lens.x2 + const R2 = Math.abs(props.lens.R2) + const d = R2 - Math.sqrt(R2 * R2 - r.value * r.value) + return x - d +}) + const moveStartHandler = (e: any) => { preventDefaultAndStopPropagation(e) const m0 = getPositionOnSvg(e); const x10 = props.lens.x1; const x20 = props.lens.x2; + const leftX0 = leftX.value + const rightX0 = rightX.value setMoveHandler((e_: any) => { const d = getPositionDiffOnSvgApp(e_, m0) - items.value[props.idx].x1 = x10 + d.x - items.value[props.idx].x2 = x20 + d.x + if (x10 + d.x < maxLightX.value) { + items.value[props.idx].x1 = maxLightX.value + items.value[props.idx].x2 = maxLightX.value + (x20 - x10) + } else if (x20 + d.x > sensor.value.x) { + items.value[props.idx].x1 = sensor.value.x - (x20 - x10) + items.value[props.idx].x2 = sensor.value.x + } else { + items.value[props.idx].x1 = x10 + d.x + items.value[props.idx].x2 = x20 + d.x + } // if (x10 + d.x < maxLightX.value + props.lens.d / 2) { // items.value[props.idx].x = maxLightX.value + props.lens.d / 2 // } else if (sensor.value.x < cx0 + d.x) { @@ -86,38 +128,6 @@ const apertureSizeChangeStartHandler = (e: any) => { }) } -const fNumber = computed(() => { - if (options.value.aperture) { - return f.value / (2 * props.lens.r * props.lens.aperture) - } else { - return f.value / (2 * props.lens.r) - } -}) - -// const rMax = computed(() => { -// const d = props.lens.d -// return Math.sqrt(R.value * R.value - (R.value - d / 2) * (R.value - d / 2)) -// }) - -const r = computed(() => { - // return Math.min(rMax.value, props.lens.r) - return props.lens.r -}) - -const leftX = computed(() => { - const x = props.lens.x1 - const R1 = Math.abs(props.lens.R1) - const d = R1 - Math.sqrt(R1 * R1 - r.value * r.value) - return x + d -}) - -const rightX = computed(() => { - const x = props.lens.x2 - const R2 = Math.abs(props.lens.R2) - const d = R2 - Math.sqrt(R2 * R2 - r.value * r.value) - return x - d -}) -