Exemplo n.º 1
0
		/// <summary>
		/// Imposta Window
		/// </summary>
		/// <param name="pt1"></param>
		/// <param name="pt2"></param>
		/// <returns></returns>
		public bool Set(Point2D pt1, Point2D pt2)
			{
			P1 = pt1;
			P2 = pt2;
			RicalcolaFinestra();
			return true;
			}
Exemplo n.º 2
0
 /// <summary>
 /// Costruttore
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="par1"></param>
 /// <param name="par2"></param>
 /// <param name="tratto1"></param>
 /// <param name="tratto2"></param>
 /// <param name="tang1"></param>
 /// <param name="tang2"></param>
 public Intersection(Point2D pt, double par1, double par2, Tratto tratto1, Tratto tratto2, bool tang1=false, bool tang2 = false)
 {
     p = pt;
     t1 = par1;
     t2 = par2;
     tg1 = tang1;
     tg2 = tang2;
     tr1 = tratto1;
     tr2 = tratto2;
 }
Exemplo n.º 3
0
 // Origine + angolo in radianti o gradi
 public Vector2D(double xorig, double yorig, double angolo, bool radianti = true)
 {
     double ang;
     this.orig = new Point2D(xorig, yorig);
     if(radianti)
         ang = angolo;
     else
         ang = angolo*Math.PI / 180.0;
     this.vers = new Point2D(Math.Cos(ang), Math.Sin(ang));
     this.valid = this.Validate();
 }
Exemplo n.º 4
0
 // Origine + versore o secondo punto
 public Vector2D(double xorig, double yorig, double xvers, double yvers, bool bVers = true)
 {
     this.orig = new Point2D(xorig,yorig);
     if(bVers)
         {
         this.vers = new Point2D(xvers,yvers);							// Imposta il versore
         }
     else
         {
         this.vers = new Point2D(xvers - xorig, yvers - yorig);			// Imposta la differenza
         }
     this.valid = this.Validate();
 }
Exemplo n.º 5
0
 // Origine + versore o secondo punto
 public Vector2D(Point2D orig, Point2D vers, bool bVers = true)
 {
     this.orig = orig;
     if(bVers)															// Imposta il versore
         {
         this.vers = vers;
         }
     else
         {
         this.vers = vers - orig;										// Imposta la differenza
         }
     this.valid = this.Validate();
 }
Exemplo n.º 6
0
		/// <summary>
		/// Distanza punto - tratto generico
		/// </summary>
		/// <param name="p">Punto</param>
		/// <param name="te">Tratto</param>
		/// <returns></returns>
		public static double Distance(Point2D p, Tratto te)
		    {
		    Type tp;
		    tp = te.GetType();
		    if(tp == typeof(Line2D))
		        {
		        return Distance( p, (Line2D) te);
		        }		
		    if(tp == typeof(Arc2D))
		        {
				throw new Exception("Tipo non implementato");		
		        // return Distance(p, (Arc2D) te);
		        }		
		    throw new Exception("Tipo non implementato");
		    }
Exemplo n.º 7
0
		/// <summary>
		/// Ottiene il versore rifratto
		/// </summary>
		/// <param name="versoreIn">Versore raggio entrante</param>
		/// <param name="versoreNorm">Versore normale uscente</param>
		/// <param name="n1">indice rifrazione mezzo attuale</param>
		/// <param name="n2">indice rifrazione prossimo mezzo</param>
		/// <returns></returns>
		public static Point2D Rifratto(Point2D versoreIn, Point2D versoreNorm, double n1, double n2)	// Rifrazione (versori) 
			{
			Point2D r = new Point2D();
			if( (n1>0) && (n2>0) )
				{
				double nn, ct, st2;
				nn = n1 / n2;				// Rapporto tra gli indici di rifrazione
				ct = versoreIn ^ versoreNorm;			// Coseno angolo incidente
				st2 = nn*nn*(1-ct*ct);		// Seno angolo riflesso, al quadrato
				if(st2 <= 1.0)				// Se entro angolo limite (non riflessione totale)
					{
					r = nn*versoreIn - versoreNorm*(nn*ct+Math.Sqrt(1-st2));
					}
				}
			return r;
			}
Exemplo n.º 8
0
		private void cancellaTuttoToolStripMenuItem_Click(object sender, EventArgs e)
			{
			displayList.Clear();
			singolo.CancellaOggetti();

			Point2D ax1, ax2, ax3;										// Punti assi
			ax1 = new Point2D(0,0);
			ax2 = new Point2D(finestra.P2.x,0);
			ax3 = new Point2D(0,finestra.P2.y);


			(new Line2D(ax1,ax2)).Display(displayList,3);				// Assi
			(new Line2D(ax1,ax3)).Display(displayList,3);

			this.gradiprimi.Visible=true;
			this.percdiam.Visible=true;

			Invalidate();
			}
Exemplo n.º 9
0
		private void test5ToolStripMenuItem_Click(object sender,EventArgs e)
			{
			Line2D lin = new Line2D(0,0,1,1);
			Raggio ray0 = new Raggio(lin,700);

			Matrix mm = Matrix.Lower(4);
			Matrix mm1 = !mm;

            Point2D p1 = new Point2D(1, 0);
            Point2D p2 = new Point2D(0, 1);
            Point2D p3 = new Point2D (0,2);
            Point2D pc = new Point2D (0,0);
            Point2D p4 = new Point2D (2, 1);
            Point2D p1w = new Point2D(1, -0.01);

            Arc2D ar1 = new Arc2D(pc, p1, p2);
            Line2D ln1 = new Line2D(p2, p3);
            Line2D ln2 = new Line2D(p4, p3);
            Line2D ln3;
            ln3 = new Line2D(p4,p1);

			CorpoOttico cc = new CorpoOttico(new MaterialeOttico("vetro",1.4));
			cc.Add(new Contorno(ln3));
			cc.Add(new Contorno(ln2));
			cc.Add(new Contorno(ln1));
			cc.Add(new Contorno(ar1));
			cc.Validate();

			Point2D po = new Point2D(1.5, -1);

			Arc2D cerchio = new Arc2D(po, 4);
			

			Raggio ray;
			ray = new Raggio(new Line2D(po, p1 + new Point2D(0.05,0)),Ottica.LunghezzaOnda.Rosso);

			List<Intersection> intersezioni = cc.TrovaIntersezioniPositive(ray);
			Contorno xx = cc.Contorno(intersezioni[0].tr2);
			
			#pragma warning disable
			int tmp;
			tmp = 1;
			
			}
Exemplo n.º 10
0
		private void test3ToolStripMenuItem_Click(object sender,EventArgs e)
			{
			Point2D p1 = new Point2D(1, 0);
			Point2D p2 = new Point2D(0, 1);
			Point2D p3 = new Point2D (1,1);
			Point2D pc = new Point2D (0,0);

			Arc2D ar1 = new Arc2D(pc, p1, p2);
			Arc2D ar2 = new Arc2D(pc, p2, p1);
			Arc2D ar3 = new Arc2D(p3, p2);

			Line2D ln1 = new Line2D(p1, p2);
			Line2D ln2 = new Line2D(pc, p3);
			Line2D ln3 = new Line2D(0,0,30,3,false,true);
			
			List<Contorno> profilo = new List<Contorno>();
			profilo.Add(new Contorno(ln1));
			profilo.Add(new Contorno(ln2));
			profilo.Add(new Contorno(ar1));

			List<Intersection> li1 = Function2D.Intersect(ln1, profilo[1].Tratto);
			
			CorpoOttico blocco = new CorpoOttico(new MaterialeOttico("vetro",1.4));

			#pragma warning disable
			int tmp;
			tmp = 1;
			#pragma warning restore
			}
Exemplo n.º 11
0
		private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
			{
			Point2D p1 = new Point2D(1, 0);
			Point2D p2 = new Point2D(0, 1);
			Point2D p3 = new Point2D (1,1);
			Point2D pc = new Point2D (0,0);
			Point2D p4 = new Point2D (0, -1);
			Point2D p5 = new Point2D (1, 2);
			Point2D p6 = new Point2D (1, -1);

			Arc2D ar1 = new Arc2D(pc, p1, p2);
			Arc2D ar1x = new Arc2D(p1, p2, pc, Arc2D.TrePunti.Estremi_e_Centro);
			Arc2D ar2 = new Arc2D(pc, p2, p1);
			Arc2D ar2x = new Arc2D(p2, p1, pc, Arc2D.TrePunti.Estremi_e_Centro);

			Arc2D ar3 = new Arc2D(p3, p2);

			Line2D ln1 = new Line2D(p1, p2);
			Line2D ln2 = new Line2D(pc, p3);
			Line2D ln3 = new Line2D(0,0,30,3,false,true);
			Line2D ln4 = new Line2D(pc, p2, true);
			Line2D ln5 = new Line2D(p2, p3);

			bool b1 = ar1.Belongs(0);
			bool b2 = ar1.Belongs(Math.PI/4);
			bool b3 = ar1.Belongs(Math.PI / 8);
			bool b4 = ln1.Belongs(p1);

			bool c1 = ar1.Belongs(new Point2D(0,1));
			bool c2 = ar1.Belongs(new Point2D(1,0));
			bool c3 = ar1.Belongs(new Point2D(Math.Sqrt(2)/2,Math.Sqrt(2)/2));

			List<Intersection> li1 = Function2D.Intersect(ln1, ln2);
			List<Intersection> li2 = Function2D.Intersect(ln2, ar1);
			List<Intersection> li3 = Function2D.Intersect(ln2, ar1, true, true);
			List<Intersection> li4 = Function2D.Intersect(ln3, ar1);
			List<Intersection> li5 = Function2D.Intersect(ln2, ar2, false, true);
			List<Intersection> li6 = Function2D.Intersect(ln4, ar3, false, false);
			List<Intersection> li7 = Function2D.Intersect(ln5, ln3);

			Point2D[] nr = new Point2D[3];
			double[] nrd = new double[3];
			Function2D.Nearest(p2, ln2, out nr[0], out nrd[0]);
			Function2D.Nearest(p4, ln3, out nr[1], out nrd[1], true);
			Function2D.Nearest(p6, ln3, out nr[2], out nrd[2]);
			Point2D[] nrx = new Point2D[3];
			nrx[0] = Function2D.Nearest(p2, ln2);
			nrx[1] = Function2D.Nearest(p4, ln3, true);
			nrx[2] = Function2D.Nearest(p6, ln3);

			Point2D[] pr = new Point2D[4];
			bool[] prb = new bool[4];

			prb[0] = Function2D.Projection(p3, ln2, out pr[0]);
			prb[1] = Function2D.Projection(p4, ln2, out pr[1]);
			prb[2] = Function2D.Projection(p6, ln2, out pr[2]);
			prb[3] = Function2D.Projection(p2, ln3, out pr[3]);
			Point2D[] prx = new Point2D[4];
			prx[0] = Function2D.Projection(p3, ln2);
			prx[1] = Function2D.Projection(p4, ln2);
			prx[2] = Function2D.Projection(p6, ln2);
			prx[3] = Function2D.Projection(p2, ln3);

			Point2D[] pra = new Point2D[5];
			bool[] prab = new bool[5];

			prab[0] = Function2D.Projection(p6, ar2, out pra[0], true);
			prab[1] = Function2D.Projection(p5, ar1, out pra[1], true);
			prab[2] = Function2D.Projection(p5, ar2, out pra[2], true);
			prab[3] = Function2D.Projection(p5, ar2, out pra[3], false);
			prab[4] = Function2D.Projection(p4, ar3, out pra[4], true);
			Point2D[] prax = new Point2D[5];
			prax[0] = Function2D.Projection(p6, ar2, true);
			prax[1] = Function2D.Projection(p5, ar1, true);
			prax[2] = Function2D.Projection(p5, ar2, true);
			prax[3] = Function2D.Projection(p5, ar2);
			prax[4] = Function2D.Projection(p4, ar3, true);
			Point2D x = new Point2D(10,-1);
			x = -x;
			Line2D[] vout = new Line2D[3];
			bool[] bv = new bool[3];
			bv[0] = Function2D.LineOut(pra[0], ar2, out vout[0], p6);
			bv[1] = Function2D.LineOut(pr[3], ln3, out vout[1], p3);
			bv[2] = Function2D.LineOut(pra[0], ar2, out vout[2], p2);
			Line2D[] voux = new Line2D[3];
			voux[0] = Function2D.LineOut(pra[0], ar2, p6);
			voux[1] = Function2D.LineOut(pr[3], ln3, p3);
			voux[2] = Function2D.LineOut(pra[0], ar2, p2);
			Point2D[] vettori = new Point2D[3];
			vettori[0] = voux[0].Vector();
			vettori[1] = voux[1].Vector();
			vettori[2] = voux[2].Vector();

			Point2D[] vvout = new Point2D[3];
			bool[] bvv = new bool[3];
			bvv[0] = Function2D.VersorOut(pra[0], ar2, out vvout[0], p6);
			bvv[1] = Function2D.VersorOut(pr[3], ln3, out vvout[1], p3);
			bvv[2] = Function2D.VersorOut(pra[0], ar2, out vvout[2], p2);

			Point2D[] vvoux = new Point2D[3];
			vvoux[0] = Function2D.VersorOut(pra[0], ar2, p6);
			vvoux[1] = Function2D.VersorOut(pr[3], ln3, p3);
			vvoux[2] = Function2D.VersorOut(pra[0], ar2, p2);


			double[] scalari = new double[3];
			scalari[0] = vvoux[0]^vettori[0];
			scalari[1] = vvoux[1]^vettori[1];
			scalari[2] = vvoux[2]^vettori[2];


			Point2D Punto2 = new Point2D(-5.17,9.91);
			Point2D Punto3 = new Point2D(-4.82,-10.08);
			Point2D centroX = new Point2D(94.48,1.64);
			Arc2D Arco = new Arc2D(Punto2,Punto3,centroX,Arc2D.TrePunti.Estremi_e_Centro);


			#pragma warning disable
			int tmp;
			tmp = 1;
			#pragma warning restore

			}
Exemplo n.º 12
0
			/// <summary>
			/// Restituisce la lista dei contorni del corpo cui appartiene il punto
			/// </summary>
			/// <param name="pt">Il punto</param>
			/// <returns></returns>
		protected List<Contorno> Belongs(Point2D pt) 
			{
			List<Contorno> lc = new List<Contorno>();		// Crea lista vuota
			foreach(Contorno c in contorni)					// Percorre i contorni
				{
				if(c.Tratto.Belongs(pt, true))				// Se il punto appartiene, aggiunge alla lista
					{
					lc.Add(c);
					}
				}
			return lc;
			}
Exemplo n.º 13
0
		/// <summary>
		/// Linea
		/// </summary>
		/// <param name="x1">x primo punto</param>
		/// <param name="y1">y primo punto</param>
		/// <param name="x2">x secondo punto</param>
		/// <param name="y2">y secondo punto</param>
		/// <param name="bRelative">true: secondo punto sommato al primo</param>
		public Line2D(double x1, double y1, double x2, double y2, bool bRelative = false) : base(typeof(Line2D)) 
			{
			if(bRelative)
				{
				this.p1 = new Point2D(x1,y1);
				this.p2 = new Point2D(p1.x + x2, p1.y + y2);
				}
			else
				{
				this.p1 = new Point2D(x1, y1);
				this.p2 = new Point2D(x2, y2);
				}
			this.Validate();
			}
Exemplo n.º 14
0
		/// <summary>
		/// Linea
		/// </summary>
		/// <param name="p1">Primo punto</param>
		/// <param name="p2">Secondo punto</param>
		/// <param name="bRelative">true: secondo punto sommato al primo</param>
		public Line2D(Point2D p1, Point2D p2, bool bRelative = false) : base(typeof(Line2D)) 
			{
			if(bRelative)
				{
				this.p1 = p1;												
				this.p2 = this.p1 + p2;
				}
			else
				{
				this.p1 = p1;
				this.p2 = p2;
				}
			this.Validate();
			}
Exemplo n.º 15
0
		/// <summary>
		/// Costruttore di copia
		/// </summary>
		/// <param name="l">Linea</param>
		public Line2D(Line2D l) : base(typeof(Line2D)) 
			{
			this.p1 = l.p1;
			this.p2 = l.p2;
			Validate();
			}
Exemplo n.º 16
0
		/// <summary>
		/// Ottiene il punto corrispondente della viewport
		/// </summary>
		/// <param name="P">Punto della Window</param>
		/// <returns></returns>
		public Point Get(Point2D P)
			{
			return new Point( (int)((P.x - P1.x) * sx + p1.X), (int)((P.y - P1.y) * sy + p1.Y) );
			}
Exemplo n.º 17
0
		#pragma warning restore 1591
		#endregion
		#region COSTRUTTORI
		/// <summary>
		/// Costruttore
		/// </summary>
		public Finestra()
			{
			P1 = new Point2D();		// Non null, se no errore al primo ricalcolo
			P2 = new Point2D();
			scaling = TipoScala.Isotropico;
			}
Exemplo n.º 18
0
		/// <summary>
		/// Linea
		/// </summary>
		/// <param name="x1">x primo punto</param>
		/// <param name="y1">y primo punto</param>
		/// <param name="angolo">angolo</param>
		/// <param name="length">lunghezza</param>
		/// <param name="radianti">tre: angolo in radianti, false: in gradi</param>
		/// <param name="bRelative">true: secondo punto sommato al primo</param>
		public Line2D(double x1, double y1, double angolo, double length, bool radianti, bool bRelative = true) : base(typeof(Line2D)) 
			{
			double ang;
			this.p1 = new Point2D(x1, y1);
			if(radianti)
				ang = angolo;
			else
				ang = angolo * Math.PI / 180.0;
			if(bRelative)
				this.p2 = this.P1 + length *(new Point2D(Math.Cos(ang), Math.Sin(ang)));
			else
				this.p2 = length * (new Point2D(Math.Cos(ang), Math.Sin(ang)));
			this.Validate();
			}
Exemplo n.º 19
0
		/// <summary>
		/// Imposta Window
		/// </summary>
		/// <param name="x1"></param>
		/// <param name="y1"></param>
		/// <param name="x2"></param>
		/// <param name="y2"></param>
		/// <returns></returns>
		public bool Set(double x1, double y1, double x2, double y2)
			{
			P1 = new Point2D(x1, y1);
			P2 = new Point2D(x2, y2);
			RicalcolaFinestra();
			return true;
			}
Exemplo n.º 20
0
		/// <summary>
		/// Normalizza tenendo fisso P1
		/// </summary>
		public void Normalize() 
			{
			Point2D v = p2-p1;					// Normalizza vettore da P1 a P2 e ricalcola P2.
			v.Normalize();		
			p2 = p1 + v;
			this.Validate();
			}
Exemplo n.º 21
0
			/// <summary>
			/// Verifica se pVertice e` un vertice del corpo ottico
			/// </summary>
			/// <param name="pVertice">Il punto</param>
			/// <returns>Intersezione fittizia, contenente il rif. ai due tratti di contorno a cui appartiene</returns>
		protected Intersection CheckVertice(Point2D pVertice) 
			{
			Intersection i = null;
			List<Contorno> lc;
			lc = Belongs(pVertice);							// Ottiene la lista
			if(lc.Count == 2)								// Se due Tratti: e` un vertice; se meno, no
				{
				i = new Intersection(pVertice, 0.0, 0.0, lc[0].Tratto, lc[1].Tratto);
				}
			if(lc.Count > 2)
				throw new Exception("Profilo con punto comune a piu` di due tratti");
			return i;
			}
Exemplo n.º 22
0
		/// <summary>
		/// Appartenenza del punto p alla retta
		/// </summary>
		/// <param name="p">Punto</param>
		/// <param name="bInside">true richiede appartenenza al segmento</param>
		/// <returns>true se appartiene alla retta o al segmento</returns>
		public override bool Belongs(Point2D p, bool bInside = false)
		    {
		    if (this.valid)
		        {
		        double tx, ty, denx, deny, t;
				bool bx = false;
				bool by = false;
				t = tx = ty = Double.NaN;
				denx = this.p2.x - this.p1.x;						// Calcola i denominatori
				deny = this.p2.y - this.p1.y;
				if(Math.Abs(denx) > Line2D.CoincidenceDistance)		// Calcola i parametri t del punto, con le x e con le y
					{												// e li usa solo se > cooincidence distance, per evitare
					bx = true;										// approssimazioni numeriche
					tx = (p.x - this.p1.x) / denx;	
					}
				if(Math.Abs(deny) > Line2D.CoincidenceDistance)
					{
					by = true;
					ty = (p.y - this.p1.y) / deny;
					}
				if( bx && by)										// Calcola t come media oppure...
					{
					t = (tx+ty)*0.5;
					}
				else
					{
					if(bx) t = tx;									// con il valore valido
					if(by) t = ty;
					}
				if( t == Double.NaN)								// Se no: eccezione (era this.valid)
					throw new Exception("Errore in public bool Line2D.Belongs(Point2D p)");
		        if((this.Point(t) - p).Mod() <= Line2D.coincidencedistance)		// Distanza tra p e intersezione calcolata.
		            {
					if(bInside)										// Se richiesta appartenenza, controlla.
						{
						if( (t >= 0.0) && (t <= 1.0))				// Se appartiene al segmento, esce con true
							return true;
						}
					else
						return true;								// Se non richiesta, esce con true
		            }
		        }
		    return false;
		    }
Exemplo n.º 23
0
		private void test2ToolStripMenuItem_Click(object sender,EventArgs e)
			{
			Point2D[] v = new Point2D[10];
			v[0] = new Point2D(1, 0, false);
			v[1] = new Point2D(1, 90, false);
			v[2] = new Point2D(1, 180, false);
			v[3] = new Point2D(1, -90, false);
			v[4] = new Point2D(1, 30, false);			
			v[5] = new Point2D(1, 45, false);			
			v[6] = new Point2D(1, 60, false);			
			v[7] = new Point2D(1, -45, false);			
			v[8] = new Point2D(1, -135, false);			
			v[9] = new Point2D(1, 135, false);
			
			Point2D[] r = new Point2D[8];
			r[0] = Ottica.Riflesso(v[1], v[3]);				// ok
			r[1] = Ottica.Rifratto(v[1], v[3], 1, 1.33);	// ok	
			r[2] = Ottica.Riflesso(v[4], v[8]);				// -v[6] ok
			r[3] = Ottica.Rifratto(v[6], v[8], 1, 1.4);		// ok
			r[4] = Ottica.Rifratto(v[6], v[8], 1.4, 1);		// ok
			r[5] = Ottica.Riflesso(v[4],v[9]);
			r[6] = Ottica.Rifratto(v[4],v[9],1,1.33);
			r[7] = Ottica.Rifratto(v[4],v[9],1.33,1);
			//r[8] = Ottica.Rifratto

			double[] ang = new double[8];
			ang[0] = r[0].Alfa(false);
			ang[1] = r[1].Alfa(false);
			ang[2] = r[2].Alfa(false);
			ang[3] = r[3].Alfa(false);
			ang[4] = r[4].Alfa(false);
			ang[5] = r[5].Alfa(false);
			ang[6] = r[6].Alfa(false);
			ang[7] = r[7].Alfa(false);
			//ang[8] = r[8].Alfa(false);

			double x = Math.Atan2(0,0);
			
			#pragma warning disable
			int tmp;
			tmp = 1;
			#pragma warning restore
			}
Exemplo n.º 24
0
		/// <summary>
		/// Ricalcola parametri e finestra
		/// </summary>
		/// <returns></returns>
		protected bool RicalcolaFinestra()
			{
			bool ok = false;
			dX = P2.x - P1.x;				// Ampiezza finestra
			dY = P2.y - P1.y;
			dx = p2.X - p1.X;				// Ampiezza viewport
			dy = p2.Y - p1.Y;
			if( (System.Math.Abs(dX) > Point2D.Epsilon) && (System.Math.Abs(dY) > Point2D.Epsilon) )
				{
				double sxnew, synew, scom;							// Nuovi fattori di scala
				sxnew = dx / dX;
				synew = dy / dY;
				scom = Math.Min(Math.Abs(sxnew), Math.Abs(synew));

				if( (System.Math.Abs(sxnew) > Point2D.Epsilon) && (System.Math.Abs(synew) > Point2D.Epsilon) )
					{
					switch(scaling)
						{
						case TipoScala.Isotropico:
							{
							sx = Math.Sign(sxnew) * scom;				// Imposta fattore di scala comune
							sy = Math.Sign(synew) * scom;
							P1 = Get(p1);								// Ricalcola la window, con stesso aspetto della vieport
							P2 = Get(p2);
							break;
							}
						case TipoScala.Anisotropico:
							{
							sx = sxnew;
							sy = synew;
							break;
							}
						}
					ok = true;
					}
				}
			centro = (P1+P2)/2;
			return ok;
			}
Exemplo n.º 25
0
		private void test4ToolStripMenuItem_Click(object sender,EventArgs e)
			{
			Point2D p1 = new Point2D(1, 0);
			Point2D p2 = new Point2D(0, 1);
			Point2D p3 = new Point2D (0,2);
			Point2D pc = new Point2D (0,0);
			Point2D p4 = new Point2D (2, 1);
			Point2D p1w = new Point2D(1, -0.01);

			Arc2D ar1 = new Arc2D(pc, p1, p2);
			Line2D ln1 = new Line2D(p2, p3);
			Line2D ln2 = new Line2D(p4, p3);
			Line2D ln3;
			ln3 = new Line2D(p4,p1);
//			ln3 = new Line2D(p4,p1w);

			CorpoOttico cc = new CorpoOttico(new MaterialeOttico("vetro",1.4));
			cc.Add(new Contorno(ln3));
			cc.Add(new Contorno(ln2));
			cc.Add(new Contorno(ln1));
			cc.Add(new Contorno(ar1));
			cc.Validate();

			Point2D po = new Point2D(1.5, -1);

			Line2D ray;
			ray = new Line2D(po, p1 + new Point2D(0.05,0));
			ray.Normalize();
			List<Intersection> intersezioni = cc.TrovaIntersezioniPositive(ray);

			#pragma warning disable
			int tmp;
			tmp = 1;
			#pragma warning restore

			}
Exemplo n.º 26
0
		/// <summary>
		/// Zoom in
		/// </summary>
		/// <returns></returns>
		public bool ZoomIn()
			{
			if (fattoreZoom <= 1.0)						// Se fattore errato, esce
				return false;
			centro = (P1 + P2) / 2.0;						// Punto centrale
			P1 = centro + (P1 - centro) / fattoreZoom;
			P2 = centro + (P2 - centro) / fattoreZoom;
			RicalcolaFinestra();
			return true;
			}
Exemplo n.º 27
0
		private void test7TrasfoToolStripMenuItem_Click(object sender, EventArgs e)
			{
			Matrix A = new Matrix(3,3);
			A.Set(0,0,1);
			A.Set(0,1,2);
			A.Set(0,2,3);
			A.Set(1,0,4);
			A.Set(1,1,5);
			A.Set(1,2,6);
			A.Set(2,0,7);
			A.Set(2,1,8);
			A.Set(2,2,9);

			Matrix B = new Matrix(3,2);
			B.Set(0,0,1);
			B.Set(0,1,0);
			B.Set(1,0,-1);
			B.Set(1,1,2);
			B.Set(2,0,0);
			B.Set(2,1,1);
			Matrix C = A*B;
			Matrix D = B*A;
			MessageBox.Show("A=\n" + A.ToString());
			MessageBox.Show("B=\n" + B.ToString());
			MessageBox.Show("C=\n" + C.ToString());
			MessageBox.Show("D=\n" + D.ToString());

			Point2D p1 = new Point2D(10,5);
			MessageBox.Show("p1=\n" + p1.ToString());

			Transform2D tr;
			Transform2D t1 = Transform2D.Traslazione(100,-200);
			Transform2D t2 = Transform2D.Traslazione(-10,-20);
			tr = t1 + t2;	// Combinazione di trasformazioni
			MessageBox.Show("tr=\n" + tr.ToString());

			Matrix h**o = Transform2D.Convert(p1);
			MessageBox.Show("h**o=\n" + h**o.ToString());

			Point2D p2 = Transform2D.Convert(h**o);
			MessageBox.Show("p2=\n" + p2.ToString());

			Point2D p3 = tr.Transform(p1);
			MessageBox.Show("p3=\n" + p3.ToString());

			Transform2D rot = Transform2D.Rotazione(20,false);
			Transform2D tra = Transform2D.Traslazione(100,0);

			Transform2D rot_tra = rot + tra;
			Transform2D tra_rot = tra + rot;

			Point2D p0 = new Point2D(0,0);
			rot_tra.Transform(p0);

			MessageBox.Show(p0 + " rotXtra\n" + rot_tra.Transform(p0));
			MessageBox.Show(p0 + " traXrot\n" + tra_rot.Transform(p0));

			#pragma warning disable
			int tmp;
			tmp = 1;
			#pragma warning restore
			}
Exemplo n.º 28
0
		/// <summary>
		/// Pan a destra
		/// </summary>
		/// <returns></returns>
		public bool PanDx()
			{
			if (fattorePan <= 0.0)						// Se fattore errato, esce
				return false;
			P1 = P1 + panx * dX * fattorePan;
			P2 = P2 + panx * dX * fattorePan;
			RicalcolaFinestra();
			return true;
			}
Exemplo n.º 29
0
		private void aggiungiToolStripMenuItem_Click(object sender, EventArgs e)
			{
			displayList.Clear();

			Point2D ax1, ax2, ax3;										// Punti assi
			ax1 = new Point2D(0,0);
			ax2 = new Point2D(finestra.P2.x,0);
			ax3 = new Point2D(0,finestra.P2.y);


			(new Line2D(ax1,ax2)).Display(displayList,3);				// Assi
			(new Line2D(ax1,ax3)).Display(displayList,3);

			this.gradiprimi.Visible=true;
			this.percdiam.Visible=true;

			FormTrasfo ft = new FormTrasfo();
			ft.ShowDialog();
			
			Transform2D tr = Transform2D.Rotazione(ft.r) + Transform2D.Traslazione(ft.x,ft.y);
			//Transform2D tr = Transform2D.Traslazione(Math.Max(lente.ET,lente.CT),0.0);

			CorpoOttico corpolente = lente.CreaCorpoOttico(tr);
			MaterialeOttico ambiente = new MaterialeOttico("vuoto", 1.0);
			completo.Add(corpolente.Materiale);
			completo.Add(ambiente);
			completo.Add(corpolente);
			
			//((CorpoOttico)amb.GetOggetto("lente")).Display(displayList,0);	//lenteIn.Display(displayList,0);
			completo.Display(displayList,0);
		
			//corpolente.Display(displayList,0);

			

			Invalidate();

			}
Exemplo n.º 30
0
		/// <summary>
		/// Pan in giu`
		/// </summary>
		/// <returns></returns>
		public bool PanGiu()
			{
			if (fattorePan <= 0.0)						// Se fattore errato, esce
				return false;
			P1 = P1 - pany * dY * fattorePan;
			P2 = P2 - pany * dY * fattorePan;
			RicalcolaFinestra();
			return true;
			}