database

[수학과 교육] 홀로그램 제작 옥타브 코드

작성자
cfdkim
작성일
2023-05-23 00:42
조회
155
clear; % 작업창 초기화

%%%%%%%%%%%%% <theta만큼 그림을 돌려주는 함수> %%%%%%%%%%%%%

function [rotx,roty]=rotation(x,y,theta)

A=[cos(theta),-sin(theta);

sin(theta),cos(theta)];

rot=A*[x;y];

rotx=rot(1,:);

roty=rot(2,:);

end

%%%%%% < 각 theta에 대하여 대변이 2a인 사각뿔 전개도 그리기> %%%%%%%

a=0.5; % 작은 사각뿔 밑변의 길이의 반

ax=sqrt(3)*a; ay=0; % 밑변의 길이가 2a인 이등변 삼각형의 등변 정의

axx=[ax]; ayy=[ay];

figure(1); clf; hold on;

plot([0,ax],[0,ay],'k-');

for i=1:4 % theta만큼 돌려주면서 등변 그리기

[nax,nay]=rotation(ax,ay,2*i*atan(1/sqrt(2)));

plot([0,nax],[0,nay],'k-');

axx=[axx,nax];

ayy=[ayy,nay];

end

plot(axx,ayy,'k-') % 이등변 삼각형의 밑변 그리기

axis image

axis off

%%%%%% < 각 theta에 대하여 대변이 2b인 사각뿔 전개도 그리기> %%%%%%%

b=3.5; % 큰 사각뿔 밑변의 길이의 반

bx=sqrt(3)*b; by=0; % 밑변의 길이가 2b인 이등변 삼각형의 등변 정의

bxx=[bx]; byy=[by];

paper_w=21; % 필름의 크기 지정 (너비)

paper_h=29.7; % 필름의 크기 지정 (높이)

f2=figure(2); clf;

ax=axes(f2,'Units','centimeters','Position',[0,0,paper_w,paper_h]);

set(f2,'Units','centimeters','Position',[0,2,paper_w,paper_h]);

hold on;

plot(axx,ayy,'k-')

plot([axx(1),bx],[ayy(1),by],'k-');

for i=1:4 % theta만큼 돌려주면서 등변 그리기

[nbx,nby]=rotation(bx,by,2*i*atan(1/sqrt(2)));

plot([axx(i+1),nbx],[ayy(i+1),nby],'k-');

bxx=[bxx,nbx];

byy=[byy,nby];

end

plot(bxx,byy,'k-') % 이등변 삼각형의 밑변 그리기

axis image

axis([-paper_w/2,paper_w/2,-2*b,paper_h-2*b])

axis off
전체 0