This is a Java Program to compute cross product of two vectors. In mathematics, the cross product or vector product is a binary operation on two vectors in three-dimensional space. It results in a vector that is perpendicular to both and therefore normal to the plane containing them.
Here is the source code of the Java Program to Compute Cross Product of Two Vectors. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
//This is a java program to find the cross product of two vectors import java.util.Random; public class Cross_Product { public static void main(String args[]) { Random random = new Random(); int u1, u2, u3, v1, v2, v3; u1 = random.nextInt(10); u2 = random.nextInt(10); u3 = random.nextInt(10); v1 = random.nextInt(10); v2 = random.nextInt(10); v3 = random.nextInt(10); int uvi, uvj, uvk; uvi = u2 * v3 - v2 * u3; uvj = v1 * u3 - u1 * v3; uvk = u1 * v2 - v1 * u2; System.out.println("The cross product of the 2 vectors \n u = " + u1 + "i + " + u2 + "j + " + u3 + "k and \n v = " + u1 + "i + " + u2 + "j + " + u3 + "k \n "); System.out.println("u X v : " + uvi + "i +" + uvj + "j+ " + uvk + "k "); } }
Output:
$ javac Cross_Product.java $ java Cross_Product The cross product of the 2 vectors u = 3i + 8j + 9k and v = 3i + 8j + 9k u X v : -2i +48j+ -42k
Related posts:
Java Program to Solve Travelling Salesman Problem for Unweighted Graph
Getting Started with Forms in Spring MVC
Converting a Stack Trace to a String in Java
How to Replace Many if Statements in Java
Java Program to Implement Ternary Search Tree
Cài đặt và sử dụng Swagger UI
Java Program to Implement Singly Linked List
Java Program to Construct K-D Tree for 2 Dimensional Data
Java Program to Implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for Elements Fro...
Java Program to Generate All Pairs of Subsets Whose Union Make the Set
String Initialization in Java
Hướng dẫn tạo và sử dụng ThreadPool trong Java
Converting String to Stream of chars
Java Map With Case-Insensitive Keys
Guide to the Volatile Keyword in Java
Introduction to Spring Method Security
Performance Difference Between save() and saveAll() in Spring Data
Spring Boot Change Context Path
Injecting Prototype Beans into a Singleton Instance in Spring
Spring Boot - Rest Controller Unit Test
Truyền giá trị và tham chiếu trong java
Java Program to Implement Adjacency List
Java Program to Implement Fibonacci Heap
Java Program to Implement Selection Sort
Java Program to Check if an UnDirected Graph is a Tree or Not Using DFS
Spring Security – Reset Your Password
Reactive WebSockets with Spring 5
Setting the Java Version in Maven
Java Program to Check if a Given Binary Tree is an AVL Tree or Not
Java Program to Find a Good Feedback Edge Set in a Graph
Comparing Strings in Java
Form Validation with AngularJS and Spring MVC