From b0324289066876915efb84a133eca039d8e8c8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 17 Dec 2023 23:17:03 +0100 Subject: =?UTF-8?q?=C5=A1ola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\305\241ola/p1/dn/6/Premica.java" | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "\305\241ola/p1/dn/6/Premica.java" (limited to 'šola/p1/dn/6/Premica.java') diff --git "a/\305\241ola/p1/dn/6/Premica.java" "b/\305\241ola/p1/dn/6/Premica.java" new file mode 100644 index 0000000..2d2ec4e --- /dev/null +++ "b/\305\241ola/p1/dn/6/Premica.java" @@ -0,0 +1,50 @@ +import java.util.*; +public class Premica { + private double k; + private double n; + public Premica(double k, double n) { + this.k = k; + this.n = n; + } + public double vrniK() { + return this.k; + } + public double vrniN() { + return this.n; + } + public String toString() { + return String.format(Locale.ROOT, "y = %.2f x + %.2f", this.k, this.n); + } + public Tocka tockaPriX(double x) { + return new Tocka(x, this.k*x+this.n); + } + public static Premica skoziTocko(double k, Tocka t) { + return new Premica(k, t.vrniY()-k*t.vrniX()); + } + + public Premica vzporednica(Tocka t) { + return skoziTocko(this.k, t); + } + + public Premica pravokotnica(Tocka t) { + return skoziTocko(-1/this.k, t); + } + + public Tocka presecisce(Premica p, double epsilon) { + if (Math.abs(this.k - p.vrniK()) < epsilon) + return null; + return tockaPriX((this.n-p.vrniN())/(p.vrniK()-this.k)); + } + public Tocka projekcija(Tocka t) { + return presecisce(pravokotnica(t), 0); + } + public double razdalja(Tocka t) { + return t.razdalja(projekcija(t)); + } + public double razdaljaOdIzhodisca() { + return Tocka.izhodisce().razdalja(projekcija(Tocka.izhodisce())); + } + public double razdalja(double n) { + return new Premica(this.k, n).razdalja(tockaPriX(0)); + } +} -- cgit v1.2.3