Question
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, determine if a given point on a 2D plane is within the parameters of a pre-defined triangle on the 2D plane. Think of the 2D plane as an image. Write the algorithm (triCheckPoint listed above) 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.
Point.cpp
1. Implement the triCheckPoint function. Implement the Barycentric Coordinate System in this function (see above). 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.
driver.cpp
// Most of the driver code is provided, however, there are several lines of code to complete. //
#include
#include
#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
{
for(w = 0; 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;
}
TESTING
Compile: g++ driver.cpp Point.cpp o driver std=c++11 Wall
Run: ./driver out.ppm
This should print an image similar to the following:
The triangle will be defined by you. If you choose to change the colors that will be fine as well.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started