using
System;
using
System.Collections.Generic;
class
Vector {
public
int
x, y, z;
public
Vector(
int
x1,
int
y1,
int
z1)
{
x = x1;
y = y1;
z = z1;
}
public
double
magnitude()
{
return
Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)
+ Math.Pow(z, 2));
}
public
static
Vector
operator
+ (Vector v1, Vector v)
{
int
x1, y1, z1;
x1 = v1.x + v.x;
y1 = v1.y + v.y;
z1 = v1.z + v.z;
return
new
Vector(x1, y1, z1);
}
public
static
Vector
operator
- (Vector v1, Vector v)
{
int
x1, y1, z1;
x1 = v1.x - v.x;
y1 = v1.y - v.y;
z1 = v1.z - v.z;
return
new
Vector(x1, y1, z1);
}
public
static
Vector
operator
*(Vector v, Vector v1)
{
int
x1, y1, z1;
x1 = v1.y * v.z - v1.z * v.y;
y1 = v1.z * v.x - v1.x * v.z;
z1 = v1.x * v.y - v1.y * v.x;
return
new
Vector(x1, y1, z1);
}
}
class
GFG {
static
double
shortDistance(Vector line_point1,
Vector line_point2,
Vector point)
{
Vector AB = line_point2 - line_point1;
Vector AC = point - line_point1;
double
area = (AB * AC).magnitude();
double
CD = area / AB.magnitude();
return
CD;
}
public
static
void
Main(
string
[] args)
{
Vector line_point1 =
new
Vector(4, 2, 1);
Vector line_point2 =
new
Vector(8, 4, 2);
Vector point =
new
Vector(2, 2, 2);
Console.WriteLine(
"Shortest Distance is : "
+ shortDistance(line_point1,
line_point2,
point));
}
}