From 9c4e87be9bcf5ebe19e61225d0f8ff63b949a3df Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 13 Jun 2025 20:59:09 +0200 Subject: [PATCH] =?UTF-8?q?Mejora=20en=20la=20normalizaci=C3=B3n=20de=20?= =?UTF-8?q?=C3=A1ngulos=20en=20la=20clase=20Aether:=20se=20implement=C3=B3?= =?UTF-8?q?=20un=20manejo=20m=C3=A1s=20robusto=20de=20los=20=C3=A1ngulos?= =?UTF-8?q?=20para=20casos=20donde=20el=20arco=20cruza=20el=20l=C3=ADmite?= =?UTF-8?q?=200/2=CF=80,=20asegurando=20un=20c=C3=A1lculo=20preciso=20de?= =?UTF-8?q?=20la=20superposici=C3=B3n=20y=20la=20distancia=20a=20los=20bor?= =?UTF-8?q?des.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Simulacion/Aether.cs | 55 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/Simulacion/Aether.cs b/Simulacion/Aether.cs index b982ecf..639fcc0 100644 --- a/Simulacion/Aether.cs +++ b/Simulacion/Aether.cs @@ -138,23 +138,58 @@ namespace CtrEditor.Simulacion Vector2 centerToBottle = bottle.Body.Position - Body.Position; // Calculate angle of bottle relative to curve center (in radians) float bottleAngle = (float)Math.Atan2(centerToBottle.Y, centerToBottle.X); - // Normalize angle to be positive - if (bottleAngle < 0) - bottleAngle += 2 * (float)Math.PI; - // If bottle is outside the angle range, return 0 - if (bottleAngle < _startAngle || bottleAngle > _endAngle) - return 0; + + // Normalize all angles to the same range [0, 2π] + float normalizedBottleAngle = bottleAngle < 0 ? bottleAngle + 2 * (float)Math.PI : bottleAngle; + float normalizedStartAngle = _startAngle < 0 ? _startAngle + 2 * (float)Math.PI : _startAngle; + float normalizedEndAngle = _endAngle < 0 ? _endAngle + 2 * (float)Math.PI : _endAngle; + + // Handle case where the arc crosses the 0/2π boundary + if (normalizedStartAngle > normalizedEndAngle) + { + // Arc crosses 0/2π boundary - check if bottle is in either part of the arc + if (!(normalizedBottleAngle >= normalizedStartAngle || normalizedBottleAngle <= normalizedEndAngle)) + return 0; + } + else + { + // Normal case - arc doesn't cross boundary + if (normalizedBottleAngle < normalizedStartAngle || normalizedBottleAngle > normalizedEndAngle) + return 0; + } // Calculate distance from center float distanceToCenter = centerToBottle.Length(); // If bottle is outside radius range, return 0 if (distanceToCenter < _innerRadius || distanceToCenter > _outerRadius) return 0; - // Calculate how far the bottle is from the edges - float angleFromStart = bottleAngle - _startAngle; - float angleToEnd = _endAngle - bottleAngle; + // Calculate how far the bottle is from the edges using normalized angles + float angleFromStart, angleToEnd, totalAngle; + + if (normalizedStartAngle > normalizedEndAngle) + { + // Arc crosses 0/2π boundary + totalAngle = (2 * (float)Math.PI - normalizedStartAngle) + normalizedEndAngle; + if (normalizedBottleAngle >= normalizedStartAngle) + { + angleFromStart = normalizedBottleAngle - normalizedStartAngle; + angleToEnd = (2 * (float)Math.PI - normalizedBottleAngle) + normalizedEndAngle; + } + else + { + angleFromStart = (2 * (float)Math.PI - normalizedStartAngle) + normalizedBottleAngle; + angleToEnd = normalizedEndAngle - normalizedBottleAngle; + } + } + else + { + // Normal case + angleFromStart = normalizedBottleAngle - normalizedStartAngle; + angleToEnd = normalizedEndAngle - normalizedBottleAngle; + totalAngle = normalizedEndAngle - normalizedStartAngle; + } + // Use the minimum distance to either edge to calculate overlap float minAngleDistance = Math.Min(angleFromStart, angleToEnd); - float totalAngle = _endAngle - _startAngle; // Calculate overlap percentage based on angle proximity to edges float overlapPercentage = Math.Min(minAngleDistance / (totalAngle * 0.1f), 1.0f); return overlapPercentage;