Question

In: Computer Science

I have to create a light dispersion prism animation in Matlab. I need a well-explained Matlab...

I have to create a light dispersion prism animation in Matlab. I need a well-explained Matlab script which works.

Solutions

Expert Solution

% most of the code is so complicated that its explanation needs a face to face practical explanation so I have tried my best to explain at least each line of the code

figure('position',[78 276 792 402]);  % spacing defined for the animation
xp=[-0.2,0.2,0];yp=[0.2,0.2,0.5];B=pi/14;  % values for partitioning
ZZ=[xp;yp]'*[cos(B),sin(B);-sin(B),cos(B)]; % equation for the spread of colors 
fill(ZZ(:,1),ZZ(:,2),[0.2,0.4,0.6]);  % filling the vectors
axis([-1,1,0,1]);hold on;set(gca,'color','k');  %axis defined
t=0;A=pi/8;set(gcf,'doublebuffer','on');  %time set for the various stages of animation
x=[-1,-1];y=[0,0];  
H=plot(x,y,'w','linewidth',6);  %plotting the first pic
while t<0.8;  % defining for how long
pause(0.1);  % pausing before next pic for animation effect
t=t+0.1;
% equation for 2nd pic
x(2)=-1+t*cos(A);  
y(2)=t*sin(A);  
set(H,'xdata',x,'ydata',y);  
end
% plotting various stages of the colors
x1=[x(2),x(2)];y1=[y(2),y(2)];H1=plot(x1,y1,'r');  
H2=plot(x1,y1,'color',[1,1,0]);x2=x1;y2=y1;  
H3=plot(x1,y1,'y');x3=x1;y3=y1;  
H4=plot(x1,y1,'g');x4=x1;y4=y1;  
H5=plot(x1,y1,'color',[0,1,1]);x5=x1;y5=y1;  
H6=plot(x1,y1,'b');x6=x1;y6=y1;  
H7=plot(x1,y1,'color',[1,0,1]);x7=x1;y7=y1;  
t=0;  
C=linspace(pi/16,0,7);  
s=linspace(1,1.2,7);  
while t<0.165;  
pause(0.1);  
t=t+0.01;
% for the 3rd part of the animation, equations obtained by value subs
x1(2)=x(2)+t*cos(C(1))*s(1);y1(2)=y(2)+t*sin(C(1))*s(1);  
x2(2)=x(2)+t*cos(C(2))*s(2);y2(2)=y(2)+t*sin(C(2))*s(2);  
x3(2)=x(2)+t*cos(C(3))*s(3);y3(2)=y(2)+t*sin(C(3))*s(3);  
x4(2)=x(2)+t*cos(C(4))*s(4);y4(2)=y(2)+t*sin(C(4))*s(4);  
x5(2)=x(2)+t*cos(C(5))*s(5);y5(2)=y(2)+t*sin(C(5))*s(5);  
x6(2)=x(2)+t*cos(C(6))*s(6);y6(2)=y(2)+t*sin(C(6))*s(6);  
x7(2)=x(2)+t*cos(C(7))*s(7);y7(2)=y(2)+t*sin(C(7))*s(7);  
set(H1,'xdata',x1,'ydata',y1);  
set(H2,'xdata',x2,'ydata',y2);  
set(H3,'xdata',x3,'ydata',y3);  
set(H4,'xdata',x4,'ydata',y4);  
set(H5,'xdata',x5,'ydata',y5);  
set(H6,'xdata',x6,'ydata',y6);  
set(H7,'xdata',x7,'ydata',y7);  
end  
C=linspace(0,-pi/8,7);  
x1(1)=[];y1(1)=[];  
x2(1)=[];y2(1)=[];  
x3(1)=[];y3(1)=[];  
x4(1)=[];y4(1)=[];  
x5(1)=[];y5(1)=[];  
x6(1)=[];y6(1)=[];  
x7(1)=[];y7(1)=[];  
K1=get(H1,'color');  
K2=get(H2,'color');  
K3=get(H3,'color');  
K4=get(H4,'color');  
K5=get(H5,'color');  
K6=get(H6,'color');  
K7=get(H7,'color');  
L=2:3:400;n=1;  
while t<0.5;  
pause(0.1);  
t=t+0.01;n=n+1;  
plot([x1,x1+t*cos(C(1))],[y1,y1+t*sin(C(1))],...  
'color',K1,'linewidth',L(n));  
plot([x2,x2+t*cos(C(2))],[y2,y2+t*sin(C(2))],...  
'color',K2,'linewidth',L(n));  
plot([x3,x3+t*cos(C(3))],[y3,y3+t*sin(C(3))],...  
'color',K3,'linewidth',L(n));  
plot([x4,x4+t*cos(C(4))],[y4,y4+t*sin(C(4))],...  
'color',K4,'linewidth',L(n));  
plot([x5,x5+t*cos(C(5))],[y5,y5+t*sin(C(5))],...  
'color',K5,'linewidth',L(n));  
plot([x6,x6+t*cos(C(6))],[y6,y6+t*sin(C(6))],...  
'color',K6,'linewidth',L(n));  
plot([x7,x7+t*cos(C(7))],[y7,y7+t*sin(C(7))],...  
'color',K7,'linewidth',L(n));  
x1=x1+t*cos(C(1));y1=y1+t*sin(C(1));  
x2=x2+t*cos(C(2));y2=y2+t*sin(C(2));  
x3=x3+t*cos(C(3));y3=y3+t*sin(C(3));  
x4=x4+t*cos(C(4));y4=y4+t*sin(C(4));  
x5=x5+t*cos(C(5));y5=y5+t*sin(C(5));  
x6=x6+t*cos(C(6));y6=y6+t*sin(C(6));  
x7=x7+t*cos(C(7));y7=y7+t*sin(C(7));  
end 

(Feel free to ask if you have doubt in some line of the code, it was very lengthy!)


Related Solutions

I need to create a code in C++ that first has a menu animation of game...
I need to create a code in C++ that first has a menu animation of game Pacman, a score label in the map, and a bar that have the lives of pacman in the map.
I have the answers for everything, I just need for it to be explained as to...
I have the answers for everything, I just need for it to be explained as to why that's the answer. A 24-year old female automotive technician presents herself at the doctor’s office. She complains of fever and of pain in her left hand. On physical examination, the patient had a deep wound on her left palm that was oozing pus. She had purplish, red streaks running up her left arm. She had enlarged lymph nodes at the elbow and under...
I need proper answers for the following ( well explained and understandable writing) 1) A hollow...
I need proper answers for the following ( well explained and understandable writing) 1) A hollow copper tube carries a current along its length. Why is B =0 inside the tube? Is B nonzero outside the tube? 2)  Why does hitting a magnet with a hammer cause the magnetism to be reduced
I need proper answers for the following ( well explained and understandable writing) 1. A long,...
I need proper answers for the following ( well explained and understandable writing) 1. A long, vertical, metallic wire carries downward electric current. (i) What is the direction of the magnetic field it creates at a point 2 cm horizontally east of the center of the wire? Why? (a) north (b) south (c) east (d) west (e) up 2. One pole of a magnet attracts a nail. Will the other pole of the magnet attract the nail? Explain. Also explain...
I need a proper solution for this question ( well explained and understandable writing) Charged particles...
I need a proper solution for this question ( well explained and understandable writing) Charged particles from outer space, called cosmic rays, strike the Earth more frequently near the poles than near the equator. Why?
Write a Matlab program to create specialized plot animation with 16 frames by using fast Fourier...
Write a Matlab program to create specialized plot animation with 16 frames by using fast Fourier transforms of complex matrices
ANSWER ALL QUESTIONS DON'T ANSWER IF YOU CANT ANSWER ALL I NEED THEM WELL EXPLAINED THANKS...
ANSWER ALL QUESTIONS DON'T ANSWER IF YOU CANT ANSWER ALL I NEED THEM WELL EXPLAINED THANKS Define perimenopause, surgical menopause, stress menopause, and postmenopause. What are the signs of menopause? What other life changes may influence a women's experience during menopause? Describe women at the highest risk for osteoporosis. Describe the traditional and alternative therapies for the conditions associated with menopause. Design a health, nutrition, and exercise program for middle-aged and older adults
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
I have this matlab program, and need to turn it into a C++ program. Can anyone...
I have this matlab program, and need to turn it into a C++ program. Can anyone help me with this? % Prompt the user for the values x and y x = input ('Enter the x coefficient: '); y = input ('Enter the y coefficient: '); % Calculate the function f(x,y) based upon % the signs of x and y. if x >= 0    if y >= 0        fun = x + y;    else        fun = x + y^2;    end...
I am doing a project and need an ER diagram, as well as some, create table...
I am doing a project and need an ER diagram, as well as some, create table statements in SQL. Here is what I have so far. My database will be a hospital management system. It will be able to keep track of patients and doctors, as well as each of their attributes, to better help organize the hospital's data. Each patient and doctor will be searchable via an id, and the user will be able to run reports as well....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT