I am working a program to create a Koch curve using a main() with a recursive function that outputs postscript cout statements. At time of execution, we do output redirection to a .ps file to view the curve. How do I calculate the coordinates given beginning and end points (x1,y1) & (x2,y2)? We are using c++11 so I can’t import turtle or any other graphics library, nor should I need too.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
I am working a program to create a Koch curve using a main() with a recursive function that outputs postscript cout statements. At time of execution, we do output redirection to a .ps file to view the curve. How do I calculate the coordinates given beginning and end points (x1,y1) & (x2,y2)? We are using c++11 so I can’t import turtle or any other graphics library, nor should I need too.
pe Acrobat Reader DC (64-bit)
Help
ogram3Descripti. x
3 /3
75%
left corner. A simple postscript program that draws a level 1 snowflake is (generated by koch 72
360 504 360 1):
%!PS-Adobe-2.0
72 360 moveto
144
O rlineto
72
125 rlineto
72 -125 rlineto
144
O rlineto
stroke
showpage
Statement of Work
Write a program (yes, that means an entire program, including a .cpp file with main()) to draw a
Koch curve of arbitrary level and with arbitrary starting line segment endpoints using a recursive
algorithm. Your program should take the initial line segment endpoints and the desired final level
as command line arguments. So, if your executable is named "koch" (on Linux/MacOS) or
"koch.exe" (on Windows), you would run it as:
koch x1 y1 x2 y2 level
The first four arguments are the starting line segment endpoints (#1, Y1) and (*2, Y2) in page
coordinates; the last is the curve level (>0).
Your program should send to cout a Postscript program (which is plain text) to draw the
requested curve. If you save this to a file with an extension of .ps (using output redirection, for
example with > on the command line), you can view the result on MacOS and Linux by double-
clicking on the .ps file (for Windows, you may need to download Ghostscript
(https://www.ghostscript.com/)_to preview Postscript files). You can also preview Postscript files
Tisina Gooale Drive by savina the file to Drive and then iust double-clicking there
hp
Transcribed Image Text:pe Acrobat Reader DC (64-bit) Help ogram3Descripti. x 3 /3 75% left corner. A simple postscript program that draws a level 1 snowflake is (generated by koch 72 360 504 360 1): %!PS-Adobe-2.0 72 360 moveto 144 O rlineto 72 125 rlineto 72 -125 rlineto 144 O rlineto stroke showpage Statement of Work Write a program (yes, that means an entire program, including a .cpp file with main()) to draw a Koch curve of arbitrary level and with arbitrary starting line segment endpoints using a recursive algorithm. Your program should take the initial line segment endpoints and the desired final level as command line arguments. So, if your executable is named "koch" (on Linux/MacOS) or "koch.exe" (on Windows), you would run it as: koch x1 y1 x2 y2 level The first four arguments are the starting line segment endpoints (#1, Y1) and (*2, Y2) in page coordinates; the last is the curve level (>0). Your program should send to cout a Postscript program (which is plain text) to draw the requested curve. If you save this to a file with an extension of .ps (using output redirection, for example with > on the command line), you can view the result on MacOS and Linux by double- clicking on the .ps file (for Windows, you may need to download Ghostscript (https://www.ghostscript.com/)_to preview Postscript files). You can also preview Postscript files Tisina Gooale Drive by savina the file to Drive and then iust double-clicking there hp
Expert Solution
Step 1 Code for Koch Curve in C++

Code for Koch Curve in C++

#include <bits/stdc++.h>
#include<iostream>
#include<math.h>

using namespace std;

void k_curve(long double,long double,long double,long double,int);
void line1(int,int,int,int);
int main()
{
int gd; int gm;
long double x=0;
long double y=0;
long double l=0;
long double angle=0;
int n=0;
cout<<"Starting point of the line:(x,y):"<<endl;
cout<<"_________________________________"<<endl;
cout<<"Enter the value of x="<<endl;
cin>>x;
cout<<"Enter the value of y="<<endl;
cin>>y;
cout<<"Enter the value of line:l:"<<endl;
cin>>l;
cout<<"Angle of the line with x axis:"<<endl;
cin>>angle;
cout<<"Enter the order of curve=n="<<endl;
cin>>n;
initgraph(&gd,&gm,"");
k_curve(x,y,l,angle,n);

closegraph();
return 0;
}
void k_curve(long double x,long double y,long double lenght,long double angle,int
n_order)
{ if(n_order>0)
{
lenght/=3;
k_curve(x,y,lenght,angle,(n_order-1));
x+=(lenght*cosl(angle*(M_PI/180)));
y+=(lenght*sinl(angle*(M_PI/180)));
k_curve(x,y,lenght,(angle-60),(n_order-1));
x+=(lenght*cosl((angle-60)*(M_PI/180)));
y+=(lenght*sinl((angle-60)*(M_PI/180)));
k_curve(x,y,lenght,(angle+60),(n_order-1));
x+=(lenght*cosl((angle+60)*(M_PI/180)));
y+=(lenght*sinl((angle+60)*(M_PI/180)));
k_curve(x,y,lenght,angle,(n_order-1));
}
else
line1(x,y,(int)(x+lenght*cosl(angle*(M_PI/180))+0.5),(int)(y+lenght*sinl(angle*(M_PI
/180))));
}
void line1(int x_1,int y_1, int x_2,int y_2)
{
int color=getcolor();
int x1=x_1;
int y1=y_1;
int x2=x_2;
int y2=y_2;
if(x_1>x_2)
{
x1=x_2;
y1=y_2;
x2=x_1;
y2=y_1;
}
int dx=abs(x2-x1);
int dy=abs(y2-y1);
int inc_dec=((y2>=y1)?1:-1);
if(dx>dy)
{
int two_dy=(2*dy);
int two_dy_dx=(2*(dy-dx));
int p=((2*dy)-dx);
int x=x1;
int y=y1;
putpixel(x,y,color);
while(x<x2)
{
x++;
if(p<0)
p+=two_dy;
else
{
y+=inc_dec;
p+=two_dy_dx;
}
putpixel(x,y,color);
}
}
else
{
int two_dx=(2*dx);
int two_dx_dy=(2*(dx-dy));
int p=((2*dx)-dy);
int x=x1;
int y=y1;
putpixel(x,y,color);put
while(y!=y2)
{ y+=inc_dec;
if(p<0)
p+=two_dx;
else
{x++;
p+=two_dx_dy;
}
putpixel(x,y,color);
} }}

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education