JAVA: GUI Implementation of the Forward Intersection Algorithm

Source: Internet
Author: User
Tags acos

JAVA: GUI Implementation of the Forward Intersection Algorithm

Compiling environment:

Operating System: Win8.1 64-bit

IDE platform: Visual Studio 2013 Ultimate

I. principles and steps


Ii. Code Implementation

Forward rendezvous. 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: The frontend intersection is extends JFrame {public static final int TEXTAREA_ROWS = 20; public static final int TEXTAREA_COLUMNS = 40; public distance from frontend 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 "); JPanel northPanel = new JPanel (); final JTextField DAP = new JTextField ("200"); final JTextField DBP = new JTextField ("200 "); final JTextField DCP = new JTextField ("200"); JPanel WestPanel = new JPanel (); JLabel pic = new JLabel (); pic. setIcon (new ImageIcon ("G:/workplace/Forward Intersection/2.png"); WestPanel. add (pic); getContentPane (). add (WestPanel, BorderLayout. WEST); JPanel northPane2 = new JPanel (); // distance from the frontend 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); 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, "Forward Intersection"); 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 (" pp "); insertButton. addActionListener (new ActionListener () {public void actionreceivmed (ActionEvent event) {// initialize the Double X1 = Double coordinate. 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 α _ white = 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-α _ white; Double XP2 = X1 + D_BP * Math. cos (α _ BP); Double YP2 = Y1 + D_BP * Math. sin (α _ BP); textArea. append ("= Forward Intersection =" + "\ n" + "reference value 1:" + "(" + XP1 + ", "+ YP1 +") "+" \ n "+" reference value 2: "+" ("+ XP2 +", "+ YP2 + ") "+" \ n "+" error distance: "+ Math. round (miss (XP1, YP1, XP2, YP2) + "meter");} 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. *; public class Test {public static void main (String [] args) {EventQueue. invokeLater (new Runnable () {public void run () {JFrame frame = new distance Forward Intersection (); frame. setTitle ("forward corner"); frame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); frame. setVisible (true );}});}}

Iii. Running results



Download: JAVA project package for Forward Intersection Algorithm



Related Article

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.