hi, if anyone can help me how to compile two .cs file? this program i refer to other programmer attachment. i really need help. thank you
Form2.cs
and another file
ConvexHull.cs
Form2.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace image
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
string[] s2=new string[] {"32.547",
"32.546",
"32.547",
"32.549",
"32.546",
"32.547",
"32.544",
"32.546",
"32.548",
"32.549",
"32.546",
"32.547",
"32.548",
"32.548",
"32.548",
"32.543",
"32.547",
"32.546",
"32.546",
"32.545",
"32.544"};
string[] s1 = new string[]{"-117.053",
"-117.052",
"-117.052",
"-117.052",
"-117.051",
"-117.051",
"-117.05",
"-117.049",
"-117.045",
"-117.045",
"-117.042",
"-117.042",
"-117.042",
"-117.037",
"-117.036",
"-117.034",
"-117.033",
"-117.032",
"-117.031",
"-117.03",
"-117.029",
};
Point[] pts = new Point[s1.Length];
for (int i = 0; i < s1.Length; i++)
{
pts[i] = new Point(Convert.ToDouble(s1[i]), Convert.ToDouble(s2[i]));
}
Point[] chpts = Convexhull.convexhull(pts);
// Console.WriteLine("Area is " + area(chpts));
System.IO.StreamWriter sr = new System.IO.StreamWriter(@"D:/tt.txt");
string str = "";
for (int i = 0; i < chpts.Length; i++)
{
sr.WriteLine(chpts[i].ToString());
}
sr.Close();
}
}
}
ConvexHull.cs
Code:
using System;
using System.Drawing.Imaging;
using System.Drawing;
namespace image
{
// ------------------------------------------------------------
// This implementation correctly handles duplicate points, and
// multiple points with the same x-coordinate.
// 1. Sort the points lexicographically by increasing (x,y), thus
// finding also a leftmost point L and a rightmost point R.
// 2. Partition the point set into two lists, upper and lower, according as
// point is above or below the segment LR. The upper list begins with
// L and ends with R; the lower list begins with R and ends with L.
// 3. Traverse the point lists clockwise, eliminating all but the extreme
// points (thus eliminating also duplicate points).
// 4. Eliminate L from lower and R from upper, if necessary.
// 5. Join the point lists (in clockwise order) in an array.
class Convexhull {
public static Point[] convexhull(Point[] pts) {
// Sort points lexicographically by increasing (x, y)
int N = pts.Length;
if (N<=1)
return pts;
Polysort.Quicksort(pts);
Point left = pts[0];
Point right = pts[N-1];
// Partition into lower hull and upper hull
CDLL lower = new CDLL(left), upper = new CDLL(left);
for (int i=0; i<N; i++) {
double det = Point.Area2(left, right, pts[i]);
if (det > 0)
upper = upper.Append(new CDLL(pts[i]));
else if (det < 0)
lower = lower.Prepend(new CDLL(pts[i]));
}
lower = lower.Prepend(new CDLL(right));
upper = upper.Append(new CDLL(right)).Next;
// Eliminate points not on the hull
eliminate(lower);
eliminate(upper);
// Eliminate duplicate endpoints
if (lower.Prev.val.Equals(upper.val))
lower.Prev.Delete();
if (upper.Prev.val.Equals(lower.val))
upper.Prev.Delete();
// Join the lower and upper hull
Point[] res = new Point[lower.Size() + upper.Size()];
lower.CopyInto(res, 0);
upper.CopyInto(res, lower.Size());
return res;
}
// Graham's scan
private static void eliminate(CDLL start) {
CDLL v = start, w = start.Prev;
bool fwd = false;
while (v.Next != start || !fwd) {
if (v.Next == w)
fwd = true;
if (Point.Area2(v.val, v.Next.val, v.Next.Next.val) < 0) // right turn
v = v.Next;
else { // left turn or straight
v.Next.Delete();
v = v.Prev;
}
}
}
}
// ------------------------------------------------------------
// Points in the plane
public class Point : Ordered {
private static readonly Random rnd = new Random();
private double x, y;
public int X
{
get
{
return (int)x;
}
set
{
x=(double)value;
}
}
public int Y
{
get
{
return (int)y;
}
set
{
y=(double)value;
}
}
public Point(double x, double y) {
this.x = x; this.y = y;
}
public override string ToString() {
return "(" + x + ", " + y + ")";
}
public static Point Random(int w, int h) {
return new Point(rnd.Next(w), rnd.Next(h));
}
public bool Equals(Point p2) {
return x == p2.x && y == p2.y;
}
public override bool Less(Ordered o2) {
Point p2 = (Point)o2;
return x < p2.x || x == p2.x && y < p2.y;
}
// Twice the signed area of the triangle (p0, p1, p2)
public static double Area2(Point p0, Point p1, Point p2) {
return p0.x * (p1.y-p2.y) + p1.x * (p2.y-p0.y) + p2.x * (p0.y-p1.y);
}
}
// ------------------------------------------------------------
// Circular doubly linked lists of Point
class CDLL {
private CDLL prev, next; // not null, except in deleted elements
public Point val;
// A new CDLL node is a one-element circular list
public CDLL(Point val) {
this.val = val; next = prev = this;
}
public CDLL Prev {
get { return prev; }
}
public CDLL Next {
get { return next; }
}
// Delete: adjust the remaining elements, make this one point nowhere
public void Delete() {
next.prev = prev; prev.next = next;
next = prev = null;
}
public CDLL Prepend(CDLL elt) {
elt.next = this; elt.prev = prev; prev.next = elt; prev = elt;
return elt;
}
public CDLL Append(CDLL elt) {
elt.prev = this; elt.next = next; next.prev = elt; next = elt;
return elt;
}
public int Size() {
int count = 0;
CDLL node = this;
do {
count++;
node = node.next;
} while (node != this);
return count;
}
public void PrintFwd() {
CDLL node = this;
do {
Console.WriteLine(node.val);
node = node.next;
} while (node != this);
Console.WriteLine();
}
public void CopyInto(Point[] vals, int i) {
CDLL node = this;
do {
vals[i++] = node.val; // still, implicit checkcasts at runtime
node = node.next;
} while (node != this);
}
}
// ------------------------------------------------------------
class Polysort {
private static void swap(Point[] arr, int s, int t) {
Point tmp = arr[s]; arr[s] = arr[t]; arr[t] = tmp;
}
private static void swap(Ordered[] arr, int s, int t) {
Ordered tmp = arr[s]; arr[s] = arr[t]; arr[t] = tmp;
}
// Typed OO-style quicksort a la Hoare/Wirth
private static void qsort(Ordered[] arr, int a, int b) {
// sort arr[a..b]
if (a < b) {
int i = a, j = b;
Point x = (Point)(arr[(i+j) / 2]);
do {
while (arr[i].Less(x)) i++;
while (x.Less(arr[j])) j--;
if (i <= j) {
swap(arr, i, j);
i++; j--;
}
} while (i <= j);
qsort(arr, a, j);
qsort(arr, i, b);
}
}
public static void Quicksort(Ordered[] arr) {
qsort(arr, 0, arr.Length-1);
}
}
public abstract class Ordered {
public abstract bool Less(Ordered that);
}
anyone can help explain it to me, thanks
Comment