Esempio n. 1
0
        /// <summary>
        /// Transforms a <see cref="M34d"/> to a <see cref="M33d"/> by deleting the
        /// specified row and column. Internally the <see cref="M34d"/> is tarnsformed
        /// to a <see cref="M44d"/> to delete the row and column.
        /// </summary>
        /// <param name="deleted_row">Row to delete.</param>
        /// <param name="deleted_column">Column to delete.</param>
        /// <returns>A <see cref="M33d"/>.</returns>
        public M33d Minor(int deleted_row, int deleted_column)
        {
            M44d temp = (M44d)this;

            M33d result      = new M33d();
            int  checked_row = 0;

            for (int actual_row = 0; actual_row < 4; actual_row++)
            {
                int checked_column = 0;

                if (actual_row != deleted_row)
                {
                    for (int actual_column = 0; actual_column < 4; actual_column++)
                    {
                        if (actual_column != deleted_column)
                        {
                            result[checked_row, checked_column] = temp[actual_row, actual_column];
                            checked_column++;
                        }
                    }
                    checked_row++;
                }
            }

            return(result);
        }
Esempio n. 2
0
        static M33d CreateConversionMatrix()
        {
            // for spectral to xyz conversion see: http://www.brucelindbloom.com/index.html?Eqn_Spect_to_XYZ.html

            var specS0Vec = new Vector <double>(SpecS0_380_780_10nm);
            var specS1Vec = new Vector <double>(SpecS1_380_780_10nm);
            var specS2Vec = new Vector <double>(SpecS2_380_780_10nm);

            var cieXVec = new Vector <double>(Ciexyz31X_380_780_10nm);
            var cieYVec = new Vector <double>(Ciexyz31Y_380_780_10nm);
            var cieZVec = new Vector <double>(Ciexyz31Z_380_780_10nm);

            var specM = new M33d
                        (
                cieXVec.DotProduct(specS0Vec), cieXVec.DotProduct(specS1Vec), cieXVec.DotProduct(specS2Vec),
                cieYVec.DotProduct(specS0Vec), cieYVec.DotProduct(specS1Vec), cieYVec.DotProduct(specS2Vec),
                cieZVec.DotProduct(specS0Vec), cieZVec.DotProduct(specS1Vec), cieZVec.DotProduct(specS2Vec)
                        );

            var cieN = 1.0 / cieYVec.Data.Sum(); // cie response curve integral normalization

            // sun spectral radiance (S0, S1, S2) is expressed in micro-meters =>
            // convert to wavelengthes in nm (unit of color matching functions) -> scale by 1/1000
            // the cie response functions are in 10nm steps -> scale by 10

            var specN = 1.0 / 1000 * 10;         // spectrum unit converions (1 micro meter to 10 nano meter)

            var norm = cieN * specN;             // normalization of color space conversion matrix

            return(specM * norm);
        }
Esempio n. 3
0
        /// <summary>
        /// Calculates the inverse matrix using Householder transformations
        /// </summary>
        public static M33d QrInverse(this M33d mat)
        {
            var qr   = new Matrix <double>((double[])mat, 3, 3);
            var diag = qr.QrFactorize();

            return((M33d)(qr.QrInverse(diag).Data));
        }
Esempio n. 4
0
        public static M33d Multiply(Rot2d rot, M33d mat)
        {
            double a = (double)System.Math.Cos(rot.Angle);
            double b = (double)System.Math.Sin(rot.Angle);

            return(new M33d(a * mat.M00 +
                            b * mat.M10,

                            a * mat.M01 +
                            b * mat.M11,

                            a * mat.M02 +
                            b * mat.M12,

                            -b * mat.M00 +
                            a * mat.M10,

                            -b * mat.M01 +
                            a * mat.M11,

                            -b * mat.M02 +
                            a * mat.M12,

                            mat.M20,

                            mat.M21,

                            mat.M22));
        }
Esempio n. 5
0
        public static Trafo2d Parse(string s)
        {
            var x = s.NestedBracketSplitLevelOne().ToArray();

            return(new Trafo2d(
                       M33d.Parse(x[0]),
                       M33d.Parse(x[1])
                       ));
        }
Esempio n. 6
0
        /// <summary>
        /// Returns true if the ray hits the other ray before the parameter
        /// value contained in the supplied hit. Detailed information about
        /// the hit is returned in the supplied hit.
        /// </summary>
        public bool HitsRay(
            Ray3d ray,
            double tmin, double tmax,
            ref RayHit3d hit
            )
        {
            V3d d = Origin - ray.Origin;
            V3d u = Direction;
            V3d v = ray.Direction;
            V3d n = u.Cross(v);

            if (Fun.IsTiny(d.Length))
            {
                return(true);
            }
            else if (Fun.IsTiny(u.Cross(v).Length))
            {
                return(false);
            }
            else
            {
                //-t0*u + t1*v + t2*n == d
                //M = {-u,v,n}
                //M*{t0,t1,t2}T == d
                //{t0,t1,t2}T == M^-1 * d

                M33d M = new M33d();
                M.C0 = -u;
                M.C1 = v;
                M.C2 = n;

                if (M.Invertible)
                {
                    V3d t = M.Inverse * d;
                    if (Fun.IsTiny(t.Z))
                    {
                        ProcessHits(t.X, double.MaxValue, tmin, tmax, ref hit);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Multiplacation of a <see cref="Scale3d"/> with a <see cref="M33d"/>.
        /// </summary>
        public static M33d Multiply(Scale3d scale, M33d mat)
        {
            return(new M33d(scale.X * mat.M00,
                            scale.X * mat.M01,
                            scale.X * mat.M02,

                            scale.Y * mat.M10,
                            scale.Y * mat.M11,
                            scale.Y * mat.M12,

                            scale.Z * mat.M20,
                            scale.Z * mat.M21,
                            scale.Z * mat.M22));
        }
Esempio n. 8
0
        public readonly V3d  Translation;       // cam 2 world was chosen, so that it can be easily read
                                                // while debugging

        public CameraExtrinsics(M33d cam2worldRotation, V3d cam2worldTranslation)
        {
            var zero = cam2worldRotation * cam2worldRotation.Transposed - M33d.Identity;

            if (zero.NormMax > 1e6)
            {
                throw new ArgumentException("supplied matrix is not a rotation");
            }
            if (cam2worldRotation.Determinant < 0.0)
            {
                throw new ArgumentException("supplied rotation is improper (mirroring)");
            }
            Rotation    = cam2worldRotation;
            Translation = cam2worldTranslation;
        }
Esempio n. 9
0
        /// <summary>
        /// Transforms XYZ coord on one reference ellipsoid to XYZ coords on another
        /// ref ellipsoid. The ellipsoids-difference is defined in a geometric datum
        /// which is passes as the second argument.
        /// </summary>
        public static V3d HelmertsTransformXyzToXyz(V3d xyz, GeoDatum datum)
        {
            // transformation matrix
            var T = new M33d(1.0, datum.rZrad, -datum.rYrad,
                             -datum.rZrad, 1.0, datum.rXrad,
                             datum.rYrad, -datum.rXrad, 1.0);

            // delta in ellipsoid center positions
            var dP = new V3d(datum.dX, datum.dY, datum.dZ);

            // scale factor
            var mu = new Scale3d(datum.dS * 0.000001 + 1.0);

            var result = dP + (mu * T) * xyz;

            return(result);
        }
        /// <summary>
        /// </summary>
        public static M33d operator *(Euclidean3d r3, Rot2d r2)
        {
            M33d m33 = (M33d)r3;
            M22d m22 = (M22d)r2;

            return(new M33d(
                       m33.M00 * m22.M00 + m33.M01 * m22.M10,
                       m33.M00 * m22.M01 + m33.M01 * m22.M11,
                       m33.M02,

                       m33.M10 * m22.M00 + m33.M11 * m22.M10,
                       m33.M10 * m22.M01 + m33.M11 * m22.M11,
                       m33.M12,

                       m33.M20 * m22.M00 + m33.M21 * m22.M10,
                       m33.M20 * m22.M01 + m33.M21 * m22.M11,
                       m33.M22
                       ));
        }
        /// <summary>
        /// Updates position until stopDragging completes.
        /// </summary>
        public static async Task <IBehavior> DragRelative(this IBehavior self,
                                                          V2d initialPosition, IEvent <V2d> moves, IAwaitable stopDragging, CancellationToken ct
                                                          )
        {
            var obj = self as IBehaviorTransform2d;

            if (obj == null)
            {
                throw new InvalidOperationException("DragRelative requires IBehaviorTransform2d.");
            }

            var lastPos = initialPosition;
            await stopDragging.RepeatUntilCompleted(
                async delegate
            {
                var p = await moves.Next.WithCancellation(ct);
                obj.Transform(M33d.Translation(p - lastPos));
                lastPos = p;
            });

            return(self);
        }
Esempio n. 12
0
        /// <summary>
        /// A <see cref="M44d"/> is transformed to <see cref="M33d"/> by deleting specified row and column
        /// </summary>

        public M33d Minor(int rowToDelete, int columnToDelete)
        {
            M33d result      = new M33d();
            int  checked_row = 0;

            for (int actual_row = 0; actual_row < 4; actual_row++)
            {
                int checked_column = 0;

                if (actual_row != rowToDelete)
                {
                    for (int actual_column = 0; actual_column < 4; actual_column++)
                    {
                        if (actual_column != columnToDelete)
                        {
                            result[checked_row, checked_column] = this[actual_row, actual_column];
                            checked_column++;
                        }
                    }
                    checked_row++;
                }
            }
            return(result);
        }
Esempio n. 13
0
 public static M34d Multiply(M33d m, Euclidean3d r)
 {
     return(M34d.Multiply(m, (M34d)r));
 }
Esempio n. 14
0
 public static M33d NormalizedImagePosToPixelEdgeMat(V2d imgSizeInPixel)
 {
     return(M33d.Scale(imgSizeInPixel - 1));
 }
Esempio n. 15
0
 /// <summary>
 /// Returns a Matrix to
 /// convert from pixel-center position to normalized image position [0,1][0,1].
 /// (The inverse of toPixelCenter.)
 /// </summary>
 public static M33d PixelCenterToNormalizedImgMat(V2d imgSizeInPixel)
 {
     return(M33d.Scale(V2d.II / imgSizeInPixel) * M33d.Translation(V2dHalf));
 }
Esempio n. 16
0
 /// <summary>
 /// Returns a Matrix to
 /// convert from normalized image position [0,1][0,1] to pixel-center position
 /// (The inverse of toNormalizedImgPos.)
 /// </summary>
 public static M33d NormalizedImagePosToPixelCenterMat(V2d imgSizeInPixel)
 {
     return(M33d.Translation(-V2dHalf) * M33d.Scale(imgSizeInPixel));
 }
Esempio n. 17
0
 public static M33d PixelEdgeToNormalizedImgMat(V2d imgSizeInPixel)
 {
     return(M33d.Scale(V2d.II / (imgSizeInPixel - 1)));
 }
Esempio n. 18
0
 public static V3d[] Transformed(this V3d[] points, M33d matrix)
 {
     return(points.Map(p => matrix.Transform(p)));
 }
Esempio n. 19
0
 /// <summary>
 /// Returns new array containing transformed points.
 /// </summary>
 public static V2d[] TransformedDir(this V2d[] pointArray, M33d m)
 {
     return(new V2d[pointArray.LongLength].SetByIndexLong(i => m.TransformDir(pointArray[i])));
 }
Esempio n. 20
0
 public Trafo2d(Trafo2d trafo)
 {
     Forward  = trafo.Forward;
     Backward = trafo.Backward;
 }
Esempio n. 21
0
 public static CameraExtrinsics FromWorld2Camera(M33d rotation, V3d translation)
 => new CameraExtrinsics(rotation.Transposed, -rotation.TransposedTransform(translation));
Esempio n. 22
0
 /// <summary>
 /// Returns new polygon with point transformed.
 /// </summary>
 public static IImmutablePolygon <V2d> TransformPoint(this IImmutablePolygon <V2d> self, int index, M33d trafo)
 => self.SetPoint(index, trafo.TransformPos(self.Points[index]));
Esempio n. 23
0
 /// <summary>
 /// Creates a rigid transformation from a rotation matrix <paramref name="rot"/> and a (subsequent) translation <paramref name="trans"/>.
 /// </summary>
 public Euclidean3d(M33d rot, V3d trans, double epsilon = 1e-12)
 {
     Rot   = Rot3d.FromM33d(rot, epsilon);
     Trans = trans;
 }
Esempio n. 24
0
 public static Trafo2d Scale(double s)
 {
     return(new Trafo2d(M33d.Scale(s),
                        M33d.Scale(1 / s)));
 }
Esempio n. 25
0
 public static Trafo2d Rotation(double angleInRadians)
 {
     return(new Trafo2d(M33d.Rotation(angleInRadians),
                        M33d.Rotation(-angleInRadians)));
 }
Esempio n. 26
0
 public static Trafo2d Scale(V2d sv)
 {
     return(new Trafo2d(M33d.Scale(sv),
                        M33d.Scale(1 / sv)));
 }
Esempio n. 27
0
 public static Trafo2d Translation(double dx, double dy)
 {
     return(new Trafo2d(M33d.Translation(dx, dy),
                        M33d.Translation(-dx, -dy)));
 }
Esempio n. 28
0
 public static Trafo2d Translation(V2d v)
 {
     return(new Trafo2d(M33d.Translation(v),
                        M33d.Translation(-v)));
 }
Esempio n. 29
0
 public static Trafo2d Scale(double sx, double sy)
 {
     return(new Trafo2d(M33d.Scale(sx, sy),
                        M33d.Scale(1 / sx, 1 / sy)));
 }
Esempio n. 30
0
 public Trafo2d(M33d forward, M33d backward)
 {
     Forward  = forward;
     Backward = backward;
 }