public static void Draw(Angle angle, SystemCoordinates SecondEnd, SystemCoordinates FirstEnd, bool Selected = false) { Point p1 = CoordinateSystem.Instance.Converter(SecondEnd); p1.Y += (int)(3 * angle.cos()); p1.X += (int)(3 * angle.sin()); Point pp1 = new Point(p1.X + (int)(Math.Ceiling(2 * angle.sin() * (-1))), p1.Y - (int)(Math.Ceiling(2 * angle.cos()))); if (angle.GetInDegrees() >= 69 && angle.GetInDegrees() <= 90) { pp1.Y += 1; } DoubleExtention d = FirstEnd.Distance(SecondEnd); d *= CoordinateSystem.Instance.Scale; int length = (int)d; Point p2 = new Point((int)(length * angle.cos()) + p1.X, (int)(length * angle.sin() * (-1)) + p1.Y); Point pp2 = new Point((int)(length * angle.cos()) + pp1.X, (int)(length * angle.sin() * (-1)) + pp1.Y); LineDrawer.DrawLine(p1, p2, Color.Red, 5); if (Selected) { LineDrawer.DrawLine(pp1, pp2, Color.Blue, 3); } else { LineDrawer.DrawLine(pp1, pp2, Color.Black, 3); } }
private void RebuildLense(SystemCoordinates center, SystemCoordinates p1, SystemCoordinates p2, SystemCoordinates p3, SystemCoordinates p4, SystemCoordinates p5, SystemCoordinates p6) { ic1 = false; ic2 = false; if (SystemCoordinates.InOneLine(p1, p2, p3)) { l1 = new Line(p1, p3, false); } else { ic1 = true; c1 = new Circle(p1, p2, p3); } if (SystemCoordinates.InOneLine(p4, p5, p6)) { l2 = new Line(p4, p6, false); } else { ic2 = true; c2 = new Circle(p4, p5, p6); } //length = p1.Distance(p3); Line l = new Line(p1, p3, false); menisk = DoubleExtention.MinimumOf(p3.Distance(p4), p3.Distance(p6)); if (menisk != 0) { if (p3.Distance(p4) < p3.Distance(p6)) { menisk1 = new Line(p3, p4, false); menisk2 = new Line(p1, p6, false); } else { menisk1 = new Line(p3, p6, false); menisk2 = new Line(p1, p4, false); } } coordinates = center; this.p2 = p2; this.p5 = p5; }
public Lense(string name, SystemCoordinates center, SystemCoordinates p1, SystemCoordinates p2, SystemCoordinates p3, SystemCoordinates p4, SystemCoordinates p5, SystemCoordinates p6) { ic1 = false; ic2 = false; if (SystemCoordinates.InOneLine(p1, p2, p3)) { l1 = new Line(p1, p3, false); } else { ic1 = true; c1 = new Circle(p1, p2, p3); } if (SystemCoordinates.InOneLine(p4, p5, p6)) { l2 = new Line(p4, p6, false); } else { ic2 = true; c2 = new Circle(p4, p5, p6); } Line l = new Line(p1, p3, false); menisk = DoubleExtention.MinimumOf(p3.Distance(p4), p3.Distance(p6)); if (menisk != 0) { if (p3.Distance(p4) < p3.Distance(p6)) { menisk1 = new Line(p3, p4, false); menisk2 = new Line(p1, p6, false); } else { menisk1 = new Line(p3, p6, false); menisk2 = new Line(p1, p4, false); } } coordinates = center; this.name = name; this.p2 = p2; this.p5 = p5; }
public override void Draw(System.Drawing.Point cursorCoordinates) { if (counter == 0) { OpticalBuilderLib.Drawing.OGL.DrawFilledCircle(new Pen(Color.Yellow), cursorCoordinates, 10); } if (counter == 1) { OpticalBuilderLib.Drawing.OGL.DrawFilledCircle(new Pen(Color.Yellow), center, 10); DoubleExtention radius = center.Distance(CoordinateSystem.Instance.Converter(cursorCoordinates)); OpticalBuilderLib.Drawing.CircleDrawer.Draw(false, center, radius * CoordinateSystem.Instance.Scale); } if (counter == 2) { OpticalBuilderLib.Drawing.OGL.DrawFilledCircle(new Pen(Color.Yellow), center, 10); OpticalBuilderLib.Drawing.CircleDrawer.Draw(false, center, radius * CoordinateSystem.Instance.Scale); } }
public void Rotate(Angle new_an) { SystemCoordinates z = new SystemCoordinates(coordinates); SystemCoordinates p1, p2, p3, p4, p5, p6; DoubleExtention l; Angle a; Line f; //P1 l = z.Distance(P1); f = new Line(z, P1, false); f.BuildAngle(); a = new Angle(new_an.GetInDegrees() + f.AngleForOnePointLines.GetInDegrees() - Anglee.GetInDegrees(), false); p1 = new SystemCoordinates(l * a.cos() + z.X, l * a.sin() + z.Y); //P2 l = z.Distance(P2); f = new Line(z, P2, false); f.BuildAngle(); a = new Angle(new_an.GetInDegrees() + f.AngleForOnePointLines.GetInDegrees() - Anglee.GetInDegrees(), false); p2 = new SystemCoordinates(l * a.cos() + z.X, l * a.sin() + z.Y); //P3 l = z.Distance(P3); f = new Line(z, P3, false); f.BuildAngle(); a = new Angle(new_an.GetInDegrees() + f.AngleForOnePointLines.GetInDegrees() - Anglee.GetInDegrees(), false); p3 = new SystemCoordinates(l * a.cos() + z.X, l * a.sin() + z.Y); //P4 l = z.Distance(P4); f = new Line(z, P4, false); f.BuildAngle(); a = new Angle(new_an.GetInDegrees() + f.AngleForOnePointLines.GetInDegrees() - Anglee.GetInDegrees(), false); p4 = new SystemCoordinates(l * a.cos() + z.X, l * a.sin() + z.Y); //P5 l = z.Distance(P5); f = new Line(z, P5, false); f.BuildAngle(); a = new Angle(new_an.GetInDegrees() + f.AngleForOnePointLines.GetInDegrees() - Anglee.GetInDegrees(), false); p5 = new SystemCoordinates(l * a.cos() + z.X, l * a.sin() + z.Y); //P6 l = z.Distance(P6); f = new Line(z, P6, false); f.BuildAngle(); a = new Angle(new_an.GetInDegrees() + f.AngleForOnePointLines.GetInDegrees() - Anglee.GetInDegrees(), false); p6 = new SystemCoordinates(l * a.cos() + z.X, l * a.sin() + z.Y); RebuildLense(coordinates, p1, p2, p3, p4, p5, p6); RaiseChanged(); ObjectCollection.Instance.RaiseObjectsChange(); }
public Lense(string savestr) { string[] splitted = savestr.Split('^'); if (splitted.Length != 18) { throw new ErrorWhileReading(); } else { try { name = splitted[1]; coordinates = new SystemCoordinates(Convert.ToDouble(splitted[2]), Convert.ToDouble(splitted[3])); SystemCoordinates p1, p2, p3, p4, p5, p6; p1 = new SystemCoordinates(Convert.ToDouble(splitted[4]), Convert.ToDouble(splitted[5])); p2 = new SystemCoordinates(Convert.ToDouble(splitted[6]), Convert.ToDouble(splitted[7])); p3 = new SystemCoordinates(Convert.ToDouble(splitted[8]), Convert.ToDouble(splitted[9])); p4 = new SystemCoordinates(Convert.ToDouble(splitted[10]), Convert.ToDouble(splitted[11])); p5 = new SystemCoordinates(Convert.ToDouble(splitted[12]), Convert.ToDouble(splitted[13])); p6 = new SystemCoordinates(Convert.ToDouble(splitted[14]), Convert.ToDouble(splitted[15])); ic1 = false; ic2 = false; if (SystemCoordinates.InOneLine(p1, p2, p3)) { l1 = new Line(p1, p3, false); } else { ic1 = true; c1 = new Circle(p1, p2, p3); } if (SystemCoordinates.InOneLine(p4, p5, p6)) { l2 = new Line(p4, p6, false); } else { ic2 = true; c2 = new Circle(p4, p5, p6); } Line l = new Line(p1, p3, false); menisk = DoubleExtention.MinimumOf(p3.Distance(p4), p3.Distance(p6)); if (menisk != 0) { if (p3.Distance(p4) < p3.Distance(p6)) { menisk1 = new Line(p3, p4, false); menisk2 = new Line(p1, p6, false); } else { menisk1 = new Line(p3, p6, false); menisk2 = new Line(p1, p4, false); } } id = Convert.ToInt32(splitted[16]); opticalDensity = Convert.ToDouble(splitted[17]); this.p2 = p2; this.p5 = p5; } catch (Exception e) { throw; } } }
public void ObjectsChanged(Object sender, EventArgs e) { if (!FinalizedLoad) { if (ObjectCollection.Instance.ObjectExists(bound_point_name)) { coordinates = ObjectCollection.Instance.GetObjectByName(bound_point_name).Coordinates; } else { ObjectCollection.Instance.AddObject(new BrightPoint(bound_point_name, coordinates)); } BoundPoint.Removal += PointRemove; BoundPoint.NameChange += NameChange; FinalizedLoad = true; } try { coordinates = BoundPoint.Coordinates; } catch (Exception) { if (ObjectCollection.Instance.ObjectExists(bound_point_name)) { coordinates = ObjectCollection.Instance.GetObjectByName(bound_point_name).Coordinates; } else { ObjectCollection.Instance.AddObject(new BrightPoint(bound_point_name, coordinates)); BoundPoint.Removal += PointRemove; BoundPoint.NameChange += NameChange; } coordinates = BoundPoint.Coordinates; } LineArray = new List <Line>(); LineArray.Add(new Line(coordinates, angle)); LineArray[0].FirstEnd = coordinates; LineArray[0].AngleForOnePointLines = angle; bool got = false; bool GotAngle; SystemCoordinates LST = SystemCoordinates.Zero; Angle LSTa = new Angle(0); int refl_limit = Convert.ToInt32(SConfig.C["Ray.ReflectionLimit"]); current_density = ObjectCollection.Instance.VneshDensity; DoubleExtention new_density = current_density; bool set_dens = false; for (int i = 1; i < refl_limit + 1; i++) { got = false; GotAngle = false; foreach (ObjectProto X in ObjectCollection.Instance.objects) { bool PF; bool AG; Angle anglee; SystemCoordinates x = X.IntersectWithLine(out PF, LineArray[i - 1], out AG, out anglee, this); if (PF && AG && got) { if (x.Distance(LineArray[i - 1].FirstEnd) < LST.Distance(LineArray[i - 1].FirstEnd)) { LST = x; LSTa = anglee; GotAngle = true; if (X is IPreloml && swap_density) { if (current_density != ((IPreloml)X).OpticalDensity) { new_density = ((IPreloml)X).OpticalDensity; } else { new_density = ObjectCollection.Instance.VneshDensity; } swap_density = false; set_dens = true; } else { set_dens = false; } } swap_density = false; } if (PF && AG && !got) { LST = x; LSTa = anglee; got = true; GotAngle = true; if (X is IPreloml && swap_density) { if (current_density != ((IPreloml)X).OpticalDensity) { new_density = ((IPreloml)X).OpticalDensity; } else { new_density = ObjectCollection.Instance.VneshDensity; } swap_density = false; set_dens = true; } else { set_dens = false; } swap_density = false; } if (PF && !AG && got) { if (x.Distance(LineArray[i - 1].FirstEnd) < LST.Distance(LineArray[i - 1].FirstEnd)) { LST = x; GotAngle = false; if (X is IPreloml && swap_density) { if (current_density != ((IPreloml)X).OpticalDensity) { new_density = ((IPreloml)X).OpticalDensity; } else { new_density = ObjectCollection.Instance.VneshDensity; } swap_density = false; set_dens = true; } else { set_dens = false; } } swap_density = false; } if (PF && !AG && !got) { LST = x; got = true; GotAngle = false; if (X is IPreloml && swap_density) { if (current_density != ((IPreloml)X).OpticalDensity) { new_density = ((IPreloml)X).OpticalDensity; } else { new_density = ObjectCollection.Instance.VneshDensity; } swap_density = false; set_dens = true; } else { set_dens = false; } swap_density = false; } swap_density = false; } if (got) { LineArray[i - 1].SecondEnd = LST; if (set_dens) { current_density = new_density; } if (i != refl_limit) { if (GotAngle == true) { LineArray.Add(new Line(LST, LSTa)); } else { break; } } swap_density = false; } else { swap_density = false; break; } } }
public override void Draw(Point cursorCoordinates) { SystemCoordinates P1, P3, P4, P6; if (count == 0) { OGL.DrawFilledCircle(new Pen(Color.Yellow), cursorCoordinates, 5); } if (count == 1) { OGL.DrawFilledCircle(new Pen(Color.Yellow), cursorCoordinates, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p1, 5); } if (count == 2 && cursorCoordinates != p1.ToScreen() && cursorCoordinates != p2.ToScreen()) { Line x = p1 + p2; DoubleExtention l = x.DistanceToPoint(cursorCoordinates); Line z = x.BuildOrthogonalLine(p2); z.BuildAngle(); if (z.AngleForOnePointLines == new Angle(90, false) || z.AngleForOnePointLines == new Angle(90, false)) { z.FirstEnd = new SystemCoordinates(p2.X, p2.Y + l); z.SecondEnd = new SystemCoordinates(p2.X, p2.Y - l); } else { z.FirstEnd = new SystemCoordinates(p2.X + l * z.AngleForOnePointLines.cos(), p2.Y + l * z.AngleForOnePointLines.sin()); z.SecondEnd = new SystemCoordinates(p2.X - l * z.AngleForOnePointLines.cos(), p2.Y + l * z.AngleForOnePointLines.sin()); } Line u = x.BuildOrthogonalLine(p1); u.BuildAngle(); if (u.AngleForOnePointLines == new Angle(90, false) || u.AngleForOnePointLines == new Angle(90, false)) { u.FirstEnd = new SystemCoordinates(p1.X, p1.Y + l); u.SecondEnd = new SystemCoordinates(p1.X, p1.Y - l); } else { u.FirstEnd = new SystemCoordinates(p1.X + l * u.AngleForOnePointLines.cos(), p1.Y + l * u.AngleForOnePointLines.sin()); u.SecondEnd = new SystemCoordinates(p1.X - l * u.AngleForOnePointLines.cos(), p1.Y + l * u.AngleForOnePointLines.sin()); } P1 = z.FirstEnd; P3 = z.SecondEnd; P4 = u.FirstEnd; P6 = u.SecondEnd; u = new Line(P1, P3, false); z = new Line(P4, P6, false); u.Drawer(2); z.Drawer(2); OGL.DrawFilledCircle(new Pen(Color.Yellow), P1, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), P3, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), P4, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), P6, 5); } if (count == 3 && cursorCoordinates != p1.ToScreen() && cursorCoordinates != p3.ToScreen() && cursorCoordinates != p4.ToScreen() && cursorCoordinates != p6.ToScreen()) { Line z = new Line(p1, p3, false); Line u = new Line(p4, p6, false); z.Drawer(2); u.Drawer(2); if (p1.Distance(p4) < p1.Distance(p6)) { Circle beta = null; Line alpha = null; if (SystemCoordinates.InOneLine(p1, cursorCoordinates, p4)) { alpha = new Line(p1, p4, false); } else { beta = new Circle(p1, cursorCoordinates, p4); } if (alpha != null) { alpha.Drawer(Color.Black, 2); } if (beta != null) { beta.Draw(false); } } else { Circle beta = null; Line alpha = null; if (SystemCoordinates.InOneLine(p1, cursorCoordinates, p6)) { alpha = new Line(p1, p6, false); } else { beta = new Circle(p1, cursorCoordinates, p6); } if (alpha != null) { alpha.Drawer(Color.Black, 2); } if (beta != null) { beta.Draw(false); } } OGL.DrawFilledCircle(new Pen(Color.Yellow), p1, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p3, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p4, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p6, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), cursorCoordinates, 5); } if (count == 4 && cursorCoordinates != p1.ToScreen() && cursorCoordinates != p3.ToScreen() && cursorCoordinates != p4.ToScreen() && cursorCoordinates != p6.ToScreen()) { Line z = new Line(p1, p3, false); Line u = new Line(p4, p6, false); z.Drawer(2); u.Drawer(2); if (p1.Distance(p4) < p1.Distance(p6)) { Line beta_x = null; Line alpha_x = null; Circle alpha = null, beta = null; if (SystemCoordinates.InOneLine(p1, p2, p4)) { beta_x = new Line(p1, p4, false); } else { beta = new Circle(p1, p2, p4); } if (SystemCoordinates.InOneLine(p3, cursorCoordinates, p6)) { alpha_x = new Line(p3, p6, false); } else { alpha = new Circle(p3, cursorCoordinates, p6); } if (beta != null) { beta.Draw(false); } if (alpha != null) { alpha.Draw(false); } if (beta_x != null) { beta_x.Drawer(2); } if (alpha_x != null) { alpha_x.Drawer(2); } } else { Line beta_x = null; Line alpha_x = null; Circle beta = null; Circle alpha = null; if (SystemCoordinates.InOneLine(p1, p2, p6)) { beta_x = new Line(p1, p6, false); } else { beta = new Circle(p1, p2, p6); } if (SystemCoordinates.InOneLine(p3, cursorCoordinates, p4)) { alpha_x = new Line(p3, p4, false); } else { alpha = new Circle(p3, cursorCoordinates, p4); } if (beta != null) { beta.Draw(false); } if (alpha != null) { alpha.Draw(false); } if (beta_x != null) { beta_x.Drawer(2); } if (alpha_x != null) { alpha_x.Drawer(2); } } OGL.DrawFilledCircle(new Pen(Color.Yellow), p1, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p3, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p4, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p6, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p2, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), cursorCoordinates, 5); } if (count == 5) { Line z = new Line(p1, p3, false); Line u = new Line(p4, p6, false); z.Drawer(2); u.Drawer(2); if (p1.Distance(p4) < p1.Distance(p6)) { Line beta_x = null; Line alpha_x = null; Circle alpha = null, beta = null; if (SystemCoordinates.InOneLine(p1, p2, p4)) { beta_x = new Line(p1, p4, false); } else { beta = new Circle(p1, p2, p4); } if (SystemCoordinates.InOneLine(p3, p5, p6)) { alpha_x = new Line(p3, p6, false); } else { alpha = new Circle(p3, p5, p6); } if (beta != null) { beta.Draw(false); } if (alpha != null) { alpha.Draw(false); } if (beta_x != null) { beta_x.Drawer(2); } if (alpha_x != null) { alpha_x.Drawer(2); } } else { Line beta_x = null; Line alpha_x = null; Circle beta = null; Circle alpha = null; if (SystemCoordinates.InOneLine(p1, p2, p6)) { beta_x = new Line(p1, p6, false); } else { beta = new Circle(p1, p2, p6); } if (SystemCoordinates.InOneLine(p3, p5, p4)) { alpha_x = new Line(p3, p4, false); } else { alpha = new Circle(p3, p5, p4); } if (beta != null) { beta.Draw(false); } if (alpha != null) { alpha.Draw(false); } if (beta_x != null) { beta_x.Drawer(2); } if (alpha_x != null) { alpha_x.Drawer(2); } } OGL.DrawFilledCircle(new Pen(Color.Yellow), p1, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p3, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p4, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p6, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p2, 5); OGL.DrawFilledCircle(new Pen(Color.Yellow), p5, 5); } }