Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vektory
- {
- class Program
- {
- static void Main(string[] args)
- {
- Vektor prvnivektor = new Vektor(5);
- Vektor druhyvektor = new Vektor (2,3);
- Vektor tretivektor = new Vektor (4,1,3);
- Vektor promennyvektor = new Vektor(0, 0, 0);
- double vysled;
- vysled = tretivektor.DelkaVektoru(tretivektor);
- prvnivektor.VypisVektor();
- druhyvektor.VypisVektor();
- tretivektor.VypisVektor();
- promennyvektor = druhyvektor + tretivektor;
- promennyvektor.VypisVektor();
- promennyvektor = druhyvektor - tretivektor;
- promennyvektor.VypisVektor();
- promennyvektor = druhyvektor * tretivektor;
- Console.WriteLine(vysled);
- vysled = tretivektor.SmerVektoru(tretivektor, druhyvektor);
- Console.WriteLine(vysled);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vektory
- {
- class Vektor
- {
- public double x;
- public double y;
- public double z;
- public Vektor(double x)
- {
- this.x = x;
- this.y = 0;
- this.z = 0;
- }
- public Vektor(double x, double y)
- {
- this.x = x;
- this.y = y;
- this.z = 0;
- }
- public Vektor(double x, double y, double z)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public void VypisVektor()
- {
- Console.WriteLine("{0},{1},{2}", this.x, this.y, this.z);
- }
- static public Vektor operator +(Vektor a, Vektor b)
- {
- double x = a.x + b.x;
- double y = a.y + b.y;
- double z = a.z + b.z;
- Vektor vysledky = new Vektor(x, y, z);
- return vysledky;
- }
- static public Vektor operator -(Vektor a, Vektor b)
- {
- double x = a.x - b.x;
- double y = a.y - b.y;
- double z = a.z - b.z;
- Vektor vysledky = new Vektor(x, y, z);
- return vysledky;
- }
- static public Vektor operator *(Vektor a, Vektor b)
- {
- double x = a.x * b.x + a.y * b.y + a.z * b.z;
- Vektor vysledky = new Vektor( x);
- Console.WriteLine("Výsledek toho součinu je tolik:");
- Console.WriteLine(x);
- return vysledky;
- }
- public double DelkaVektoru(Vektor a)
- {
- double delka;
- delka = Math.Sqrt((a.x*a.x)+(a.y*a.y)+(a.z*a.z));
- return delka;
- }
- public double SmerVektoru(Vektor a, Vektor b)
- {
- double smer;
- smer = (a.x * b.x + a.y * b.y + a.z * b.z) / (DelkaVektoru(a)*DelkaVektoru(b));
- smer = Math.Acos(smer);
- smer = smer * 180 / Math.PI;
- return smer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment