caoziwu преди 2 дни
родител
ревизия
c7d2747a46

+ 6 - 6
src/renderer/src/components/simulator/DiagramPanel.vue

@@ -22,12 +22,11 @@ const render = (): void => {
   if (!board || !chartDom.value) return
 
   const pal = palette.value
-  const { z, d1, d2, d3, hCov, vCov, dir, isSymmetric } = props.params
+  const { z, d1, d2, d3, hCov, vCov, dir, isSymmetric, yAxisPosition } = props.params
 
   // 根据安装方式选择对应的覆盖角
   const cov = dir === 'H' ? hCov : vCov
   const t6 = cov / 2
-
   const labels = {
     empty: t('diagram.empty'),
     horizontalDistance: t('diagram.horizontalDistance'),
@@ -56,12 +55,12 @@ const render = (): void => {
   let finalMaxZ = rawMaxZ
 
   // 如果对称,实际的 X 轴总跨度是 2 倍的 finalMaxD
-  const xSpan = isSymmetric ? 2 * finalMaxD : finalMaxD
+  const xSpan = isSymmetric || yAxisPosition == 'center' ? 2 * finalMaxD : finalMaxD
   const ySpan = finalMaxZ
 
   if (xSpan / ySpan < ratio) {
     // 宽度不够,拉宽 X 轴
-    finalMaxD = (ySpan * ratio) / (isSymmetric ? 2 : 1)
+    finalMaxD = (ySpan * ratio) / (isSymmetric || yAxisPosition == 'center' ? 2 : 1)
   } else {
     // 高度不够,拉高 Y 轴
     finalMaxZ = xSpan / ratio
@@ -70,18 +69,19 @@ const render = (): void => {
   // 4. 严格设定边界 [xMin, yMax, xMax, yMin]
   // 核心修改:如果开启对称,左边界设为 -finalMaxD * 1.05,保证 Y 轴在正中间
   const viewBox: [number, number, number, number] = [
-    isSymmetric ? -finalMaxD * 1.05 : -finalMaxD * 0.1,
+    isSymmetric || yAxisPosition == 'center' ? -finalMaxD * 1.05 : -finalMaxD * 0.1,
     finalMaxZ * 1.15,
     finalMaxD * 1.05,
     -finalMaxZ * 0.1
   ]
 
   board.setBoundingBox(viewBox, false)
+  console.log(props.params)
 
   // 5. 将修正后的最大边界和 isSymmetric 传给绘制函数
   drawDiagram(
     board,
-    { ...props.params, maxD: finalMaxD, maxZ: finalMaxZ, isSymmetric },
+    { ...props.params, maxD: finalMaxD, maxZ: finalMaxZ },
     props.result,
     labels,
     pal

+ 2 - 0
src/renderer/src/components/simulator/ParamsPanel.vue

@@ -91,6 +91,7 @@ const apply = (): void => {
     hCov: formData.hCov,
     polarPlot: device.polarPlot,
     isSymmetric: device.isSymmetric,
+    yAxisPosition: device.yAxisPosition,
     forceFullCircle: device.forceFullCircle,
     vCov: formData.vCov
   }
@@ -99,6 +100,7 @@ const apply = (): void => {
     vCov: formData.vCov,
     isSymmetric: device.isSymmetric,
     forceFullCircle: device.forceFullCircle,
+    yAxisPosition: device.yAxisPosition,
     splMax: formData.splMax
   }
 

+ 3 - 0
src/renderer/src/components/simulator/SpeakerSimulator.vue

@@ -50,6 +50,7 @@ const defaultParams: SpeakerParams = {
   polarPlot: null,
   d3: 10.39,
   isSymmetric: false,
+  yAxisPosition: 'left',
   forceFullCircle: false
 }
 
@@ -68,6 +69,7 @@ const deviceState = reactive<DevicePanelState>({
   hCov: params.hCov,
   polarPlot: params.polarPlot,
   isSymmetric: params.isSymmetric,
+  yAxisPosition: params.yAxisPosition,
   forceFullCircle: params.forceFullCircle,
   vCov: params.vCov
 })
@@ -182,6 +184,7 @@ const applySpec = (spec: DeviceSpec): void => {
   if (spec.vCov !== null) params.vCov = spec.vCov
   if (spec.splMax !== null) params.splMax = spec.splMax
   if (spec.isSymmetric !== null) params.isSymmetric = spec.isSymmetric
+  if (spec.yAxisPosition !== null) params.yAxisPosition = spec.yAxisPosition
   if (spec.forceFullCircle !== null) params.forceFullCircle = spec.forceFullCircle
   runCalc()
 }

+ 3 - 1
src/renderer/src/config/index.ts

@@ -63,7 +63,9 @@ export const devicesConfig = [
     model: 'IPS-C1',
     horizontalAngle: 60 * 2,
     verticalAngle: 60 * 2,
-    // fixedAngle: 90,
+    fixedAngle: 90,
+    // isSymmetric: true,
+    yAxisPosition: 'center',
     forceFullCircle: true,
     polarPlot: { horizontal: IPSC1, vertical: IPSC1 },
     splMax: {

+ 59 - 134
src/renderer/src/lib/speaker/jsxgraph/diagram.ts

@@ -48,13 +48,21 @@ function drawEmpty(board: Board, text: string, pal: ChartPalette): void {
 
 export function drawDiagram(
   board: Board,
-  p: SpeakerParams & { maxD?: number; maxZ?: number; isSymmetric?: boolean },
+  p: SpeakerParams & {
+    maxD?: number
+    maxZ?: number
+    isSymmetric?: boolean
+    yAxisPosition?: 'left' | 'center'
+  },
   result: CalcResult | null,
   labels: DiagramChartLabels,
   pal: ChartPalette
 ): void {
   const { z, d1, d2, d3, angle, hCov, vCov, dir } = p
-  const isSymmetric = p.isSymmetric === true
+
+  const isCenter = p.isSymmetric === true || p.yAxisPosition === 'center'
+  const showLeftSide = p.isSymmetric === true
+
   const cov = dir === 'H' ? hCov : vCov
   const t6 = cov / 2
 
@@ -71,21 +79,20 @@ export function drawDiagram(
   const upperAngle = aRad + t6Rad
   const lowerAngle = aRad - t6Rad
 
-  // 右侧边界与地面的交点
+  // 允许角度在 0~180° 之间计算交点(包含负数),并限制在屏幕宽度
   let nearX: number | null = null
-  if (upperAngle > 0.01 && upperAngle < Math.PI / 2 - 0.01) {
-    nearX = Math.min(maxD, Math.max(0, z / Math.tan(upperAngle)))
+  if (upperAngle > 0.01 && upperAngle < Math.PI - 0.01) {
+    nearX = Math.max(-maxD, Math.min(maxD, z / Math.tan(upperAngle)))
   }
 
   let farX: number | null = null
-  if (lowerAngle > 0.01 && lowerAngle < Math.PI / 2 - 0.01) {
-    farX = Math.min(maxD, z / Math.tan(lowerAngle))
+  if (lowerAngle > 0.01 && lowerAngle < Math.PI - 0.01) {
+    farX = Math.max(-maxD, Math.min(maxD, z / Math.tan(lowerAngle)))
   }
 
-  // 左侧边界与地面的交点(镜像对称)
   let leftNearX: number | null = null
   let leftFarX: number | null = null
-  if (isSymmetric) {
+  if (showLeftSide) {
     leftNearX = nearX !== null ? -nearX : null
     leftFarX = farX !== null ? -farX : null
   }
@@ -113,10 +120,9 @@ export function drawDiagram(
     const pt = (x: number, y: number) => addObj('point', [x, y], { visible: false, fixed: true })
 
     // ================= 一、网格和坐标轴 =================
-    const gD = nice(maxD / 6)
-    const gZ = nice(maxZ / 5)
+    const gD = nice(maxD / 8)
+    const gZ = nice(maxZ / 6)
 
-    // 垂向网格线
     for (let d = gD; d < maxD; d += gD) {
       addObj(
         'segment',
@@ -126,7 +132,7 @@ export function drawDiagram(
         ],
         { strokeColor: pal.border, strokeWidth: 1, dash: 2, strokeOpacity: 0.5, layer: 0 }
       )
-      if (isSymmetric) {
+      if (isCenter) {
         addObj(
           'segment',
           [
@@ -138,19 +144,17 @@ export function drawDiagram(
       }
     }
 
-    // 水平网格线
     for (let h = gZ; h < maxZ; h += gZ) {
       addObj(
         'segment',
         [
-          [isSymmetric ? -maxD : 0, h],
+          [isCenter ? -maxD : 0, h],
           [maxD, h]
         ],
         { strokeColor: pal.border, strokeWidth: 1, dash: 2, strokeOpacity: 0.5, layer: 0 }
       )
     }
 
-    // Y 轴与 X 轴
     addObj(
       'segment',
       [
@@ -162,13 +166,12 @@ export function drawDiagram(
     addObj(
       'segment',
       [
-        [isSymmetric ? -maxD : 0, 0],
+        [isCenter ? -maxD : 0, 0],
         [maxD, 0]
       ],
       { strokeColor: pal.dim, strokeWidth: 1.5, lastArrow: true, layer: 1 }
     )
 
-    // X 轴刻度和数字
     for (let d = gD; d < maxD; d += gD) {
       addObj(
         'segment',
@@ -185,7 +188,7 @@ export function drawDiagram(
         anchorY: 'top',
         layer: 1
       })
-      if (isSymmetric) {
+      if (isCenter) {
         addObj(
           'segment',
           [
@@ -204,7 +207,6 @@ export function drawDiagram(
       }
     }
 
-    // Y 轴刻度和数字
     for (let h = gZ; h < maxZ; h += gZ) {
       addObj(
         'segment',
@@ -223,7 +225,6 @@ export function drawDiagram(
       })
     }
 
-    // 轴名称
     addObj('text', [maxD, -maxZ * 0.05, labels.horizontalDistance], {
       fontSize: 10,
       color: pal.dim,
@@ -240,61 +241,31 @@ export function drawDiagram(
     })
 
     // ================= 二、覆盖区域和声学线 =================
-    // 右侧覆盖区域
+    // 【核心修复】:以 Y 轴为界,左右两侧单独绘制多边形,防止跨中轴合并变成巨型色块
     if (nearX !== null && farX !== null) {
-      const leftX = Math.min(nearX, farX)
-      const rightX = Math.max(nearX, farX)
-      addObj('polygon', [pt(0, z), pt(leftX, 0), pt(rightX, 0)], {
-        fillColor: pal.accent,
-        fillOpacity: 0.1,
-        strokeColor: 'none',
-        layer: 2
-      })
-      addObj(
-        'segment',
-        [
-          [leftX, 0],
-          [rightX, 0]
-        ],
-        {
-          strokeColor: pal.accent,
-          strokeWidth: 4,
-          strokeOpacity: 0.35,
+      const x1 = Math.min(nearX, farX)
+      const x2 = Math.max(nearX, farX)
+      if (x2 > x1 + 0.01) {
+        addObj('polygon', [pt(0, z), pt(x1, 0), pt(x2, 0)], {
+          fillColor: pal.accent,
+          fillOpacity: 0.1,
+          strokeColor: 'none',
           layer: 2
-        }
-      )
-    }
-
-    // 左侧覆盖区域(镜像)
-    if (isSymmetric && leftNearX !== null && leftFarX !== null) {
-      const leftLeftX = Math.min(leftNearX, leftFarX)
-      const leftRightX = Math.max(leftNearX, leftFarX)
-      addObj('polygon', [pt(0, z), pt(leftLeftX, 0), pt(leftRightX, 0)], {
-        fillColor: pal.accent,
-        fillOpacity: 0.1,
-        strokeColor: 'none',
-        layer: 2
-      })
-      addObj(
-        'segment',
-        [
-          [leftLeftX, 0],
-          [leftRightX, 0]
-        ],
-        {
-          strokeColor: pal.accent,
-          strokeWidth: 4,
-          strokeOpacity: 0.35,
-          layer: 2
-        }
-      )
+        })
+        addObj(
+          'segment',
+          [
+            [x1, 0],
+            [x2, 0]
+          ],
+          { strokeColor: pal.accent, strokeWidth: 4, strokeOpacity: 0.35, layer: 2 }
+        )
+      }
     }
-
-    // 辅助函数:计算超出屏幕时的射线端点
     const boundaryPoint = (boundaryAngle: number): [number, number] | null => {
       const dx = Math.cos(boundaryAngle)
       const dy = -Math.sin(boundaryAngle)
-      const minX = isSymmetric ? -maxD : -maxD * 0.1 // 对称时左侧边界放宽
+      const minX = isCenter ? -maxD : -maxD * 0.1
       let distance = Number.POSITIVE_INFINITY
 
       if (dx > 0.01) distance = Math.min(distance, maxD / dx)
@@ -319,17 +290,14 @@ export function drawDiagram(
       })
     }
 
-    // 右侧边界
     drawBoundary(farX, lowerAngle)
     drawBoundary(nearX, upperAngle)
 
-    // 左侧边界(镜像角度)
-    if (isSymmetric) {
+    if (showLeftSide) {
       drawBoundary(leftFarX, Math.PI - lowerAngle)
       drawBoundary(leftNearX, Math.PI - upperAngle)
     }
 
-    // 轴心线 D3
     const d3Clamped = Math.min(maxD, d3)
     addObj(
       'segment',
@@ -337,26 +305,16 @@ export function drawDiagram(
         [0, z],
         [d3Clamped, 0]
       ],
-      {
-        strokeColor: pal.accent,
-        strokeWidth: 1.5,
-        dash: 2,
-        layer: 3
-      }
+      { strokeColor: pal.accent, strokeWidth: 1.5, dash: 2, layer: 3 }
     )
-    if (isSymmetric) {
+    if (showLeftSide) {
       addObj(
         'segment',
         [
           [0, z],
           [-d3Clamped, 0]
         ],
-        {
-          strokeColor: pal.accent,
-          strokeWidth: 1.5,
-          dash: 2,
-          layer: 3
-        }
+        { strokeColor: pal.accent, strokeWidth: 1.5, dash: 2, layer: 3 }
       )
     }
 
@@ -416,7 +374,6 @@ export function drawDiagram(
       const isNearRightEdge = x > maxD * 0.85
       const anchorX = isNearRightEdge ? 'right' : 'center'
 
-      // 右侧点标签
       addObj('text', [x, textY, `${ptDef.lbl} = ${x.toFixed(1)}m`], {
         fontSize: 10,
         color: ptDef.c,
@@ -432,8 +389,7 @@ export function drawDiagram(
         layer: 4
       })
 
-      // 左侧点标签(开启对称时)
-      if (isSymmetric) {
+      if (showLeftSide) {
         addObj('point', [-x, 0], {
           size: 4,
           fillColor: ptDef.c,
@@ -441,17 +397,18 @@ export function drawDiagram(
           strokeWidth: 1,
           layer: 4
         })
+        const anchorXLeft = -x < -maxD * 0.85 ? 'left' : 'center'
         addObj('text', [-x, textY, `${ptDef.lbl} = ${x.toFixed(1)}m`], {
           fontSize: 10,
           color: ptDef.c,
-          anchorX: 'center',
+          anchorX: anchorXLeft,
           anchorY: 'bottom',
           layer: 4
         })
         addObj('text', [-x, textY + maxZ * 0.1, `${spl.toFixed(1)} dB`], {
           fontSize: 10,
           color: ptDef.c,
-          anchorX: 'center',
+          anchorX: anchorXLeft,
           anchorY: 'top',
           layer: 4
         })
@@ -459,8 +416,6 @@ export function drawDiagram(
     })
 
     // ================= 四、弧线与角度 =================
-
-    // 1. 水平基准虚线
     const baseRefLineLength = maxD * 0.18
     addObj(
       'segment',
@@ -468,35 +423,22 @@ export function drawDiagram(
         [0, z],
         [baseRefLineLength, z]
       ],
-      {
-        strokeColor: pal.dim,
-        strokeWidth: 1,
-        dash: 2,
-        strokeOpacity: 0.8,
-        layer: 3
-      }
+      { strokeColor: pal.dim, strokeWidth: 1, dash: 2, strokeOpacity: 0.8, layer: 3 }
     )
-    if (isSymmetric) {
+    if (showLeftSide) {
       addObj(
         'segment',
         [
           [0, z],
           [-baseRefLineLength, z]
         ],
-        {
-          strokeColor: pal.dim,
-          strokeWidth: 1,
-          dash: 2,
-          strokeOpacity: 0.8,
-          layer: 3
-        }
+        { strokeColor: pal.dim, strokeWidth: 1, dash: 2, strokeOpacity: 0.8, layer: 3 }
       )
     }
 
-    // 2. 覆盖角 V 的圆弧(外圈)
+    // 覆盖角 V 的圆弧(外圈)
     if (upperAngle > 0.01) {
       const vRadius = Math.min(maxZ * 0.15, z * 0.5)
-      // 右侧圆弧
       addObj(
         'curve',
         [
@@ -508,8 +450,7 @@ export function drawDiagram(
         { strokeColor: '#eab308', strokeWidth: 2, layer: 4 }
       )
 
-      // 左侧镜像圆弧
-      if (isSymmetric) {
+      if (showLeftSide && Math.abs(angle - 90) > 0.01) {
         addObj(
           'curve',
           [
@@ -531,18 +472,16 @@ export function drawDiagram(
       })
     }
 
-    // 3. 安装倾斜角 A 的圆弧(内圈)
+    // 安装倾斜角 A 的圆弧(内圈)
     if (angle > 0.01) {
       const aRadius = maxZ * 0.16
-      // 右侧圆弧
       addObj(
         'curve',
         [(t: number) => Math.cos(t) * aRadius, (t: number) => z - Math.sin(t) * aRadius, 0, aRad],
         { strokeColor: pal.text, strokeWidth: 1.5, strokeOpacity: 0.9, layer: 4 }
       )
 
-      // 左侧镜像圆弧
-      if (isSymmetric) {
+      if (showLeftSide) {
         addObj(
           'curve',
           [
@@ -555,34 +494,20 @@ export function drawDiagram(
         )
       }
 
-      // 右侧标签
       const midA = aRad / 2
       const aLblR = aRadius + maxZ * 0.04
       addObj(
         'text',
         [Math.cos(midA) * aLblR, z - Math.sin(midA) * aLblR, `A = ${angle.toFixed(1)}°`],
-        {
-          fontSize: 11,
-          color: pal.text,
-          anchorX: 'left',
-          anchorY: 'bottom',
-          layer: 10
-        }
+        { fontSize: 11, color: pal.text, anchorX: 'left', anchorY: 'bottom', layer: 10 }
       )
 
-      // 左侧标签
-      if (isSymmetric) {
+      if (showLeftSide) {
         const midALeft = Math.PI - aRad / 2
         addObj(
           'text',
           [Math.cos(midALeft) * aLblR, z - Math.sin(midALeft) * aLblR, `A = ${angle.toFixed(1)}°`],
-          {
-            fontSize: 11,
-            color: pal.text,
-            anchorX: 'right',
-            anchorY: 'bottom',
-            layer: 10
-          }
+          { fontSize: 11, color: pal.text, anchorX: 'right', anchorY: 'bottom', layer: 10 }
         )
       }
     }

+ 3 - 0
src/renderer/src/lib/speaker/types.ts

@@ -46,6 +46,7 @@ export interface SpeakerParams {
   /** 计算结果 */
   result?: CalcResult
   isSymmetric?: boolean
+  yAxisPosition: 'left' | 'center'
   forceFullCircle?: boolean
 }
 
@@ -94,6 +95,7 @@ export interface DeviceSpec {
   /** 最大声压级 dB SPL */
   splMax: number | null
   isSymmetric?: boolean | null
+  yAxisPosition: 'left' | 'center'
   forceFullCircle?: boolean | null
 }
 
@@ -118,5 +120,6 @@ export interface DevicePanelState {
   vCov: number | null
   polarPlot: any
   isSymmetric?: boolean
+  yAxisPosition: 'left' | 'center'
   forceFullCircle: boolean | null
 }