
Steven S. answered 12/17/19
Software Developer C# .NET SQL
using System;
public class ThreeDVector
{
public static void Main(string[] args)
{
var ray = new ThreeDVector(0.0, -1.0, -1.0);
var rayPoint = new ThreeDVector(0.0, 0.0, 11.0);
var plane = new ThreeDVector(0.0, 0.0, 3.0);
var planePoint = new ThreeDVector(0.0, 0.0, 4.0);
Console.WriteLine("Intersection of the plane occurs at {0}", ThreeDVector.FindIntersection(ray, rayPoint, plane, planePoint));
}
private double x;
private double y;
private double z;
public ThreeDVector(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
public static ThreeDVector operator +(ThreeDVector a, ThreeDVector b)
{
return new ThreeDVector(a.x + b.x, a.y + b.y, a.z + b.z);
}
public static ThreeDVector operator -(ThreeDVector a, ThreeDVector b)
{
return new ThreeDVector(a.x - b.x, a.y - b.y, a.z - b.z);
}
public static ThreeDVector operator *(ThreeDVector a, double b)
{
return new ThreeDVector(a.x * b, a.y * b, a.z * b);
}
public double Point(ThreeDVector a)
{
return this.x * a.x + this.y * a.y + this.z * a.z;
}
public static ThreeDVector FindIntersection(ThreeDVector ray, ThreeDVector rayPoint, ThreeDVector plane, ThreeDVector planePoint)
{
return rayPoint - ray * ((rayPoint - planePoint).Point(plane) / ray.Point(plane));
}
public override string ToString()
{
return string.Format("({0:F}, {1:F}, {2:F})", this.x, this.y, this.z);
}
}