- /
-
Into the Abyss - Schwarzschild Radius (a time lapse)
on 21 Oct 2024
- 13
- 255
- 0
- 4
- 1067
Cite your audio source here (if applicable): Hans Zimmer - Mountains (Interstellar (2014))
drawframe(1);
Write your drawframe function below
function drawframe(f)
%%
% Inspired and have used part of the code
% from the work and entry of Mr. Adam Danz (MathWorks).
% https://www.mathworks.com/matlabcentral/communitycontests/contests/4/entries/5071
% This script provides a basic calculation and time-lapse visualization of the
% Schwarzschild radius effect. The purpose is to illustrate the concept
% visually. If used for scientific or other applications, use at your own risk.
% A collapsed stellar object that emits no radiation is referred to as a 'Black Hole'.
% The Schwarzschild radius represents the distance between the singularity
% of a black hole and its event horizon. Thus, the event horizon is the
% theoretical boundary around a black hole where the escape velocity
% equals the speed of light. Approaching the Schwarzschild radius and
% theoretically remaining just outside of it for a few hours would
% correspond to the passage of approximately several decades on Earth
% due to relativistic time dilation.
% Black Hole Effect Parameters (constants)
G = 6.67430e-11; % Gravitational constant (m^3 kg^-1 s^-2)
M = 5.972e24; % Mass of black hole (kg, using an Earth-like mass as an example)
c = 3e8; % Speed of light (m/s)
r_s = 2 * G * M / c^2; % Schwarzschild radius (meters)
% Set up the 3D surface and camera parameters
figure;
colormap(flip(bone)); % Use colormap instead of axes parameters
hold on;
% Torus Surface with Stars
[x, y] = meshgrid(0:.03:7, 0:0.03:2*pi); % Mesh grid for torus surface
R = 9; r = 5; % Major and minor radii of the torus
X = (R + r * cos(y)) .* cos(x); % X coordinates of the torus
Y = (R + r * cos(y)) .* sin(x); % Y coordinates of the torus
Z = r * sin(y); % Z coordinates of the torus
% Plot the torus surface once
surf(X, Y, Z, 'EdgeColor', 'none');
axis equal;
% Zoom out by adjusting the camera parameters
camva(1.9); % Increase the field of view angle to zoom out
campos([0 -300 150]); % Move the camera further back to show more of the torus
% Number of stars and random placement on the torus
num_stars = 900;
n_rows = size(X, 1);
n_cols = size(X, 2);
% Precompute random indices for star placement
star_rows = randi(n_rows, num_stars, 1);
star_cols = randi(n_cols, num_stars, 1);
% Extract star positions
star_x = X(sub2ind([n_rows, n_cols], star_rows, star_cols));
star_y = Y(sub2ind([n_rows, n_cols], star_rows, star_cols));
star_z = Z(sub2ind([n_rows, n_cols], star_rows, star_cols));
% Schwarzschild radius effect: Apply a pull toward the black hole
star_dist = sqrt(star_x.^2 + star_y.^2 + star_z.^2); % Distance from center (black hole)
schwarz_effect = (r_s ./ star_dist).^2; % Effect decays with distance^2
% Apply the Schwarzschild radius effect: Pull the stars towards the center
star_x = star_x .* (1 - schwarz_effect);
star_y = star_y .* (1 - schwarz_effect);
star_z = star_z .* (1 - schwarz_effect);
% Apply slower sinusoidal motion using the input parameter f
amplitude = 0.01; % Amplitude for sinusoidal motion
frequency = 0.01 * f; % Slower frequency for star motion
star_x_moved = star_x + amplitude * sin(frequency); % Apply sinusoidal motion to X
% Plot the stars with the calculated positions
plot3(star_x_moved, star_y, star_z, 'w.', 'MarkerSize', 10);
% Overlay Schwarzschild radius as a white circle (optional visualization)
theta = linspace(0, 2*pi, 100);
plot3(r_s * cos(theta), r_s * sin(theta), zeros(size(theta)), 'w-', 'LineWidth', 2);
axis off; % Turn off the axis for a cleaner view
% Disclaimer: This calculation is provided for illustrative purposes.
% While the methodology is accurate, it is intended primarily for visualization.
% Use at your own discretion and responsibility.
end