To connect the top two points of the ellipse symmetrically with mesh and add the gradation color according to the value
1 回表示 (過去 30 日間)
古いコメントを表示
clc;
clear all;
% 데이터 읽기
data = load('1.txt');
% 데이터 분리
theta_deg = data(:, 1); % 첫 번째 열: 각도 (degree)
r = data(:, 2); % 두 번째 열: 반지름
z = data(:, 3); % 세 번째 열: 높이 값
% 각도를 라디안으로 변환
theta = deg2rad(theta_deg);
% XY 평면 좌표 계산
x = r .* cos(theta); % X 좌표
y = r .* sin(theta); % Y 좌표
% 3D 타원 피팅 (가정: Z 축 대칭)
% 타원의 중심과 반경 계산
x_center = mean(x);
y_center = mean(y);
z_center = mean(z);
% 타원의 장축과 단축 (XY 평면)
a = max(r); % 장축 반경
b = min(r); % 단축 반경
% 3D 타원의 표면 좌표 생성
phi = linspace(0, 2*pi, 100); % 타원의 각도
theta_3d = linspace(0, pi, 50); % 3D 구면 각도
[Phi, Theta] = meshgrid(phi, theta_3d);
X = a * sin(Theta) .* cos(Phi); % X 좌표 (타원)
Y = b * sin(Theta) .* sin(Phi); % Y 좌표 (타원)
Z = z_center + cos(Theta); % Z 좌표 (대칭 높이)
% 타원 중심 이동
X = X + x_center;
Y = Y + y_center;
Z = Z + z_center;
% 추가 점 (x, y = 0, z = ±56060)
X_extra = [0, 0];
Y_extra = [0, 0];
Z_extra = [-56060, 56060];
% 추가 점을 포함한 플롯
figure;
surf(X, Y, Z, 'EdgeColor', 'none'); % 타원의 표면
hold on;
scatter3(X_extra, Y_extra, Z_extra, 100, 'r', 'filled'); % 추가 점 (빨간색)
colormap jet;
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Ellipse Fitting with Additional Points');
axis equal;
grid on;
% 시각적 효과
shading interp; % 부드러운 표면 렌더링
view(3); % 3D 보기
0 件のコメント
回答 (1 件)
Ruchika Parag
2024 年 11 月 28 日
Hi @daeyeong, to connect the top two points of the ellipse symmetrically with a mesh and add gradation color according to the value, you can modify your MATLAB script to include a surface patch between the additional points and the ellipse surface. Here's how you can adjust your script:
clc;
clear all;
data = load('1.txt');
theta_deg = data(:, 1);
r = data(:, 2);
z = data(:, 3);
theta = deg2rad(theta_deg);
x = r .* cos(theta);
y = r .* sin(theta);
x_center = mean(x);
y_center = mean(y);
z_center = mean(z);
a = max(r);
b = min(r);
phi = linspace(0, 2*pi, 100);
theta_3d = linspace(0, pi, 50);
[Phi, Theta] = meshgrid(phi, theta_3d);
X = a * sin(Theta) .* cos(Phi);
Y = b * sin(Theta) .* sin(Phi);
Z = z_center + cos(Theta);
X = X + x_center;
Y = Y + y_center;
Z = Z + z_center;
X_extra = [0, 0];
Y_extra = [0, 0];
Z_extra = [-56060, 56060];
figure;
surf(X, Y, Z, 'EdgeColor', 'none');
hold on;
scatter3(X_extra, Y_extra, Z_extra, 100, 'r', 'filled');
for i = 1:length(X_extra)
line([X_extra(i), x_center], [Y_extra(i), y_center], [Z_extra(i), z_center], 'Color', 'r', 'LineWidth', 2);
end
colormap jet;
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Ellipse Fitting with Additional Points');
axis equal;
grid on;
shading interp;
view(3);
The script connects additional points to the ellipse using the `line` function, creating a visual link. It applies a gradient color scheme with `colormap jet` and `colorbar` based on Z-values. The `shading interp` command ensures smooth surface rendering. This setup allows you to visualize the ellipse and additional points with a gradient effect, ensuring symmetry and clarity. Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!