vojta249

Vectors

Mar 30th, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. namespace Vektory
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.            
  15.             Vektor prvnivektor = new Vektor(5);
  16.             Vektor druhyvektor = new Vektor (2,3);
  17.             Vektor tretivektor = new Vektor (4,1,3);
  18.             Vektor promennyvektor = new Vektor(0, 0, 0);
  19.             double vysled;
  20.             vysled = tretivektor.DelkaVektoru(tretivektor);
  21.             prvnivektor.VypisVektor();
  22.             druhyvektor.VypisVektor();
  23.             tretivektor.VypisVektor();
  24.             promennyvektor = druhyvektor + tretivektor;
  25.             promennyvektor.VypisVektor();
  26.             promennyvektor = druhyvektor - tretivektor;
  27.             promennyvektor.VypisVektor();
  28.             promennyvektor = druhyvektor * tretivektor;
  29.             Console.WriteLine(vysled);
  30.             vysled = tretivektor.SmerVektoru(tretivektor, druhyvektor);
  31.             Console.WriteLine(vysled);
  32.         }
  33.     }
  34. }
  35.  
  36.  
  37. using System;
  38. using System.Collections.Generic;
  39. using System.Linq;
  40. using System.Text;
  41. using System.Threading.Tasks;
  42.  
  43. namespace Vektory
  44. {
  45.     class Vektor
  46.     {
  47.         public double x;
  48.         public double y;
  49.         public double z;
  50.  
  51.         public Vektor(double x)
  52.         {
  53.             this.x = x;
  54.             this.y = 0;
  55.             this.z = 0;
  56.         }
  57.         public Vektor(double x, double y)
  58.         {
  59.             this.x = x;
  60.             this.y = y;
  61.             this.z = 0;
  62.         }
  63.         public Vektor(double x, double y, double z)
  64.         {
  65.             this.x = x;
  66.             this.y = y;
  67.             this.z = z;
  68.         }
  69.        
  70.         public void VypisVektor()
  71.         {
  72.             Console.WriteLine("{0},{1},{2}", this.x, this.y, this.z);
  73.         }
  74.         static public Vektor operator +(Vektor a, Vektor b)
  75.         {
  76.             double x = a.x + b.x;
  77.             double y = a.y + b.y;
  78.             double z = a.z + b.z;
  79.  
  80.             Vektor vysledky = new Vektor(x, y, z);
  81.             return vysledky;
  82.         }
  83.         static public Vektor operator -(Vektor a, Vektor b)
  84.         {
  85.             double x = a.x - b.x;
  86.             double y = a.y - b.y;
  87.             double z = a.z - b.z;
  88.  
  89.             Vektor vysledky = new Vektor(x, y, z);
  90.             return vysledky;
  91.         }
  92.         static public Vektor operator *(Vektor a, Vektor b)
  93.         {
  94.             double x = a.x * b.x + a.y * b.y + a.z * b.z;
  95.             Vektor vysledky = new Vektor( x);
  96.             Console.WriteLine("Výsledek toho součinu je tolik:");
  97.             Console.WriteLine(x);
  98.             return vysledky;
  99.         }
  100.  
  101.         public double DelkaVektoru(Vektor a)
  102.         {
  103.             double delka;
  104.             delka = Math.Sqrt((a.x*a.x)+(a.y*a.y)+(a.z*a.z));
  105.             return delka;
  106.         }
  107.         public double SmerVektoru(Vektor a, Vektor b)
  108.         {
  109.             double smer;
  110.             smer = (a.x * b.x + a.y * b.y + a.z * b.z) / (DelkaVektoru(a)*DelkaVektoru(b));
  111.             smer = Math.Acos(smer);
  112.             smer = smer * 180 / Math.PI;
  113.            
  114.             return smer;
  115.         }
  116.  
  117.     }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment