/// <summary> /// Constructs the identifier from the axis number, and a set of logical values. The part of the logical value that belongs to the provided axis number is ignored. /// </summary> /// <param name="parallelAxisNumber">Number of the axis (0: X, 1: Y, 2: Z).</param> /// <param name="logicalValuesOther">Set of values that determine the position of the axis line in the coordinate space.</param> public CSLineID(int parallelAxisNumber, Logical3D logicalValuesOther) { _parallelAxisNumber = parallelAxisNumber; switch (_parallelAxisNumber) { case 0: _logicalValueFirstOther = logicalValuesOther[1]; _logicalValueSecondOther = logicalValuesOther[2]; break; case 1: _logicalValueFirstOther = logicalValuesOther[0]; _logicalValueSecondOther = logicalValuesOther[2]; break; case 2: _logicalValueFirstOther = logicalValuesOther[0]; _logicalValueSecondOther = logicalValuesOther[1]; break; default: throw new ArgumentOutOfRangeException("AxisNumber must be either 0, 1, or 2, but you provide: " + parallelAxisNumber.ToString()); } }
/// <summary> /// Gets a iso line in a path object. /// </summary> /// <param name="r0">Starting position in logical coordinates.</param> /// <param name="r1">End position in logical coordinates.</param> /// <returns>The graphics path for the isoline.</returns> public abstract IPolylineD3D GetIsoline(Logical3D r0, Logical3D r1);
/// <summary> /// Calculates from two coordinates of a point the logical values (values between 0 and 1). Returns true if the conversion /// is possible, otherwise false. /// </summary> /// <param name="location">The x coordinate of the converted value (for instance location).</param> /// <param name="r">The computed logical position value.</param> /// <returns>True if the conversion was successfull, false if the conversion was not possible. For 3D coordinate systems, /// the relative values of x and y with z=0 should be returned.</returns> public abstract bool LayerToLogicalCoordinates(PointD3D location, out Logical3D r);
/// <summary> /// Converts logical coordinates along an isoline to layer coordinates and the appropriate derivative. /// </summary> /// <param name="r0">Logical position of starting point of the isoline.</param> /// <param name="r1">Logical position of end point of the isoline.</param> /// <param name="t">Parameter between 0 and 1 that determines the point on the isoline. /// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical /// coordinates are linear interpolated between starting point and end point.</param> /// <param name="position">Layer coordinate of the isoline point.</param> /// <param name="direction">Derivative of layer coordinate with respect to parameter t at the point <paramref name="position"/>.</param> /// <returns>True if the conversion was sucessfull, otherwise false.</returns> public abstract bool LogicalToLayerCoordinatesAndDirection( Logical3D r0, Logical3D r1, double t, out PointD3D position, out VectorD3D direction);
/// <summary> /// Calculates from two logical values (values between 0 and 1) the coordinates of the point. Returns true if the conversion /// is possible, otherwise false. /// </summary> /// <param name="r">The logical position value.</param> /// <param name="location">On return, gives the coordinates of the converted value (for instance location).</param> /// <returns>True if the conversion was successfull, false if the conversion was not possible.</returns> public abstract bool LogicalToLayerCoordinates(Logical3D r, out PointD3D location);
/// <summary> /// Converts logical coordinates along an isoline to layer coordinates and returns the direction of the isoline at this point. /// </summary> /// <param name="r0">Logical starting point of the isoline.</param> /// <param name="r1">Logical end point of the isoline.</param> /// <param name="t">Parameter between 0 and 1 that determines the point on the isoline. /// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical /// coordinates are linear interpolated between starting point and end point.</param> /// <param name="direction">Logical direction vector.</param> /// <param name="normalizeddirection">Returns the normalized direction vector,i.e. a vector of norm 1, that /// goes in the logical direction provided by the previous argument. </param> /// <returns>The location (in layer coordinates) of the isoline point.</returns> public virtual PointD3D GetPositionAndNormalizedDirection( Logical3D r0, Logical3D r1, double t, Logical3D direction, out VectorD3D normalizeddirection) { PointD3D pos; VectorD3D dir; Logical3D rn0 = Logical3D.Interpolate(r0, r1, t); Logical3D rn1 = rn0 + direction; this.LogicalToLayerCoordinatesAndDirection(rn0, rn1, 0, out pos, out dir); double hypot = dir.Length; if (0 == hypot) { // then we look a little bit displaced - we might be at the midpoint where the directions are undefined double displT = t; if (displT < 0.5) displT += 1E-6; else displT -= 1E-6; Logical3D displR = Logical3D.Interpolate(r0, r1, displT); Logical3D displD = displR + direction; PointD3D dummyx; LogicalToLayerCoordinatesAndDirection(displR, displD, 0, out dummyx, out dir); hypot = dir.Length; } // Normalize the vector if (hypot > 0) { dir /= hypot; } normalizeddirection = dir; return pos; }
/// <summary> /// Converts logical coordinates along an isoline to layer coordinates and returns the direction of the isoline at this point. /// </summary> /// <param name="r0">Logical coordinates of starting point of the isoline.</param> /// <param name="r1">Logical coordinates of end point of the isoline.</param> /// <param name="t">Parameter between 0 and 1 that determines the point on the isoline. /// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical /// coordinates are linear interpolated between starting point and end point.</param> /// <param name="angle">Angle between direction of the isoline and returned normalized direction vector.</param> /// <param name="normalizeddirection">Returns the normalized direction vector,i.e. a vector of norm 1, that /// has the angle <paramref name="angle"/> to the tangent of the isoline. </param> /// <returns>The location (in layer coordinates) of the isoline point.</returns> public PointD3D GetNormalizedDirection( Logical3D r0, Logical3D r1, double t, double angle, out VectorD3D normalizeddirection) { //double ax, ay, adx, ady; PointD3D position; VectorD3D direction; this.LogicalToLayerCoordinatesAndDirection( r0, r1, t, out position, out direction); if (angle != 0) { throw new NotImplementedException("We need here two angles instead of one"); /* double phi = Math.PI * angle / 180; double hdx = adx * Math.Cos(phi) + ady * Math.Sin(phi); ady = -adx * Math.Sin(phi) + ady * Math.Cos(phi); adx = hdx; */ } normalizeddirection = direction.Normalized; return position; }
public PointD3D GetPointOnPlane(CSPlaneID id, Logical3D r) { PointD3D result; if (id.PerpendicularAxisNumber == 0) LogicalToLayerCoordinates(new Logical3D(id.LogicalValue, r.RY, r.RZ), out result); else if (id.PerpendicularAxisNumber == 1) LogicalToLayerCoordinates(new Logical3D(r.RX, id.LogicalValue, r.RZ), out result); else LogicalToLayerCoordinates(new Logical3D(r.RX, r.RY, id.LogicalValue), out result); return result; }
/// <summary> /// Draws an isoline on a plane beginning from r0 to r1. For r0,r1 either ry0,ry1 is used (if it is an x-axis), /// otherwise rx0,rx1 is used. The other parameter pair is not used. /// </summary> /// <param name="path">Graphics path to fill with the isoline.</param> /// <param name="r0">Logical coordinate of the start point.</param> /// <param name="r1">Logical coordinate of the end point.</param> /// <param name="id">The axis to end the isoline.</param> public virtual void GetIsolineOnPlane(CSPlaneID id, Logical3D r0, Logical3D r1, IPolylineD3D path) { if (id.PerpendicularAxisNumber == 0) { path = GetIsoline(new Logical3D(id.LogicalValue, r0.RY, r0.RZ), new Logical3D(id.LogicalValue, r1.RY, r1.RZ)); } else if (id.PerpendicularAxisNumber == 1) { path = GetIsoline(new Logical3D(r0.RX, id.LogicalValue, r0.RZ), new Logical3D(r1.RX, id.LogicalValue, r1.RZ)); } else { path = GetIsoline(new Logical3D(r0.RX, r0.RY, id.LogicalValue), new Logical3D(r1.RX, r1.RY, id.LogicalValue)); } }
/// <summary> /// Gets an isoline beginning from a given point to the axis. /// </summary> /// <param name="path">Graphics path to fill with the isoline.</param> /// <param name="r">Logical coordinate of the start point.</param> /// <param name="id">The logical plane to end the isoline.</param> public virtual void GetIsolineFromPointToPlane(Logical3D r, CSPlaneID id, out IPolylineD3D path) { if (id.PerpendicularAxisNumber == 0) { path = GetIsoline(r, new Logical3D(id.LogicalValue, r.RY, r.RZ)); } else if (id.PerpendicularAxisNumber == 1) { path = GetIsoline(r, new Logical3D(r.RX, id.LogicalValue, r.RZ)); } else { path = GetIsoline(r, new Logical3D(r.RX, r.RY, id.LogicalValue)); } }
public static Logical3D Interpolate(Logical3D from, Logical3D to, double t) { return new Logical3D ( from.RX + t * (to.RX - from.RX), from.RY + t * (to.RY - from.RY), from.RZ + t * (to.RZ - from.RZ) ); }
public Logical3D InterpolateTo(Logical3D to, double t) { return new Logical3D ( this.RX + t * (to.RX - this.RX), this.RY + t * (to.RY - this.RY), this.RZ + t * (to.RZ - this.RZ) ); }