필터 지우기
필터 지우기

how to generate a dome shape by using defined points

조회 수: 8 (최근 30일)
nikhil
nikhil 2020년 2월 13일
답변: BhaTTa 2024년 6월 14일
Hi all,
i am trying to generate a semi ellipsoidal dome shape by using x, y, z values and below is my code. in the code i defined the x,y,z values but i am unable to assign those values to sphere.
any suggestions and thanks in advance
clc
x = [65 55.2125 50.8267 46.7398 42.9232 39.3476 35.9815 32.7882 29.7175 26.6833 23.4690 18.7605];
y = x;
z = [0.0,0.9,2.7,5.2,8.2,11.8,15.8,20.3,25.2,30.7,37.1,47.5]; % max height of dome is 47.5
[x,y,z] = sphere(20);
x = x(12:end,:);
y = y(12:end,:);
z = z(12:end,:);
r = 65; % radius of the dome
surf(r.*x,r.*y,r.*z);
axis equal;

답변 (1개)

BhaTTa
BhaTTa 2024년 6월 14일
To generate a semi-ellipsoidal dome shape using specific x, y, and z values in MATLAB, you'll need to adjust your approach. The sphere function generates a unit sphere, and you're correctly slicing it to get a dome shape, but it seems you want to use predefined x, y, and z values to define an ellipsoidal shape instead.
Given your unique x, y, and z values, it appears you're trying to map these onto a dome shape rather than using the uniform spherical coordinates generated by sphere. To achieve a semi-ellipsoidal dome based on your description, you can use meshgrid to create a grid of x and y values and then calculate the corresponding z values based on the ellipsoidal equation.
However, if your goal is to use the specific z values you've listed with corresponding x and y values to create an ellipsoidal dome, you would typically need a function that represents the dome's shape in terms of z = f(x, y).
If you're looking to create a semi-ellipsoid with predefined dimensions (not necessarily using the x, y, z values you've listed as direct coordinates), you can use the ellipsoid formula:
[ \frac{x^2}{a^2} + \frac{y^2}{b^2} + \frac{z^2}{c^2} = 1 ]
where a, b, and c are the radii along the x, y, and z axes, respectively. For a dome, you would only plot the upper half of this ellipsoid.
Here's an example code snippet that creates a semi-ellipsoidal dome shape:
clc;
clear;
% Semi-ellipsoid dimensions
a = 65; % semi-major axis in the x-direction
b = 65; % semi-major axis in the y-direction
c = 47.5; % semi-major axis in the z-direction (height of the dome)
% Create a meshgrid for x and y
[x, y] = meshgrid(linspace(-a, a, 50), linspace(-b, b, 50));
% Calculate corresponding z values for the semi-ellipsoid
% Ensure the argument inside the sqrt is non-negative
insideSqrt = 1 - (x.^2/a^2) - (y.^2/b^2);
insideSqrt(insideSqrt < 0) = 0; % Avoid complex numbers by setting negative values to 0
z = c * sqrt(insideSqrt);
% Plot the semi-ellipsoidal dome
surf(x, y, z);
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Semi-Ellipsoidal Dome Shape');

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by