public override List <GraphicPoint> intesectionCircle(GraphicPoint center1, float radius1) { GraphicPoint center = points[0]; float dx = center.X - center1.X; float dy = center.Y - center1.Y; double dist = Math.Sqrt(dx * dx + dy * dy); List <GraphicPoint> list = new List <GraphicPoint>(); if ((dist > scaled_radius + radius1) || (dist < Math.Abs(scaled_radius - radius1)) || ((dist == 0) && (scaled_radius == radius1))) { return(list); } double a = (scaled_radius * scaled_radius - radius1 * radius1 + dist * dist) / (2 * dist); double h = Math.Sqrt(scaled_radius * scaled_radius - a * a); double cx2 = center.X + a * (center1.X - center.X) / dist; double cy2 = center.Y + a * (center1.Y - center.Y) / dist; list.Add(new GraphicPoint( (float)(cx2 + h * (center1.Y - center.Y) / dist), (float)(cy2 - h * (center1.X - center.X) / dist))); list.Add(new GraphicPoint( (float)(cx2 - h * (center1.Y - center.Y) / dist), (float)(cy2 + h * (center1.X - center.X) / dist))); return(list); }
private void createTriangle(Dictionary <string, string> gobject) { string str_a, str_b, str_c, str_color, str_lineType, str_fill; gobject.TryGetValue("a", out str_a); gobject.TryGetValue("b", out str_b); gobject.TryGetValue("c", out str_c); gobject.TryGetValue("color", out str_color); gobject.TryGetValue("lineType", out str_lineType); gobject.TryGetValue("filled", out str_fill); GraphicPoint a = new GraphicPoint(float.Parse(str_a.Split(';')[0].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(str_a.Split(';')[1].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture)); GraphicPoint b = new GraphicPoint(float.Parse(str_b.Split(';')[0].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(str_b.Split(';')[1].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture)); GraphicPoint c = new GraphicPoint(float.Parse(str_c.Split(';')[0].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(str_c.Split(';')[1].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture)); max_x = Math.Max(max_x, Math.Max(Math.Abs(a.X), Math.Max(Math.Abs(b.X), Math.Abs(c.X)))); max_y = Math.Max(max_y, Math.Max(Math.Abs(a.Y), Math.Max(Math.Abs(b.Y), Math.Abs(c.Y)))); bool filled = bool.Parse(str_fill); Color color = Color.FromArgb(int.Parse(str_color.Split(';')[0]), int.Parse(str_color.Split(';')[1]), int.Parse(str_color.Split(';')[2]), int.Parse(str_color.Split(';')[3])); LineTypes lt; Enum.TryParse(str_lineType, true, out lt); list_gobjects.Add(new Triangle(lt, color, a, b, c, filled)); }
public override List <GraphicPoint> intesectionCircle(GraphicPoint center, float radius) { List <GraphicPoint> list = new List <GraphicPoint>(); float cx = center.X; float cy = center.Y; float k = (points[1].Y - points[0].Y) / (points[1].X - points[0].X); float n = points[0].Y - k * points[0].X; float A = 1 + k * k; float B = -2 * cx + 2 * k * (n - cy); float C = cx * cx + (n - cy) * (n - cy) - radius * radius; float D = B * B - 4 * A * C; if (D < 0) { return(list); } float x1 = (float)(-B + Math.Sqrt(D)) / (2 * A); float y1 = k * x1 + n; float x2 = (float)(-B - Math.Sqrt(D)) / (2 * A); float y2 = k * x2 + n; list.Add(new GraphicPoint(x1, y1)); list.Add(new GraphicPoint(x2, y2)); return(list); }
public override List <GraphicPoint> intesectionCircle(GraphicPoint center, float radius) { List <GraphicPoint> points = new List <GraphicPoint>(); foreach (Line line in asLines()) { points.AddRange(line.intesectionCircle(center, radius)); } return(points); }
public override bool contains(GraphicPoint point) { if (Math.Abs(Math.Pow(points[0].X - point.X, 2) + Math.Pow(points[0].Y - point.Y, 2) - Math.Pow(scaled_radius, 2)) < 0.1) { return(true); } else { return(false); } }
public override bool contains(GraphicPoint point) { foreach (Line l in asLines()) { if (l.contains(point)) { return(true); } } return(false); }
public override bool contains(GraphicPoint point) { float k = (points[1].Y - points[0].Y) / (points[1].X - points[0].X); float n = points[0].Y - k * points[0].X; if ((point.X > leftmost_x()) && point.X < rightmost_x() && Math.Abs(point.Y - (k * point.X + n)) < 0.01) { return(true); } else { return(false); } }
private void createCircle(Dictionary <string, string> gobject) { string str_center, str_radius, str_color, str_lineType, str_fill; gobject.TryGetValue("center", out str_center); gobject.TryGetValue("radius", out str_radius); gobject.TryGetValue("color", out str_color); gobject.TryGetValue("lineType", out str_lineType); gobject.TryGetValue("filled", out str_fill); GraphicPoint center = new GraphicPoint(float.Parse(str_center.Split(';')[0].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(str_center.Split(';')[1].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture)); float radius = float.Parse(str_radius.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture); bool filled = bool.Parse(str_fill); max_x = Math.Max(max_x, center.X + radius); max_y = Math.Max(max_y, center.Y + radius); Color color = Color.FromArgb(int.Parse(str_color.Split(';')[0]), int.Parse(str_color.Split(';')[1]), int.Parse(str_color.Split(';')[2]), int.Parse(str_color.Split(';')[3])); LineTypes lt; Enum.TryParse(str_lineType, true, out lt); list_gobjects.Add(new Circle(lt, color, center, radius, filled)); }
public abstract List <GraphicPoint> intesectionCircle(GraphicPoint center, float radius);
public abstract bool contains(GraphicPoint point);
public Circle(LineTypes lt, Color col, GraphicPoint c, float r, bool f) : base(lt, col) { points = new GraphicPoint[1]; points[0] = c; filled = f; scaled_radius = radius = r; }
public Line(LineTypes lt, Color c, GraphicPoint a, GraphicPoint b) : base(lt, c) { points = new GraphicPoint[2]; points[0] = a; points[1] = b; }
public override void draw(Bitmap bitmap, float scaling) { if (!filled) { foreach (Line line in asLines()) { line.draw(bitmap, scaling); } } else { setScaling(scaling); List <GraphicPoint> list_points = points.ToList(); list_points.Sort(delegate(GraphicPoint p1, GraphicPoint p2) { return(-p1.Y.CompareTo(p2.Y)); }); GraphicPoint a = list_points[0]; GraphicPoint b = list_points[1]; GraphicPoint c = list_points[2]; Line ab = new Line(lineType, color, a, b); Line bc = new Line(lineType, color, b, c); Line ac = new Line(lineType, color, a, c); Line leftEdge; Line rightEdge; if (ab.leftmost_x() < ac.leftmost_x()) { leftEdge = ab; rightEdge = ac; } else { leftEdge = ac; rightEdge = ab; } Line bottomEdge = bc; int startY = (int)a.Y, endY = (int)c.Y; for (int y = startY; y >= endY; y--) { int startX, endX = (int)rightEdge.X(y); if (y < leftEdge.Y((int)leftmost_x())) { startX = (int)bottomEdge.X(y); } else { startX = (int)leftEdge.X(y); } for (int x = startX; x <= endX; x++) { if ((Math.Abs(x + bitmap.Width / 2) < bitmap.Width) && (Math.Abs(y + bitmap.Height / 2) < bitmap.Height)) { bitmap.SetPixel(x + bitmap.Width / 2, y + bitmap.Height / 2, pen.Color); } } } } }
public Triangle(LineTypes lt, Color col, GraphicPoint a, GraphicPoint b, GraphicPoint c, bool f) : base(lt, col) { points = new GraphicPoint[3]; points[0] = a; points[1] = b; points[2] = c; filled = f; }