I have to modify the program so that it can read 10 sample points and determine which are contained in the plume boundary. This is my first object oriented class and I have made it run ten times but I dont think that is correct. Please advise.... Thanks.

data given:

0 0 19 44
3 5 20 55
4 16 25 31
7 35 24 4
10 22 10 3

#include <iostream>
#include <cmath>
#include <fstream>

using namespace std;
const int LARGE_NUM = 1.0e10;

struct Point
{
public:
	double x, y;
};

struct Line_seg
{
public:
	Point endpt1, endpt2;
	double slope, intercept;
};

class Boundary_map
{
private:
	enum {NUM_MAP_PTS = 10};
	Point boundary_pts[NUM_MAP_PTS + 1];

public:
	Boundary_map ();
	void read_boundary_pts ();
	void map_wrap_around ();
	Point* get_boundary_pts ();
	int get_num_boundary_pts ();
};

class Probe
{
private:
	Point sample_pt, endpt1, endpt2;
	int num_crosses;
	Point probe_line_intersect (Line_seg);
	int probe_line_seg_intersect (Point, Line_seg);

public:
	Probe ();
	void read_sample_pt ();
	void check_map_boundary (Point*, int);
};

Boundary_map :: Boundary_map ()
{
	int i;
	for (i = 0; i < NUM_MAP_PTS + 1; i++)
	{
		boundary_pts[i].x = 0;
		boundary_pts[i].y = 0;
	}
}

void Boundary_map :: read_boundary_pts ()
{
	int i;
	ifstream infile ("C:\\BNDARY.DAT");

	for (i = 0; i < NUM_MAP_PTS; i++)
	{
		infile >> boundary_pts[i].x;
		infile >> boundary_pts[i].y;
	}
}

void Boundary_map :: map_wrap_around ()
{
	boundary_pts[NUM_MAP_PTS] = boundary_pts[0];
}

Point* Boundary_map :: get_boundary_pts ()
{
	return (boundary_pts);
}

int Boundary_map :: get_num_boundary_pts ()
{
	return (NUM_MAP_PTS + 1);
}

Probe :: Probe ()
{
	sample_pt.x = 0;
	sample_pt.y = 0;
	endpt1.x = 0;
	endpt1.y = 0;
	endpt2.x = LARGE_NUM;
	endpt2.y = 0;
	num_crosses = 0;
}

void Probe :: read_sample_pt ()
{
	cout << "Enter the x and y coordinates of the sample point" << endl;
	cin >> sample_pt.x >> sample_pt.y;
	endpt1 = sample_pt;
	endpt2.y = sample_pt.y;
}

Point Probe :: probe_line_intersect (Line_seg map_line_seg)
{
	Point intersect_pt;
	double probe_slope, probe_intercept;

	if (fabs (map_line_seg.endpt2.x - map_line_seg.endpt1.x) < 1.0E-20)
	{
		intersect_pt.x = map_line_seg.endpt1.x;
		intersect_pt.y = endpt1.y;
	}
	else
	{
		map_line_seg.slope = (map_line_seg.endpt2.y
			- map_line_seg.endpt1.y) / (map_line_seg.endpt2.x
			- map_line_seg.endpt1.x);

		map_line_seg.intercept = map_line_seg.endpt2.y
			- map_line_seg.slope * map_line_seg.endpt2.x;

		probe_slope = 0.0;
		probe_intercept = sample_pt.y;

		if (fabs (map_line_seg.slope) < 1.0E-20)
		{
			intersect_pt.x = LARGE_NUM;
			intersect_pt.y = LARGE_NUM;
		}

		intersect_pt.x = (probe_intercept - map_line_seg.intercept) /
			(map_line_seg.slope - probe_slope);

		intersect_pt.y = map_line_seg.slope * intersect_pt.x
			+ map_line_seg.intercept;
	}

	return (intersect_pt);
}

int Probe :: probe_line_seg_intersect (Point intersect_pt, Line_seg seg2)
{
	Line_seg seg1;
	double x_low_1, x_high_1, x_low_2, x_high_2;
	double y_low_1, y_high_1, y_low_2, y_high_2;

	seg1.endpt1 = endpt1;
	seg1.endpt2 = endpt2;

	x_low_1 = (seg1.endpt1.x < seg1.endpt2.x) ?
		seg1.endpt1.x : seg1.endpt2.x;

	x_high_1 = (seg1.endpt1.x > seg1.endpt2.x) ?
		seg1.endpt1.x : seg1.endpt2.x;

	x_low_2 = (seg2.endpt1.x < seg2.endpt2.x) ?
		seg2.endpt1.x : seg2.endpt2.x;

	x_high_2 = (seg2.endpt1.x > seg2.endpt2.x) ?
		seg2.endpt1.x : seg2.endpt2.x;

	y_low_1 = (seg1.endpt1. y < seg1.endpt2.y) ?
		seg1.endpt1.y : seg1.endpt2.y;

	y_high_1 = (seg1.endpt1. y > seg1.endpt2.y) ?
		seg1.endpt1.y : seg1.endpt2.y;

	y_low_2 = (seg2.endpt1. y < seg2.endpt2.y) ?
		seg2.endpt1.y : seg2.endpt2.y;

	y_high_2 = (seg2.endpt1. y > seg2.endpt2.y) ?
		seg2.endpt1.y : seg2.endpt2.y;

	if ((x_low_1 <= intersect_pt.x && intersect_pt.x
		<= x_high_1) && (x_low_2 <= intersect_pt.x &&
		intersect_pt.x <= x_high_2) && (y_low_1
		<= intersect_pt.y && intersect_pt.y <= y_high_1) &&
		(y_low_2 <= intersect_pt.y && intersect_pt.y
		<= y_high_2))
	{
		return (1);
	}
	else
	{
		return (0);
	}
}

void Probe :: check_map_boundary (Point* bnd_pt, int num_pts)
{
	int i, does_cross, even_odd;
	Point intersect_pt;
	Line_seg map_line_seg;

	for (i = 0; i < num_pts - 1; i++)
	{
		map_line_seg.endpt1 = bnd_pt[i];
		map_line_seg.endpt2 = bnd_pt[i + 1];

		intersect_pt = probe_line_intersect
			(map_line_seg);

		does_cross = probe_line_seg_intersect
			(intersect_pt, map_line_seg);

		num_crosses += does_cross;
	}

	even_odd = num_crosses % 2;

	if (even_odd == 0) cout << "The sample point is outside the "
		"plume." << endl;

	if (even_odd == 1) cout << "The sample point is inside the "
		"plume." << endl;
}

int main ( )
{
	Boundary_map plume_map;
	Probe probe_from_water_sample;
	int counter;
	for (counter = 1; counter <= 10; counter++)
	{
	plume_map.read_boundary_pts ();

	plume_map.map_wrap_around ();

	probe_from_water_sample.read_sample_pt ();

	probe_from_water_sample.check_map_boundary
		(plume_map.get_boundary_pts (),
		plume_map.get_num_boundary_pts ());
	}
	return 0;
}

Recommended Answers

All 4 Replies

Please explain what you mean by Tag before you post, this is my first time so I have no clue in what Im doing today.... LOL

Please explain what you mean by Tag before you post, this is my first time so I have no clue in what Im doing today.... LOL

Well, adnan.siddique tried to say that use code tags when you post code. That will preserve the code formatting making it readable. As you can see, niek_e added the code tags to your post and now it looks good.

Scroll up to your first post and click the link that reads "Help with Code Tags".

Thank you !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.