creating a 3d object based off of a information gathered from user input 3d graph

2 次查看(过去 30 天)
I'm trying to create a 3d object based off of information gathered from a previous user input 3d graph. here is what i have so far.
sidelength = input('Enter Sidelength');
height = input('Enter Height');
V=nsidedpoly(10,'Side',sidelength).Vertices;
V(end+1,3)=-height;
trisurf( delaunay(V(:,1:2)), V(:,1), V(:,2), V(:,3),'FaceColor','c')
%% calculating angle for new shape based off sidelength and height input
x6 = (sidelength*3.078)/2;
angle1 = atand(height/x6);
angle2 = 90-angle1
The thickness of this object isn't very important, and it doesn't need to have a fixed height either. The object just needs to fit flush at the base of the decagon angle (150degrees) and follow slant of the user input pyramid (angle2). I added an image to help illustrate what i mean. I don't quite know if this is possible to do, any help would be greatly appreciated.
  1 个评论
Matthew
Matthew 2023-10-23
i've added
L = sidelength/2 %
a = (3.236*sidelength)/2 % this would be the 2d angle orgin for this new shape.
I'm still trying to figure out how to get this line to extend L from a at 150degrees.
the next step i believe would be turning this new 150 deree line into a plane that follows angle2 towards the vertex of the pyramid.

请先登录,再进行评论。

回答(1 个)

Yatharth
Yatharth 2023-12-1
Hi Matthew,
I understand that you want to create a 3D figure based on user's input.
You can represent the base decagon and the new shape in a 3D space to create a 3D plot for the provided scenario. Here's how you can adjust the current code to accomplish this.
% User input for side length and height
sidelength = input('Enter Sidelength: ');
height = input('Enter Height: ');
% Create the base decagon
V = nsidedpoly(10, 'Side', sidelength).Vertices;
V(end+1, 3) = -height; % Set the z-coordinate to -height for the base vertices
% Plot the base decagon
trisurf(delaunay(V(:,1), V(:,2)), V(:,1), V(:,2), V(:,3), 'FaceColor', 'c');
hold on; % Hold the plot so we can add the new shape
% Calculating angle for new shape based off sidelength and height input
x6 = (sidelength * 3.078) / 2;
angle1 = atand(height / x6);
angle2 = 90 - angle1;
% Define the new shape based on the calculated angles
% Example: creating a new triangular shape based on the calculated angles
% Define the vertices of the new shape
new_shape_vertices = [0, 0, 0; sidelength, 0, 0; sidelength / 2, 0, tand(angle2) * sidelength / 2];
% Plot the new shape
fill3(new_shape_vertices(:,1), new_shape_vertices(:,2), new_shape_vertices(:,3), 'r');
% Additional adjustments and annotations can be added here
hold off; % Release the hold on the plot
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3D Object with New Shape');
In this modified code, the 'trisurf' function is used to plot the base decagon, and the 'fill3' function is used to plot the new shape. This will create a 3D plot showing the base decagon and the new shape in a 3D space.
You can read more about 'fill3' here. https://www.mathworks.com/help/matlab/ref/fill3.html
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Computational Geometry 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by