import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
class MyVector {
private double x;
private double y;
public MyVector(double x, double y) {
this.x = x;
this.y = y;
}
public double vLength() {
double tempLen
= Math.
sqrt(x
*x
+ y
*y
); double newLen
= new BigDecimal(tempLen
).
setScale(3, RoundingMode.
UP).
doubleValue(); return newLen;
}
public static MyVector sum(MyVector a, MyVector b) {
return new MyVector(a.x + b.x, a.y + b.y);
}
public static MyVector sub(MyVector a, MyVector b) {
return new MyVector(a.x - b.x, a.y - b.y);
}
public static MyVector mul(MyVector a, double c) {
return new MyVector(a.x * c, a.y * c);
}
public static double scalar(MyVector a, MyVector b) {
double tempScalar = a.x * b.x + a.y * b.y;
double newScalar
= new BigDecimal(tempScalar
).
setScale(3, RoundingMode.
UP).
doubleValue(); return newScalar;
}
public static double cos(MyVector a, MyVector b) {
double tempCos = scalar(a, b) / (a.vLength() * b.vLength());
double newCos
= new BigDecimal(tempCos
).
setScale(3, RoundingMode.
UP).
doubleValue(); return newCos;
}
public static double projection(MyVector a, MyVector b) {
double tempProj = scalar(a, b) / b.vLength();
double newProj
= new BigDecimal(tempProj
).
setScale(5, RoundingMode.
UP).
doubleValue(); return newProj;
}
double eps = 0.0001;
if (b.x == 0 || b.y == 0) {
}
return (Math.
abs(a.
x / b.
x - a.
y / b.
y) < eps
); }
public static double vecProduct(MyVector a, MyVector b) {
double tempProduct
= a.
vLength() * b.
vLength() * Math.
sqrt(1 - cos
(a,b
) * cos
(a,b
)); double newProduct
= new BigDecimal(tempProduct
).
setScale(5, RoundingMode.
UP).
doubleValue(); return newProduct;
}
return new String(x
+ " ; " + y
); }
}
class Main {
public static void main
(String[] args
) { MyVector a = new MyVector(10.1,-19);
MyVector b = new MyVector(13,-2.09);
System.
out.
println(a.
vLength()); System.
out.
println(b.
vLength()); System.
out.
println(MyVector.
sum(a,b
)); System.
out.
println(MyVector.
sub(a,b
)); System.
out.
println(MyVector.
mul(a,
8)); System.
out.
println(MyVector.
scalar(a,b
)); System.
out.
println(MyVector.
cos(a,b
)); System.
out.
println(MyVector.
projection(a,b
)); System.
out.
println(MyVector.
isCollinear(a,b
)); System.
out.
println(MyVector.
vecProduct(a,b
)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLm1hdGguQmlnRGVjaW1hbDsKaW1wb3J0IGphdmEubWF0aC5Sb3VuZGluZ01vZGU7CgpjbGFzcyBNeVZlY3RvciB7Cglwcml2YXRlIGRvdWJsZSB4OwoJcHJpdmF0ZSBkb3VibGUgeTsKCXB1YmxpYyBNeVZlY3Rvcihkb3VibGUgeCwgZG91YmxlIHkpIHsKCQl0aGlzLnggPSB4OyAKCQl0aGlzLnkgPSB5OwoJfQoJcHVibGljIGRvdWJsZSB2TGVuZ3RoKCkgewoJCWRvdWJsZSB0ZW1wTGVuID0gIE1hdGguc3FydCh4KnggKyB5KnkpOwoJCWRvdWJsZSBuZXdMZW4gPSBuZXcgQmlnRGVjaW1hbCh0ZW1wTGVuKS5zZXRTY2FsZSgzLCBSb3VuZGluZ01vZGUuVVApLmRvdWJsZVZhbHVlKCk7CgkJcmV0dXJuIG5ld0xlbjsKCX0KCXB1YmxpYyBzdGF0aWMgTXlWZWN0b3Igc3VtKE15VmVjdG9yIGEsIE15VmVjdG9yIGIpIHsKCQlyZXR1cm4gbmV3IE15VmVjdG9yKGEueCArIGIueCwgYS55ICsgYi55KTsKCX0KCXB1YmxpYyBzdGF0aWMgTXlWZWN0b3Igc3ViKE15VmVjdG9yIGEsIE15VmVjdG9yIGIpIHsKCQlyZXR1cm4gbmV3IE15VmVjdG9yKGEueCAtIGIueCwgYS55IC0gYi55KTsKCX0KCXB1YmxpYyBzdGF0aWMgTXlWZWN0b3IgbXVsKE15VmVjdG9yIGEsIGRvdWJsZSBjKSB7CgkJcmV0dXJuIG5ldyBNeVZlY3RvcihhLnggKiBjLCBhLnkg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