01 Geometry CPP CS

background image

C++:

CS:

//Geometria.cpp
#include <iostream.h>

class Punkt2D {

public:
double x, y;

};

class Linia2D {
public:

Punkt2D p1, p2;
void skaluj(double d){

Punkt2D c;
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;
}

void przesun(Punkt2D &p) {

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

}

int 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 abs(dx1*dyY2-dy1*dx2)<0.0001;

}

Linia2D lustroOX() {

Linia2D l;
l.p1.x = p1.x; l.p1.y = -p1.y;

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

}
};

int main() {
Linia2D l1, l2;

Punkt2D p1;

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);
cout << l1.rownolegla(l2);

l2 = l2.lustroOX();
return 0;

}

//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 Java 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
01 Z Charakterystyki geometrycz Nieznany (2)
01-charakterystyki geometryczne
figury geometryczne plaskie 01
01 oprac geometria równań liniowych
cooling water (cw cs 1) 1 01
01 pole powierzchni geometra
01 Basic Suspension Geometry

więcej podobnych podstron