cosmo/frontend/src/utils/scaleDistance.ts

45 lines
1.1 KiB
TypeScript

/**
* Non-linear distance scaling for better solar system visualization
* Inner solar system gets more space, outer solar system is compressed
*/
export function scaleDistance(distanceInAU: number): number {
// Inner solar system (0-2 AU): expand by 3x for better visibility
if (distanceInAU < 2) {
return distanceInAU * 3;
}
// Middle region (2-10 AU): normal scale with offset
if (distanceInAU < 10) {
return 6 + (distanceInAU - 2) * 1.5;
}
// Outer solar system (10-50 AU): compressed scale
if (distanceInAU < 50) {
return 18 + (distanceInAU - 10) * 0.5;
}
// Very far (> 50 AU): heavily compressed
return 38 + (distanceInAU - 50) * 0.2;
}
/**
* Scale a 3D position vector
*/
export function scalePosition(x: number, y: number, z: number): { x: number; y: number; z: number } {
const distance = Math.sqrt(x * x + y * y + z * z);
if (distance === 0) {
return { x: 0, y: 0, z: 0 };
}
const scaledDistance = scaleDistance(distance);
const scale = scaledDistance / distance;
return {
x: x * scale,
y: y * scale,
z: z * scale,
};
}