01 Geometry Java CS

background image

Java:

CS:

//Geometria.java
import java.lang.*;

class Punkt2D {

public double x, y;
}

class Linia2D {

public Punkt2D p1=new Punkt2D(),
p2=new Punkt2D();

public void skaluj(double d) {

Punkt2D c = new Punkt2D();
c.x = (p1.x+p2.x)/2;

c.y = (p1.y+p2.y)/2;
p1.x = c.x+(p1.x-c.x)* d;

p1.y = c.y+(p1.y-c.y)* d;
p2.x = c.x+(p2.x-c.x)* d;

p2.y = c.y+(p2.y-c.y)* d;
}

public void przesun(Punkt2D p) {

p1.x += p.x; p1.y += p.y;
p2.x += p.x; p2.y += p.y;

}

public boolean rownolegla(Linia2D l) {
double dx1 = l.p2.x- l.p1.x,

dy1 = l.p2.y- l.p1.y,
dx2 = p2.x-p1.x,

dy2 = p2.y-p1.y;
return Math.abs(dx1*dy2-dy1*dx2)<0.0001?

true:false;
}

Linia2D lustroOX() {

Linia2D l = new Linia2D();
l.p1.x = p1.x; l.p1.y = -p1.y;

l.p2.x = p2.x; l.p2.y = -p2.y;
return l;

}
}

public class Geometria {

public static void main(String args[]) {
Linia2D l1 = new Linia2D(),

l2 = new Linia2D();
Punkt2D p1 = new Punkt2D();

l1.p1.x = l2.p1.x = 0;
l1.p1.y = l2.p1.y = 0;

l1.p2.x = l2.p2.x = 1;
l1.p2.y = l2.p2.y = 1;

p1.x = 1; p1.y = 2;
l2.skaluj(2);

l2.przesun(p1);
System.out.println(l1.rownolegla(l2));

l2 = l2.lustroOX();
}

}

//Geometria.cs
using System;

class Punkt2D {

public double x, y;

}

class Linia2D {

public Punkt2D p1=new Punkt2D(),
p2=new Punkt2D();

public void Skaluj(double d) {

Punkt2D c = new Punkt2D();
c.x = (p1.x+p2.x)/2;

c.y = (p1.y+p2.y)/2;
p1.x = c.x+(p1.x-c.x)* d;

p1.y = c.y+(p1.y-c.y)* d;
p2.x = c.x+(p2.x-c.x)* d;

p2.y = c.y+(p2.y-c.y)* d;
}

public void Przesun(Punkt2D p) {

p1.x += p.x; p1.y += p.y;
p2.x += p.x; p2.y += p.y;

}

public bool Rownolegla(Linia2D l) {
double dx1 = l.p2.x- l.p1.x,

dy1 = l.p2.y- l.p1.y,
dx2 = p2.x-p1.x,

dy2 = p2.y-p1.y;
return Math.Abs(dx1*dy2-dy1*dx2)<0.0001?

true:false;
}

Linia2D LustroOX() {

Linia2D l = new Linia2D();
l.p1.x = p1.x; l.p1.y = -p1.y;

l.p2.x = p2.x; l.p2.y = -p2.y;
return l;

}

public static void Main(string[] args)

{

Linia2D l1 = new Linia2D(),

l2 = new Linia2D();
Punkt2D p1 = new Punkt2D();

l1.p1.x = l2.p1.x = 0;
l1.p1.y = l2.p1.y = 0;

l1.p2.x = l2.p2.x = 1;
l1.p2.y = l2.p2.y = 1;

p1.x = 1; p1.y = 2;
l2.Skaluj(2);

l2.Przesun(p1);
Console.WriteLine(l1.Rownolegla(l2));

l2 = l2.LustroOX();
}

}


Wyszukiwarka

Podobne podstrony:
01 Geometry CPP CS
01 Geometry CPP Java
01 Geometria analityczna w n wymiarach okładka
01 Geometria analityczna w n wymiarach okładka
01 Geometria analityczna w n wymiarach okładka
Java 01 Wstep
01 Z Charakterystyki geometrycz Nieznany (2)
java 01
01-charakterystyki geometryczne
01-08, Programowanie, ! Java, Java i XML
Java praca domowa 01
figury geometryczne plaskie 01
JAVA 01 podstawowe informacje

więcej podobnych podstron