Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective is to create a sheet of hexagons that is 13 hexes horizontal by 11 hexes vertical. There are two files provided that provide the


Objective is to create a \"sheet\" of hexagons that is 13 hexes horizontal by 11 hexes vertical.


There are two files provided that provide the drawing library (Code 1), along with a sample program that draws a single hexagon (Code 2).

To compile:

g++ -std=c++11 draw_hexes.cpp hexagon.cpp -o drawsheet

To run:

./drawsheet >output.html

Openoutput.htmlin your browser to see the results.

As with the original hexagon problem, there are two goals to strive for: creating the first solution, and creating a solution that uses the fewest number of \"constructs\". Constructs are defined as:

Each function call to one of the four functions provided

Each function call to a function you have written

Each while, do-while, or for-loop

Each if-statement

Code 1:

// Hexagon.cpp // Version 2.0 #include \"hexagon.h\" #include #include #include #include #include #include #include #include //for: atexit using namespace std;

const double POINTS_PER_INCH=96.0;

struct Point { double x; double y; double inches; double deg; Point(double a, double b, double c, double in) : x(a), y(b), deg(c), inches(in){} };

const double Pi=atan(1)*4; const double DegPerRad=57.2957795;

static Point currentPoint(0.0,0.0,0.0/DegPerRad, 0.25); static std::vector v;

void moveForward(double inches) { double x,y; x=cos(currentPoint.deg)*POINTS_PER_INCH*inches; y=-sin(currentPoint.deg)*POINTS_PER_INCH*inches; v.push_back(Point(x,y,currentPoint.deg, inches)); currentPoint.x=x; currentPoint.y=y; }

void moveBackward(double inches) { double x,y; x=cos(currentPoint.deg+Pi)*POINTS_PER_INCH*inches; //Add Pi Radians to reverse direction y=-sin(currentPoint.deg+Pi)*POINTS_PER_INCH*inches; //Add Pi Radians to reverse direction v.push_back(Point(x,y,currentPoint.deg, inches)); currentPoint.x=x; currentPoint.y=y; }

void turnRightBy(double deg) { currentPoint.deg=(currentPoint.deg-deg/DegPerRad);

}

void turnLeftBy(double deg) { currentPoint.deg=((currentPoint.deg+deg/DegPerRad)); }

static double ymax=0.0;//std::numeric_limits::min(); static double ymin=0.0;//std::numeric_limits::max(); static double xmax=0.0;//std::numeric_limits::min(); static double xmin=0.0;//std::numeric_limits::max();

double _yelem_min(double d, const Point& p) { double newsum=d+p.y; ymin=(newsum return newsum; }

double _yelem_max(double d, const Point& p) { double newsum=d+p.y; ymax=(newsum > ymax) ? newsum : ymax; return newsum; }

double _xelem_min(double d, const Point& p) { double newsum=d+p.x; xmin = (newsum return newsum; }

double _xelem_max(double d, const Point& p) { double newsum=d+p.x; xmax=(newsum > xmax) ? newsum : xmax; return newsum; }

static double verticalMarginInches=0.5*POINTS_PER_INCH; static double horizontalMarginInches=0.5*POINTS_PER_INCH;

void printpage() { // A hack. Use this iterator to compute the summed minimum of each axis std::accumulate(v.begin(), v.end(), 0.0, _yelem_min); std::accumulate(v.begin(), v.end(), 0.0, _yelem_max); std::accumulate(v.begin(), v.end(), 0.0, _xelem_min); std::accumulate(v.begin(), v.end(), 0.0, _xelem_max);

double offx=0.0-xmin+horizontalMarginInches/2.0; double offy=0.0-ymin+verticalMarginInches/2.0;

cout.precision(3); cout

cout cout

\" cout

\" cout

\"

cout

cout

//starting point cout for(int j=0; j { offx+=v[j].x; offy+=v[j].y; cout } cout cout \" cout cout cout }

class Wrapper { public: Wrapper() {atexit(printpage);} }; static Wrapper w; //force the atexit function to be set up

Code 2:

// draw_hexes.cpp

#include\"hexagon.h\" int main() { for(int i=0; i6;> { moveForward(); turnRightBy(60); } return 0; }






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_2

Step: 3

blur-text-image_3

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions