JAVA: Distance to the rear intersection algorithm GUI implementation

Source: Internet
Author: User
Tags acos cos gettext sin

Compilation Environment:

Operating system: Win8.1 64-bit

IDE platform: Visual Studio Ultimate

First, the principle

The distance s1,s2,s3 is observed on the point p to be measured, and the plane coordinates of P are determined:




Second, the Code implementation

Distance to the rear intersection. java

Package Text;import Java.awt.*;import Java.awt.event.*;import java.math.*;import javax.swing.*;import   Javax.swing.border.border;public class distance rear Rendezvous extends jframe{public static final int textarea_rows = 20;    public static final int textarea_columns = 40;      Public distance rear 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");      Final JTextField c_x = new JTextField ("37163");      Final JTextField c_y = new JTextField ("16046");      Final JTextField s_1 = new JTextField ("200");      Final JTextField s_2 = new JTextField ("200");      Final JTextField S_3 = new JTextField ("200");      JPanel Northpanel = new JPanel ();      JPanel Westpanel = new JPanel ();      JLabel pic= new JLabel ();      Pic.seticon (New ImageIcon ("g:/workplace/distance from the rear intersection/4.png"));      Westpanel.add (pic); Getcontentpane (). Add (Westpanel, BorderLayout.WEST);    JPanel northPane2 = new JPanel ();          Distance to the front intersection northpane2.setlayout (New GridLayout (3, 4));          Northpane2.add (New JLabel ("a_x:", Swingconstants.center));          Northpane2.add (a_x);          Northpane2.add (New JLabel ("A_y:", Swingconstants.center));          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 ("S1:", Swingconstants.center));          Northpane2.add (S_1);          Northpane2.add (New JLabel ("S2:", Swingconstants.center));          Northpane2.add (s_2);          Northpane2.add (New JLabel ("S3:", Swingconstants.center));  Northpane2.add (S_3);    Border etched = Borderfactory.createetchedborder ();      Border titled = Borderfactory.createtitledborder (Etched, "distance to the rear rendezvous");      Northpanel.setborder (titled);            Getcontentpane (). Add (NorthPane2, Borderlayout.north);      Final JTextArea TextArea = new JTextArea (20,40);      JScrollPane ScrollPane = new JScrollPane (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)            {//coordinates initialize 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 s1=double.valueof (S_1.gettext ()). Doublevalue ();            Double s2=double.valueof (S_2.gettext ()). Doublevalue ();                      Double s3=double.valueof (S_3.gettext ()). Doublevalue ();            A, B, P Double d_ab=math.sqrt (Math.pow (X1-X2), 2) +math.pow ((Y1-y2), 2));            Doubleα_ab=math.acos ((D_AB*D_AB+S1*S1-S2*S2)/(2*D_AB*S1));            Doubleα_1=math.atan (Math.Abs (y2-y1)/math.abs (x2-x1));            Doubleα_2=α_ab-α_1;            Double Xp1=x1+s1*math.cos (α_2);                      Double Yp1=y1-s1*math.sin (α_2);            B, C, P Double d_bc=math.sqrt (Math.pow (X3-X2), 2) +math.pow ((Y3-y2), 2));            Doubleα_bc=math.acos ((D_BC*D_BC+S2*S2-S3*S3)/(2*D_BC*S2));            Doubleα_3=math.atan (Math.Abs (y3-y2)/math.abs (x3-x2));            Doubleα_4=α_bc-α_3;            Double Xp2=x1+s1*math.cos (α_4); Double Yp2=y1-s1*maTh.sin (Α_4); Textarea.append ("===== distance from the rear 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");            Textarea.append ("Test:" +β_2); } public double Miss (double xp1,double yp1,double xp2,double YP2) {return math.sqrt (Math.pow (XP1-XP            2), 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 from the rear intersection ();               Frame.settitle ("distance from the rear intersection");               Frame.setdefaultcloseoperation (jframe.exit_on_close);               Frame.setvisible (True);}}         );}   }

Iii. Results of operation



Download: Distance from the rear Rendezvous algorithm Java Project package




JAVA: Distance to the rear 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.