/// <summary> /// Transforms a point into plane space with x and y being the /// position on the plane, and z being distance from the plane. /// <para/> /// This can be used for performing accelerated operations, such as /// triangulation, insideness checks, and clipping, on 2D geometry. /// This can be reversed with unprojectPoint. /// </summary> /// <param name="p"></param> /// <returns></returns> public gvec3 ProjectPoint(gvec3 p) { //Console.WriteLine("Warning: very inefficient function projectPoint"); //dmat4 mat = new dmat4(dquat.FromAxisAngle(0.0, new dvec3(a, b, c))); //return new g_vert3((dvec3)(mat * new dvec4(p.x, p.y, p.z, 1.0))); throw new NotImplementedException(); }
public static gvec3 Interpolate(gvec3 a, gvec3 b, double a_to_b) { if (a_to_b > 1.0 || a_to_b < 0.0) { throw new Exception("Interpolation range must be 0 to 1 inclusive"); } return(new gvec3 { x = a.x + (b.x - a.x) * a_to_b, y = a.y + (b.y - a.y) * a_to_b, z = a.z + (b.z - a.z) * a_to_b }); }
public static Plane CCW(gvec3 v0, gvec3 v1, gvec3 v2) { gvec3 cross = gvec3.Cross(v1 - v0, v2 - v0).Normalized; return(new Plane { a = cross.x, b = cross.y, c = cross.z, d = gvec3.Dot(cross, v0) }); }
/// <summary> /// Finds an intersection between this plane and a specified infinite line. /// </summary> /// <param name="p0">A point lying on an infinite line</param> /// <param name="p1">A point lying on an infinite line</param> /// <returns>The intersection between this plane and the specified infinite line</returns> public gvec3 UnconstrainedIntersection(gvec3 p0, gvec3 p1) { //math overview: //ax + by + cz = d //dot(<a, b, c>, <x, y, z>) = d //<x, y, z> = v0 + dir * t //dot(<a, b, c>, (v0 + dir * t)) = d //dot(<a, b, c>, v0) + dot(<a, b, c>, dir) * t = d //t = (d - dot(<a, b, c>, v0)) / dot(<a, b, c>, dir) gvec3 dir = p1 - p0; double num = d - a * p0.x - b * p0.y - c * p0.z; double div = a * dir.x + b * dir.y + c * dir.z; double t = num / div; return(p0 + dir * t); }
/// <summary> /// Finds an intersection between this plane and a specified finite line. /// </summary> /// <param name="p0">A point lying on an finite line</param> /// <param name="p1">A point lying on an finite line</param> /// <param name="intersection">The intersection between this plane and the specified finite line, if it exists</param> /// <returns>Whether or not there was an intersection</returns> public bool ConstrainedIntersection(gvec3 p0, gvec3 p1, ref gvec3 intersection) { gvec3 dir = p1 - p0; double num = d - a * p0.x - b * p0.y - c * p0.z; double div = a * dir.x + b * dir.y + c * dir.z; double t = num / div; if (t < 0) { return(false); } if (t < (p1 - p0).Length) { intersection = p0 + dir * t; return(true); } else { return(false); } }
public bool Identical(gvec3 other) { return(x == other.x && y == other.y && z == other.z); }
public gvec3 InterpolateTo(gvec3 b, double a_to_b) { return(Interpolate(this, b, a_to_b)); }
public static gvec3 Cross(gvec3 lhs, gvec3 rhs) { return(new gvec3 { x = lhs.y * rhs.z - lhs.z * rhs.y, y = lhs.z * rhs.x - lhs.x * rhs.z, z = lhs.x * rhs.y - lhs.y * rhs.x }); }
public static double Dot(gvec3 lhs, gvec3 rhs) { return(lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z); }
public gvec3 UnprojectPoint(gvec3 p) { throw new NotImplementedException(); }