Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a simple C++ class called Point. The point class will have two data members, a double x and y. Provide a default constructor, regular

Create a simple C++ class called Point. The point class will have two data members, a double x and y. Provide a default constructor, regular constructor, setters, and getters. In addition to the class functions, create a function called triCheckPoint. The function is not part of the Point class but uses instances of the class.

The prototype of triCheckPoint is: int triCheckPoint(Point, Point, Point, Point);

Using this, write the algorithm (triCheckPoint) to determine if a given point is within the parameters of the triangle. Three files will be used for this.

****************************************************************************

Point.h

The point class will provide the following:

1. The class definition for the point class.

2. Define a function prototype for triCheckPoint described above. Not part of the class.

#include Point.h #define Point.h"

class Point;

private: double x, y; public: Point(); Point(double x, double y);

~point();

void setX(double x); void setY(double y);

double getX(); double getY();

};

void hitcheckpoint(Point a, Point b, Point c);pointP

********************************************************************

Point.cpp

1. Implement the triCheckPoint function. Implement the Barycentric Coordinate System in this function. This function has four parameters:

a. Four Points - one for each point of a triangle. One that represents the point being tested.

2. The return value will be 1 or 0.

a. Return 1 if the point being tested is within the boundaries of the triangle.

b. Return 0 if the point being tested is not within the boundaries of the triangle

3. Implement the Point Class.

#include Point.h

void Point::setX(double x) { x = x; }

Point:: Point() { x = 0; y = 0; }

Point::Point(double x, double y) { this-> = x; }

*********************************************************************

driver.cpp

// Most of the driver code is provided, however, there are several lines of code to complete. //

#include "Point.h"

using namespace std;

int main(int argc, char* argv[])

{

/*Create an output file pointer. The name of the file name will be provided on the command line.

*Check to make sure the file opened successfully*/

//FILL IN CODE HERE

/*Use the output pointer to write out the PPM header information.

*This should be a P6 image width = 500 and height = 500 */

//FILL IN CODE HERE

/*Create three instances of the Point class and define the three

*points (your choice of point value)*/

//FILL IN CODE HERE

/*test is used to test each pixel of the image. Remember you are

*trying to determine if test (which is a point) is within the three points *of the triangle*/

Point test;

int w = 0;

int h = 0;

int hit = 0;

for(h = 0; h < 500; h++)

{

for(w = 0; w < 500; w++)

{

/*Set the X and Y values to the test Point*/

//FILL IN CODE HERE

hit = triCheckPoint(p1, p2, p3, test);

if (hit == 1)

{

unsigned char r = 82;

unsigned char g = 45;

unsigned char b = 128;

/*Write the code to output r, g, and b*/

//FILL IN CODE HERE

}

else

{

unsigned char r = 246;

unsigned char g = 102;

unsigned char b = 51;

/*Write the code to output r, g, and b*/

//FILL IN CODE HERE

}

}

}

/*close the file pointer */

//FILL IN CODE HERE

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

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 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions