Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Extend the GUI with an additional function to be applied to Task 1 needle dropping: 1 . It should allow the user to select a

Extend the GUI with an additional function to be applied to Task 1 needle dropping:
1. It should allow the user to select a needle by clicking on or near it with the mouse. The needle will then be highlighted in a different colour.
2. The n needles with most similar orientation will then be highlighted in yet another colour. The default value is n =3, and the value of n can be modified through the GUI.
this the code for task 1 code:
"function [p, crossings, allLines, allvertices_counters]= BuffonStandardPiPlot(width, length, throws, floorboards)
crossings =0;
allLines = cell(throws,1); % Initialize the cell array
allvertices_counters = cell(throws,1);
for i=1:throws
vertex_counter =0;
centerX = rand()* width *floorboards;
centerY =(rand()*(width))*floorboards ;
rotationAngle = rand()*(pi/2);
% Genereating vertices of the lines
lineVertices =[centerX +(length/2)* cos(rotationAngle), centerY +(length/2)* sin(rotationAngle);
centerX -(length/2)* cos(rotationAngle), centerY -(length/2)* sin(rotationAngle); ];
allLines{i,1}= lineVertices; % Store the generated line vertices
leftside = floor(centerX/width)* width;
rightside = leftside + width;
%Check every vertex whether crossed the vertical line or not
vertex_counter = sum(lineVertices(:,1)>= rightside | lineVertices(:,1)= leftside)+ vertex_counter;
allvertices_counters{i}= vertex_counter;
crossings = crossings + sum(vertex_counter ~=0);
end
p =(2* length * throws)/(crossings * width);
disp(['Estimated p: ', num2str(p)]);
disp(['Number of needles that crossed a crack: ', num2str(crossings)])
end
"
and this is the GUI code
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions