caoziwu 1 долоо хоног өмнө
parent
commit
3d6e4949ca

+ 53 - 23
src/renderer/src/lib/speaker/jsxgraph/diagram.ts

@@ -70,11 +70,29 @@ export function drawDiagram(
   const upperAngle = aRad + t6Rad
   const lowerAngle = aRad - t6Rad
 
-  const dFar = upperAngle < Math.PI / 2 - 0.01 ? z / Math.tan(upperAngle) : maxD * 3
-  const dNear = lowerAngle > 0.01 ? z / Math.tan(lowerAngle) : -1
+  // 覆盖角边界与前方地面(x > 0)的交点:
+  // - 较小的边界角(越接近水平 0°)-> 交点越远(dFar / 远点)
+  // - 较大的边界角(越接近垂直 90°)-> 交点越近(dNear / 近点)
+  // 当边界角 <= 0°(水平或向上):不与前方地面相交,远点视为无穷远(截断到 maxD)
+  // 当边界角 >= 90°(垂直或向上):交点在 x = 0(扬声器正下方)
+
+  // 近点:较大边界角 upperAngle 决定(越垂直越近)
+  // upperAngle >= 90°:垂直向下,交点在 x = 0(扬声器正下方)
+  // 0° < upperAngle < 90°:正常计算 z / tan(upperAngle)
+  // upperAngle <= 0°:不与前方地面交,nearX 为 null
+  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)))
+  }
 
-  const nearX = dNear >= 0 ? Math.min(maxD, Math.max(0, dNear)) : null
-  const farX = dFar > 0 ? Math.min(maxD, dFar) : null
+  // 远点:较小边界角 lowerAngle 决定(越水平越远)
+  // 0° < lowerAngle < 90°:正常计算 z / tan(lowerAngle)
+  // lowerAngle <= 0°:下边界向上或水平,无前方交点,farX 为 null(不画虚线)
+  // lowerAngle >= 90°:垂直向上,farX 为 null
+  let farX: number | null = null
+  if (lowerAngle > 0.01 && lowerAngle < Math.PI / 2 - 0.01) {
+    farX = Math.min(maxD, z / Math.tan(lowerAngle))
+  }
 
   board.suspendUpdate()
   try {
@@ -199,6 +217,7 @@ export function drawDiagram(
     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,
@@ -218,27 +237,37 @@ export function drawDiagram(
       )
     }
 
-    if (farX !== null) {
-      addObj(
-        'segment',
-        [
-          [0, z],
-          [farX, 0]
-        ],
-        { strokeColor: pal.accent, strokeWidth: 1.2, dash: 2, strokeOpacity: 0.6, layer: 3 }
-      )
+    const boundaryPoint = (boundaryAngle: number): [number, number] | null => {
+      const dx = Math.cos(boundaryAngle)
+      const dy = -Math.sin(boundaryAngle)
+      const minX = -maxD * 0.1
+      let distance = Number.POSITIVE_INFINITY
+
+      if (dx > 0.01) distance = Math.min(distance, maxD / dx)
+      else if (dx < -0.01) distance = Math.min(distance, minX / dx)
+
+      if (dy > 0.01) distance = Math.min(distance, (maxZ - z) / dy)
+      else if (dy < -0.01) distance = Math.min(distance, -z / dy)
+
+      if (!Number.isFinite(distance) || distance <= 0) return null
+      return [dx * distance, z + dy * distance]
     }
-    if (nearX !== null) {
-      addObj(
-        'segment',
-        [
-          [0, z],
-          [nearX, 0]
-        ],
-        { strokeColor: pal.accent, strokeWidth: 1.2, dash: 2, strokeOpacity: 0.6, layer: 3 }
-      )
+
+    const drawBoundary = (x: number | null, boundaryAngle: number) => {
+      const end = x === null ? boundaryPoint(boundaryAngle) : [x, 0]
+      if (!end) return
+      addObj('segment', [[0, z], end], {
+        strokeColor: pal.accent,
+        strokeWidth: 1.2,
+        dash: 2,
+        strokeOpacity: 0.6,
+        layer: 3
+      })
     }
 
+    drawBoundary(farX, lowerAngle)
+    drawBoundary(nearX, upperAngle)
+
     const d3Clamped = Math.min(maxD, d3)
     addObj(
       'segment',
@@ -348,7 +377,8 @@ export function drawDiagram(
     )
 
     // 2. 覆盖角 V 的圆弧(外圈)
-    if (dFar > 0.01) {
+    // 上边界角度 > 0°(有向下分量)时,覆盖角扇面与前方地面有交集,绘制外圈弧线
+    if (upperAngle > 0.01) {
       // 半径与 maxZ 挂钩,确保在不同拉伸比例下都足够清晰
       const vRadius = maxZ * 0.3
       addObj(

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
tsconfig.web.tsbuildinfo


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно