private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { bugPoint p = new bugPoint((float)e.X, (float)e.Y); // a new point is created based on the point clicked by the user UpdateList(); }
public Form1() { InitializeComponent(); // create c1 by using the default constructor c1 = new bugCircle(); // unit cirlce c1.Radius = 10.0; c1.center.X = 5; c1.center.Y = 10; c1.name = " a cute circle "; // create c2 and c3 by using the overloaded constructor c2 = new bugCircle(-5.0, new Point(3, 3)); // another unit circle c3 = new bugCircle(3.0, new Point(5, 4)); // yet another one p1 = new bugPoint(); // locate at the origin p2 = new bugPoint(3F, 4F); p3 = new bugPoint(2F, 4F); bugPoint p4; // = p2.Add(p3); p4 = p2 + p3; this.Text = p4.ToString(); this.Text += "dist " + p1.Distance2(p2).ToString(); this.Text += "ang = " + p2.SlopeWChoice(bugPoint.AngleType.Degree).ToString(); }
private void lBoxPoints_SelectedIndexChanged(object sender, EventArgs e) { // if an point is selected, dipslay its content in the text boxes if (lBoxPoints.SelectedIndex >= 0) { bugPoint p = (bugPoint)lBoxPoints.SelectedItem; tBoxX.Text = p.Location.X.ToString(); tBoxY.Text = p.Location.Y.ToString(); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (lBoxPoints.SelectedIndex >= 0) { bugPoint p = (bugPoint)lBoxPoints.SelectedItem; float f = 0f; if (float.TryParse(tBoxX.Text, out f)) { p.Location.X = f; } if (float.TryParse(tBoxY.Text, out f)) { p.Location.Y = f; } UpdateList(); } }
/// <summary> /// Overloaded constructor using a bugPoint object /// </summary> /// <param name="p">a bugPoint Object</param> public bugPoint(bugPoint p) { Location = new PointF(p.Location.X, p.Location.Y); }
/// <summary> /// Compute the dot prodct between this and vector p /// </summary> /// <param name="p">vector p</param> /// <returns></returns> public float DotProduct(bugPoint p) { return(0F); }
/// <summary> /// Subtract vector p from this one /// </summary> /// <param name="p">vector to subtract</param> /// <returns>resulting vector</returns> public bugPoint Subtract(bugPoint p) { return(new bugPoint(this.Location.X - p.Location.X, this.Location.Y - p.Location.Y)); // yet another stub }
/// <summary> /// Add vector p to this one /// and return a new vector that represents the sum /// </summary> /// <param name="p">vector to add to this</param> /// <returns>resulting vector</returns> public bugPoint Add(bugPoint p) { return(new bugPoint(this.Location.X + p.Location.X, this.Location.Y + p.Location.Y)); }
/// <summary> /// Compute the distance between this point and point p /// </summary> /// <param name="p">distance to point p is to be computed</param> /// <returns>distance in float</returns> public float Distance2(bugPoint p) { return((float)Math.Sqrt(Math.Pow((double)(this.Location.X - p.Location.X), 2.0) + Math.Pow((double)(this.Location.Y - p.Location.Y), 2.0))); }
/// <summary> /// Overloaded constructor using a bugPoint object /// </summary> /// <param name="p">a bugPoint Object</param> public bugPoint(bugPoint p) { Location = new PointF(p.Location.X, p.Location.Y); nPoints++; buglist.Add(this); }