Azzera filtri
Azzera filtri

Generate a triangle from a set of specified set variables.

3 visualizzazioni (ultimi 30 giorni)
I need to generate a triangle that will be able to be user controlled with input length of base in pixels and both base angles in degrees.
subplot(2,4,3);
sides = 3;
t = (1/(2*sides):1/(sides):1)*2*pi-pi/3;
x_size=100;
x = x_size*sin(t);
y = x_size*cos(t);
fill(x,y,'black');
axis square;
this is the code I used.

Risposta accettata

Image Analyst
Image Analyst il 10 Mag 2015
See this snippet. Adapt as you see fit:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '18.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter Angle 1 : ', 'Enter Angle 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check for a valid number.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end

Più risposte (1)

Image Analyst
Image Analyst il 10 Mag 2015
Why don't you have a user interface where you let the user control the width with a slider? See this framework. http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component Put your code in the slider callback. First get the slider value, then use it in the rest of your code that draws the triangle.
  1 Commento
Yashlin Naidoo
Yashlin Naidoo il 10 Mag 2015
Since the representation doesn't require that.I just need a code that can be user controlled to input base and two base angles to generate the triangle thats it

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by