Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- class Vector {
- float x,y;
- Vector (float x, float y) {
- x = x;
- y = y;
- }
- public static Vector Add (Vector v1, Vector v2) {
- float nx,ny;
- nx = v1.x + v2.x;
- ny = v1.y + v2.y;
- return new Vector(nx,ny);
- }
- public static Vector Sub (Vector v1, Vector v2) {
- float nx,ny;
- nx = v1.x - v2.x;
- ny = v1.y - v2.y;
- return new Vector(nx,ny);
- }
- public static Vector Mul (Vector v1, Vector v2) {
- float nx,ny;
- nx = v1.x * v2.x;
- ny = v1.y * v2.y;
- return new Vector(nx,ny);
- }
- public static Vector MulByNum (Vector v1, float n) {
- float nx,ny;
- nx = v1.x * n;
- ny = v1.y * n;
- return new Vector(nx,ny);
- }
- public static Vector Div (Vector v1, int n) {
- return Vector.MulByNum(v1,1/n);
- }
- public static Vector Neg (Vector v1,) {
- float nx,ny;
- nx = - v1.x ;
- ny = - v1.y ;
- return new Vector(nx,ny);
- }
- public static float Abs (Vector v1) {
- return Math.abs(v1.x) + Math.abs(v1.y);
- }
- public static void print(Vector v) {
- System.out.println( "[" + v.x + ", " +v. y+"]");
- }
- }
- public class Main {
- public static void main(String[] args) {
- final int i = 2;
- Vector v1 = new Vector (i , 4);
- Vector v2 = new Vector (1 , 4);
- Vector v3 = Vector.Add(v1,v2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement