/// <summary> /// Initializes a new instance of the <see cref="Spheref"/> using the specified location and radius. /// </summary> /// <param name="center">The center of the sphere.</param> /// <param name="radius">The radius of the sphere.</param> public Spheref(Point3f center, float radius) { Contract.Requires(0 <= radius); X = center.X; Y = center.Y; Z = center.Z; Radius = radius; }
/// <summary> /// Initializes a new instance of the <see cref="Boxf"/> using the specified location and size. /// </summary> /// <param name="location">The front-lower-left corner of the box.</param> /// <param name="size">The size of the box.</param> public Boxf(Point3f location, Size3f size) { X = location.X; Y = location.Y; Z = location.Z; Width = size.Width; Height = size.Height; Depth = size.Depth; }
/// <summary> /// Initializes a new instance of the <see cref="Boxf"/> using the specified location and size. /// </summary> /// <param name="location">The front-lower-left corner of the box.</param> /// <param name="width">Value for the Width component of the box.</param> /// <param name="height">Value for the Height component of the box.</param> /// <param name="depth">Value for the Depth component of the box.</param> public Boxf(Point3f location, float width, float height, float depth) { X = location.X; Y = location.Y; Z = location.Z; Width = width; Height = height; Depth = depth; }
public Point3f[] ToArray() { var result = new Point3f[Count]; for (int i = 0; i < Count; ++i) { result[i] = this[i]; } return(result); }
/// <summary> /// Reads a <see cref="Polygon3f"/> from an <see cref="Ibasa.IO.BinaryReader">. /// </summary> public static Polygon3f ReadPolygon3f(this Ibasa.IO.BinaryReader reader) { var length = reader.ReadInt32(); var array = new Point3f[length]; for (int i = 0; i < length; ++i) { array[i] = reader.ReadPoint3f(); } return(new Polygon3f(array)); }
/// <summary> /// Transforms a point in cartesian coordinates to spherical coordinates. /// </summary> /// <param name="value">The point to transform.</param> /// <returns>The spherical coordinates of value.</returns> public static SphericalCoordinate CartesianToSpherical(Point3f value) { double r = Functions.Sqrt(value.X * value.X + value.Y * value.Y + value.Z * value.Z); double theta = Functions.Atan2(value.Y, value.X); if (theta < 0) { theta += 2 * Constants.Pi; } return(new SphericalCoordinate( r, (double)Functions.Acos(value.Z / r), theta)); }
/// <summary> /// Returns the manhatten distance between two points. /// </summary> /// <param name="value1">The first point.</param> /// <param name="value2">The second point.</param> /// <returns>The manhatten distance between value1 and value2.</returns> public static float ManhattenDistance(Point3f value1, Point3f value2) { return(Functions.Abs(value2.X - value1.X) + Functions.Abs(value2.Y - value1.Y) + Functions.Abs(value2.Z - value1.Z)); }
/// <summary> /// Returns the squared distance between two points. /// </summary> /// <param name="value1">The first point.</param> /// <param name="value2">The second point.</param> /// <returns>The squared distance between value1 and value2.</returns> public static float DistanceSquared(Point3f value1, Point3f value2) { return(Vector.AbsoluteSquared(value2 - value1)); }
/// <summary> /// Returns a value that indicates whether two points are equal. /// </summary> /// <param name="left">The first point to compare.</param> /// <param name="right">The second point to compare.</param> /// <returns>true if the left and right are equal; otherwise, false.</returns> public static bool Equals(Point3f left, Point3f right) { return(left == right); }
/// <summary> /// Returns a point where each component is rounded to the nearest integral value. /// </summary> /// <param name="value">A point.</param> /// <param name="digits">The number of fractional digits in the return value.</param> /// <returns>The result of rounding value.</returns> public static Point3f Round(Point3f value, int digits) { return(new Point3f(Functions.Round(value.X, digits), Functions.Round(value.Y, digits), Functions.Round(value.Z, digits))); }
/// <summary> /// Maps the components of a point and returns the result. /// </summary> /// <param name="value">The point to map.</param> /// <param name="mapping">A mapping function to apply to each component.</param> /// <returns>The result of mapping each component of value.</returns> public static Point3d Map(Point3f value, Func <float, double> mapping) { return(new Point3d(mapping(value.X), mapping(value.Y), mapping(value.Z))); }
/// <summary> /// Determines whether any component of a point is non-zero. /// </summary> /// <param name="value">A point.</param> /// <returns>true if any components are non-zero; false otherwise.</returns> public static bool Any(Point3f value) { return(value.X != 0 || value.Y != 0 || value.Z != 0); }
/// <summary> /// Adds a point and a vector and returns the result. /// </summary> /// <param name="point">The point value to add.</param> /// <param name="vector">The vector value to add.</param> /// <returns>The sum of left and right.</returns> public static Point3f Add(Point3f point, Vector3f vector) { return(new Point3f(point.X + vector.X, point.Y + vector.Y, point.Z + vector.Z)); }
/// <summary> /// Writes the given <see cref="Point3f"/> to an <see cref="Ibasa.IO.BinaryWriter">. /// </summary> public static void Write(this Ibasa.IO.BinaryWriter writer, Point3f point) { writer.Write(point.X); writer.Write(point.Y); writer.Write(point.Z); }
/// <summary> /// Performs a linear interpolation between two points. /// </summary> /// <param name="point1">First point.</param> /// <param name="point2">Second point.</param> /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="value2"/>.</param> /// <returns>The linear interpolation of the two points.</returns> public static Point3f Lerp(Point3f point1, Point3f point2, float amount) { return(point1 + (point2 - point1) * amount); }
/// <summary> /// Projects a point onto a vector, returns the distance of the projection from the origin. /// </summary> /// <param name="vector">The vector to project onto.</param> /// <param name="point">The point to project.</param> /// <returns>The distance from the origin of the projection.</returns> public static float Project(Point3f point, Vector3f vector) { return(vector.X * point.X + vector.Y * point.Y + vector.Z * point.Z); }
/// <summary> /// Calculates the reciprocal of each component in the point. /// </summary> /// <param name="value">A point.</param> /// <returns>A point with the reciprocal of each of values components.</returns> public static Point3f Reciprocal(Point3f value) { return(new Point3f(1 / value.X, 1 / value.Y, 1 / value.Z)); }
/// <summary> /// Returns a point where each component is rounded to the nearest integral value. /// </summary> /// <param name="value">A point.</param> /// <param name="digits">The number of fractional digits in the return value.</param> /// <param name="mode">Specification for how to round value if it is midway between two other numbers.</param> /// <returns>The result of rounding value.</returns> public static Point3f Round(Point3f value, int digits, MidpointRounding mode) { return(new Point3f(Functions.Round(value.X, digits, mode), Functions.Round(value.Y, digits, mode), Functions.Round(value.Z, digits, mode))); }
/// <summary> /// Determines whether all components of a point are non-zero. /// </summary> /// <param name="value">A point.</param> /// <returns>true if all components are non-zero; false otherwise.</returns> public static bool All(Point3f value) { return(value.X != 0 && value.Y != 0 && value.Z != 0); }
/// <summary> /// Subtracts one points from another and returns the result. /// </summary> /// <param name="left">The value to subtract from (the minuend).</param> /// <param name="right">The value to subtract (the subtrahend).</param> /// <returns>The result of subtracting right from left (the difference).</returns> public static Vector3f Subtract(Point3f left, Point3f right) { return(new Vector3f(left.X - right.X, left.Y - right.Y, left.Z - right.Z)); }
/// <summary> /// Determines whether all components of a point satisfy a condition. /// </summary> /// <param name="value">A point.</param> /// <param name="predicate">A function to test each component for a condition.</param> /// <returns>true if every component of the point passes the test in the specified /// predicate; otherwise, false.</returns> public static bool All(Point3f value, Predicate <float> predicate) { return(predicate(value.X) && predicate(value.Y) && predicate(value.Z)); }
/// <summary> /// Subtracts a vector from a point and returns the result. /// </summary> /// <param name="point">The point value to subtract from (the minuend).</param> /// <param name="vector">The vector value to subtract (the subtrahend).</param> /// <returns>The result of subtracting vector from point (the difference).</returns> public static Point3f Subtract(Point3f point, Vector3f vector) { return(new Point3f(point.X - vector.X, point.Y - vector.Y, point.Z - vector.Z)); }
/// <summary> /// Determines whether any components of a point satisfy a condition. /// </summary> /// <param name="value">A point.</param> /// <param name="predicate">A function to test each component for a condition.</param> /// <returns>true if any component of the point passes the test in the specified /// predicate; otherwise, false.</returns> public static bool Any(Point3f value, Predicate <float> predicate) { return(predicate(value.X) || predicate(value.Y) || predicate(value.Z)); }
public static bool Contains(Spheref sphere, Point3f point) { return(Vector.AbsoluteSquared(sphere.Center - point) <= sphere.Radius * sphere.Radius); }
/// <summary> /// Maps the components of a point and returns the result. /// </summary> /// <param name="value">The point to map.</param> /// <param name="mapping">A mapping function to apply to each component.</param> /// <returns>The result of mapping each component of value.</returns> public static Point3l Map(Point3f value, Func <float, long> mapping) { return(new Point3l(mapping(value.X), mapping(value.Y), mapping(value.Z))); }
/// <summary> /// Returns a point where each component is the fractional part of the specified component. /// </summary> /// <param name="value">A point.</param> /// <returns>The fractional of value.</returns> public static Point3f Fractional(Point3f value) { return(new Point3f(Functions.Fractional(value.X), Functions.Fractional(value.Y), Functions.Fractional(value.Z))); }
/// <summary> /// Divides a point by a scalar and returns the result. /// </summary> /// <param name="point">The point to be divided (the dividend).</param> /// <param name="scalar">The scalar to divide by (the divisor).</param> /// <returns>The result of dividing left by right (the quotient).</returns> public static Point3f Divide(Point3f point, float scalar) { return(new Point3f(point.X / scalar, point.Y / scalar, point.Z / scalar)); }
/// <summary> /// Returns a point where each component is rounded to the nearest integral value. /// </summary> /// <param name="value">A point.</param> /// <returns>The result of rounding value.</returns> public static Point3f Round(Point3f value) { return(new Point3f(Functions.Round(value.X), Functions.Round(value.Y), Functions.Round(value.Z))); }
/// <summary> /// Returns the product of a point and scalar. /// </summary> /// <param name="point">The point to multiply.</param> /// <param name="scalar">The scalar to multiply.</param> /// <returns>The product of the left and right parameters.</returns> public static Point3f Multiply(Point3f point, float scalar) { return(new Point3f(point.X * scalar, point.Y * scalar, point.Z * scalar)); }
/// <summary> /// Returns a point where each component is the integral part of the specified component. /// </summary> /// <param name="value">A point.</param> /// <returns>The integral of value.</returns> public static Point3f Truncate(Point3f value) { return(new Point3f(Functions.Truncate(value.X), Functions.Truncate(value.Y), Functions.Truncate(value.Z))); }