JAVA: Distance forward intersection algorithm GUI implementation

Source: Internet
Author: User
Tags acos 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

Distance to the front intersection. Java

Package Text;import Java.awt.*;import Java.awt.event.*;import java.math.*;import javax.swing.*;import javax.swing.border.border;/** * A frame with sample text Components. */public class distance forward Rendezvous extends jframe{& nbsp;  public static final int textarea_rows = 20;   public static final int textarea_columns = 40;    Public Distance forward intersection ()    {      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");      JPanel northpanel = new JPanel ();      final JTextField DAP = new JTextField ("200");      final JTextField DBP = new JTextField (" $ ");      final JTextField DCP = new JTextField ("$");      JPanel Westpanel = new JPanel ();       JLabel pic= New JLabel ();      Pic.seticon (New ImageIcon ("g:/workplace/ Distance forward intersection/2.png "));      westpanel.add (pic);      GetContentPane ( ). Add (Westpanel, borderlayout.west);      JPanel northPane2 = new JPanel ();    //distance from the front intersection           northpane2.setlayout (New GridLayout (3, 8));           Northpane2.add (New JLabel ("a_x:", Swingconstants.center));           Northpane2.add (a_x);           Northpane2.add (New JLabel ("A_y:", Swingconstants.center));   &NBsp;       Northpane2.add (a_y);           Northpane2.add (New JLabel ("b_x:", Swingconstants.center));           Northpane2.add (b_x);          Northpane2.add (New JLabel ("B_Y: ", Swingconstants.center));          NorthPane2.add (B_Y);           Northpane2.add (New JLabel ("c_x:", Swingconstants.center));           Northpane2.add (c_x);           Northpane2.add (New JLabel ("C_y:", Swingconstants.center));           Northpane2.add (c_y);          Northpane2.add (New JLabel ("DAP:", Swingconstants.center));           Northpane2.add (DAP);          Northpane2.add (New JLabel ("DBP:", Swingconstants.center));          NorthPane2.add (DBP);           Northpane2.add (New JLabel ("DCP:", Swingconstants.center));           Northpane2.add (DCP);      Border etched = Borderfactory.createetchedborder ();      Border titled = Borderfactory.createtitledborder (Etched, "distance ahead Rendezvous");      Northpanel.setborder (titled);      Getcontentpane (). Add (NorthPane2, 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 Jpane L ();      JButton Insertbutton = new JButton ("Calculate p-point coordinates");      Insertbutton.addactionlistener (New ActionListener ()          {             public void actionperformed (ActionEvent event)              {          //coordinates 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 d_ap=double.valueof (Dap.gettext ()). Doublevalue ();                double D_BP= Double.valueof (Dbp.gettext ()). Doublevalue ();                 double d_cp=double.valueof (Dcp.gettext ()). Doublevalue ();                          //a, B, P                  double d_ab=math.sqrt ( Math.pow ((X1-X2), 2) +math.pow ((Y1-y2), 2);                 doubleα_bap=math.acos ((D_AB*D_AB+D_AP*D_AP-D_BP*D_BP)/(2*D_AB*D_AP));                 //doubleα_abp=math.acos (d_ab*d_ab+d_bp*d_ BP-D_AP*D_AP)/2*d_ab*d_bp);                doubleα_ab=90-math.atan (Math.Abs (y2-y1)/math.abs (x2-x1));                 Doubleα_AP=α_AB-α_BAP;                 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α_cbp=math.acos ((D_BC*D_BC+D_BP*D_BP-D_CP*D_CP)/(2*D_BC*D_BP));                 //doubleα_bcp=math.acos ((D_BC*D_BC+D_CP*D_CP-D_BP*D_BP)/2*D_BC *D_CP);                doubleα_bc=90- Math.atan (Math.Abs (y2-y3)/math.abs (x2-x3));                 Doubleα_BP=α_BC-α_CBP;                 double Xp2=x1+d_bp*math.cos (Α_BP);            &NBsp;    double Yp2=y1+d_bp*math.sin (Α_BP);                                   textarea.append ("===== distance ahead Rendezvous = = =" + "\ n" + "reference value 1:" + "(" +xp1+ "," +yp1+ ")"                          +   "\ n" + "reference value 2:" + "(" +xp2+ "," +yp2+ ")"                          +  "\ n" + "error distance approx:" +math.round (Miss (XP1,YP1 , XP2,YP2)) + "M");           }             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 Distance forward rendezvous ();                Frame.settitle ("Distance ahead Rendezvous");                frame.setdefaultcloseoperation (jframe.exit_on_close);                frame.setvisible (True);            }        });  }} 

Iii. Results of operation



Download: Distance forward Rendezvous algorithm Java project package



JAVA: Distance forward 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.