/// <summary> /// Copy constructor. /// </summary> /// <param name="v">A SpatialVector from which to copy</param> public SpatialVector(SpatialVector v){ _x = v._x; _y = v._y; _z = v._z; _ra = v._ra; _dec = v._dec; _okRaDec = v._okRaDec; _okXYZ = v._okXYZ; }
/// <summary> /// Test whether or not point described by vector v is inside /// this halfspace /// </summary> /// <param name="v">A point</param> /// <returns>true if the specified point described by v is inside this halfspace</returns> public bool contains(SpatialVector v) { // v is inside the halfspace, if the angle between v and // the direction vector is smaller than the cone half-angle. // Note that _D = cos(half-angle) // return (v.dot(_SV) >= _D); }
/// <summary> /// Make a halfspace with parameters (V, D) /// /// It is not necessary that the directional vector, though normal /// to the cutting plane, by definition, be a normal vector. /// </summary> /// <param name="v">The cutting plane's normal vector</param> /// <param name="d">The distance of the cutting plane along the normal /// vector's direction. Can be negative.</param> public Halfspace(SpatialVector v, double d) { init(); if (d < -1.0) _D = -1.0; else if (d > 1.0) _D = 1.0; else _D = d; _SV.assign(v); _SV.normalizeMeSafely(); if (_D < -SpatialVector.Epsilon) { _sign = Sign.Negative; } else if (_D >= SpatialVector.Epsilon) { _sign = Sign.Positive; } else { _sign = Sign.Zero; } _hangle = Math.Acos(_D); }
/// <summary> /// Allocate some internal veriables /// </summary> private void init(){ _ID = HtmState.Instance.newhs; // a unique ID for this halfspace _D = 0.0; _SV = new SpatialVector(0.0, 0.0, 1.0); _West = new SpatialVector(); _hangle = SpatialVector.Pi / 2.0; _sign = Sign.Zero; }
/// <summary> /// Perform cross prodcut of this and another /// vector. Operation writes result into this vector /// </summary> /// <param name="that">The other vector</param> public void crossMe(SpatialVector that){ Cartesian a = that; this.crossMe(a); }
/// <summary> /// Perform dot product between this and another /// vector. /// </summary> /// <param name="that">The other vector</param> /// <returns>The dot product</returns> public double dot(SpatialVector that){ Cartesian a = this; Cartesian b = that; return a.dot(b); }
/// <summary> /// Perform cross prodcut of this and another /// vector. Operation returns a new instance of a /// Cartesian. /// </summary> /// <param name="that">The other vector</param> /// <returns>A new Cartesian</returns> public Cartesian cross(SpatialVector that){ Cartesian a = this; Cartesian b = that; return a.cross(b); }