JAVA: Perspective intersection algorithm GUI implementation

Source: Internet
Author: User
Tags cos gettext pow sin

Compilation Environment:

Operating system: Win8.1 64-bit

IDE platform: Visual Studio Ultimate

First, principle and procedure



Second, the Code implementation

Angle ahead intersection. java

Package Text;import Java.awt.*;import Java.awt.event.*;import java.math.*;import javax.swing.*;import Javax.swing.border.border;public class Angle forward Rendezvous extends jframe{   public static final int textarea_rows = 20;&nbs p;  public static final int textarea_columns = 40;    Public Angle Forward Rendezvous ()    {      final JTextField a_x = new JTextField ("37477") ;      final JTextField a_y = new JTextField ("16307");      final JTextField b_x = new JTextField ("37327");      final JTextField b_y = new JTextField ("16078"); nbsp;         final JTextField c_x = new JTextField ("37163");       final JTextField c_y = new JTextField ("16046");      final jtextfieldα1 = new Jtext Field ("40°41");      final jtextfieldβ1 = new JTextField ("75°19");       final jtextfieldα2 = new JTextField ("58°11");      final jtextfieldβ2 = new JTextField ("69°6"); &n bsp;     JPanel Northpanel = new JPanel ();      final JTextField DAP = new J TextField ();      final JTextField DBP = new JTextField ();      JPanel Westpanel = new JPanel ();      JLabel pic= New JLabel ();      Pic.seticon (New ImageIcon ("g:/workplace/Angle Forward Rendezvous/1.png"));      westpanel.add (pic);       Getcontentpane (). Add (Westpanel, borderlayout.west);//angle forward intersection        Northpanel.setlayout (New GridLayout (2));      Northpanel.add (New JLabel ("A_x:", Swingconstants.center));      Northpanel.add (a_x);      Northpanel.add (New JLabel ("A_y:", Swingconstants.center));       Northpanel.add (a_y);      Northpanel.add (New JLabel ("b_x:", Swingconstants.center ));      Northpanel.add (b_x);      NorthPanel.add (New JLabel ("B _y: ", Swingconstants.center));      Northpanel.add (b_y);      Northpanel.add (New JLabel ("c_x:", Swingconstants.center));      Northpanel.add (C_X);       Northpanel.add (New JLabel ("C_y:", Swingconstants.center));       Northpanel.add (c_y);      Northpanel.add (New JLabel ("Alpha 1:", Swingconstants.center)) ;      Northpanel.add (α1);      NorthPanel.add (New JLabel ("Beta 1:" , Swingconstants.center));      Northpanel.add (β1);      Northpanel.add (New JLabel ("Alpha 2:", Swingconstants.center));      Northpanel. Add (α2);      Northpanel.add (New JLabel ("Beta 2:", Swingconstants.center));       Northpanel.add (β2);      Border etched = Borderfactory.createetchedborder ();      Border titled = Borderfactory.createtitledborder (Etched, "angle ahead Rendezvous");      Northpanel.setborder (titled);      Getcontentpane (). Add (Northpanel, Borderlayout.north);             Final JTextArea TextArea = new JTextArea (20,40);      jscrollpane scrollPane = new Jscrol Lpane (TextArea);      Getcontentpane (). Add (ScrollPane, Borderlayout.center);       //Add button to append text into the text area      JPanel Southpanel = New JPanel ();      JButton Insertbutton = new JButton ("Calculate p-point coordinates");       inSertbutton.addactionlistener (New ActionListener ()          {             public void actionperformed (ActionEvent event)              {         / /coordinate initialization                 double x1= Double.valueof (A_x.gettext ()). Doublevalue ();                 double y1=double.valueof (A_y.gettext ()). Doublevalue ();                 double x2=double.valueof (B_x.gettext ()). Doublevalue ();                 double y2=double.valueof (b_ Y.gettext ()). Doublevalue ();                double X3=doUble.valueof (C_x.gettext ()). Doublevalue ();                 double y3=double.valueof (C_y.gettext ()). Doublevalue ();                                 doubleα_1=convert (Α1.gettext ());                 doubleβ_1=convert (Β1.gettext ());                 doubleα_2=convert (Α2.gettext ());                 doubleβ_2=convert (Β2.gettext ());                          //a, B, P                     &NBsp;double d_ab=math.sqrt (Math.pow (X1-X2), 2) +math.pow ((Y1-y2), 2));                 double d_ap=d_ab*math.sin (β_1)/math.sin (α_1+β_1);                 doubleα_ab=90-math.atan (Math.Abs (y2-y1)/ Math.Abs (x2-x1));                doubleα_ ap=α_ab-α_1;                double XP1=X1+D _ap*math.cos (Α_AP);                Double Yp1=y1+d_ap*math.sin (Α_AP);                         //b, C, p                 double d_bc=math.sqrt (Math.pow (X3-X2), 2) +math.pow ((Y3-y2), 2));                 double d_bp=d_bc*math.sin (β_2)/ Math.sin (α_2+β_2);                doubleα_ Bc=math.atan (Math.Abs (y2-y3)/math.abs (x2-x3));                Doubleα_BP=α_BC-α_2;                 double Xp2=x2+d_bp*math.cos (Α_BP);                 double yp2=y1+d_bp*math.sin (Α_BP);                                  textarea.append ("===== angle forward intersection = = =" + "\ n" + "reference value 1:" + "(" +xp1+ "," +yp1+ ")"                           +  "\ n" + "reference value 2:" + "(" +xp2+ "," +yp2+ ")"                          +  "\ n" + "error distance approx:" +math.round (Miss ( XP1,YP1,XP2,YP2) + "M");                // Textarea.append ("Test:" +β_2);           }             public double Miss (double xp1,double yp1,double xp2,double YP2 ) {                return math.sqrt (Math.pow ((XP1-XP2), 2) +math.pow ((YP1-YP2), 2));           }             public double convert (String input) {                 double a=double.valueof (Input.split ("°") [0]). Doublevalue ();                 Double b=double.valueof (Input.split ("°") [1].split ("'") [0]). Doublevalue ();                 return a+b/60;            }        });     Add (Insertbutton , Borderlayout.south);      pack ();  }}

test.java

Package Text;import Java.awt.*;import javax.swing.*;p ublic class test{   public static void Main (string[] args )    {      Eventqueue.invokelater (New Runnable ()           {            public void run ()              {                JFrame frame = new angle Forward rendezvous ();                frame.settitle ("Angle Ahead Rendezvous");                frame.setdefaultcloseoperation (jframe.exit_on_close);                frame.setvisible (True);            }        });  }} 

Iii. Results of operation





JAVA: Perspective intersection algorithm GUI implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.