RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

question about c# gestion of 180 degree angles

Vitremer

Sorceror
with visual studio IDE, i try to calculate the degree value of angle created by intersection of two lines.
but the response is always the angle value bigger than 90 degree...why ?
i post an example of code
Code:
                        point = new Point(m_Basion[0], m_Basion[1]);
                        point2 = new Point(m_Nasion[0], m_Nasion[1]);
                        int y1 = m_Nasion[1];
                        int x1 = m_Nasion[0];
                        int y2 = m_Basion[1];
                        int x2 = m_Basion[0];
                        float m = (float)(y2 - y1) / (float)(x2 - x1);

                        Point point3 = new Point(m_Pterigomascellare[0], m_Pterigomascellare[1]);
                        Point point4 = new Point(m_Gnathion[0], m_Gnathion[1]);
                        int y3 = m_Gnathion[1];
                        int x3 = m_Gnathion[0];
                        int y4 = m_Pterigomascellare[1];
                        int x4 = m_Pterigomascellare[0];
                        float m1 = (float)(y4 - y3) / (float)(x4 - x3);

/* calcolare il punto di intersezione tra le rette N-Ba e PTM-Gn
* di modo che poi viene calcolato l'angolo compreso tra BaPTMGn
* che è il metodo esatto
*/
                        int q3 = y1 - (int)(m * x1);//calcola il termine noto della retta passante per Pg e per N
                        Console.WriteLine("il valore di q3 è {0}", q3);
                        int q4 = y3 - (int)(m1 * x3);
                        int x5 = (int)((q3 - q4) / (m1 - m));// mi calcola la x dell'intersezione
                        //tra le due rette
                        int y5 = (int)(m * x5 + q3);// mi calcola la y della stessa intersezione
                        Console.WriteLine("il valore di x5 è {0} e y5 {1}", x5, y5);
                        Point point5 = new Point(x5, y5);//questo è il punto del Gonion costruito

                        float m2 = (float)(y3 - y5) / (float)(x3 - x5);
                        float m3 = (float)(y2 - y5) / (float)(x2 - x5);

                        float diffmm1 = m3 - m2;
                        float sommmm1 = 1 + (m3 * m2);
                        float tangenteAlpha = diffmm1 / sommmm1;
                        float angoloinRadianti = (float)(Math.Atan(tangenteAlpha));
                        Console.WriteLine("il valore di m1 - m è {0}", diffmm1);
                        Console.WriteLine("il valore di 1+(m*m1) è {0}", sommmm1);
                        Console.WriteLine("il valore di tangentalpha è {0}", tangenteAlpha);
                        //    float angoloinRadianti = (float)Math.Atan2(m1, m);// questo metodo funziona però y e x non devono essere le coordinate di un punto bensì i coeff angolari di due rette incidenti
                        float angoloinGradi = (float)((angoloinRadianti) * (180 / Math.PI));// converte l'angolo dai radianti ai gradi esadecimali
                        float angolo = Math.Abs(angoloinGradi); // restituisce il valore assoluto dell'angolo
                        //interposto minore di 90°...considerare che due rette incidenti hanno
                        //sempre diviso il piano in 4 angoli uguali a due a due e solo in caso
                        //di rette perpendicolari avremo 4 angoli di 90°, altrimenti due dei quattro
                        // saranno acuti e gli altri due ottusi

                        float angoloCalcolato = 180.00F - angolo;//in questo modo ottengo
                        //l'angolo effettivo interposto dalla parte ottusa

                        Console.WriteLine("l'angolo dell'asse facciale è in gradi {0} {1} ", angolo, angoloCalcolato );

now you imagine two lines in a cartesian plane, the angles that create are two, of different amplitude...i want to obtain exactly the interposed area "N-Ba ^ PTM-Gn", instead "angolo" value is always < 90°.....but why ?

excuse for my english
 

Vitremer

Sorceror
excuse me, thank for you help but don't run.. i try to explain with an image
link

Uploaded with ImageShack.us

in this case i've obtain the corrected value. that is an angle > 90 degree.

then the other possible case


Uploaded with ImageShack.us

Well, in THIS case i obtain NOT the value i need, but the value of the part of angle that is > 90 degree....why ?

excuse me but the original line of my code was :
Code:
                        float angoloCalcolato = 90.00F - angolo;//in questo modo ottengo
                        //l'angolo effettivo interposto dalla parte ottusa

thanks to all
 

Jeff

Lord
Naming your values in Spanish doesn't help us English speakers ... but the equation i gave you will tell you what you need to know. Also, are you sure its not a radians to degrees issue? Radians are measured 0 -> 1 for the circumference of a circle, where as degrees are 0 -> 360.
 
Top