Exemplo n.º 1
0
        /// <summary>
        /// Constructs a new instance of the <see cref="PolarPointsGenerator"/> class.
        /// </summary>
        /// <param name="center">The central point around which this class will generate other points.</param>
        /// <param name="xBase">Basis vector that serves as the X axis</param>
        /// <param name="yBase">Basis vector that serves as the Y axis</param>
        /// <remarks><paramref name="xBase"/> and <paramref name="yBase"/> vectors must be orthogonal</remarks>
        public PolarPointsGenerator(Point3D center, Vector3D xBase, Vector3D yBase)
        {
            Contract.Requires(xBase.LengthSquared > 0);
            Contract.Requires(yBase.LengthSquared > 0);
            Contract.Requires(MathUtils3D.AreOrthogonal(xBase, yBase));

            this.center = center;
            xBase.Normalize();
            yBase.Normalize();

            this.xBase = xBase;
            this.yBase = yBase;
        }
Exemplo n.º 2
0
        public SketchPlane(string name, Point3D center, Vector3D xAxis, Vector3D yAxis, Vector3D normal, double width, double height)
        {
            Contract.Requires(!string.IsNullOrEmpty(name));
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);
            Contract.Requires(MathUtils3D.AreOrthogonal(xAxis, yAxis));
            Contract.Requires(MathUtils3D.AreOrthogonal(xAxis, normal));
            Contract.Requires(MathUtils3D.AreOrthogonal(yAxis, normal));

            xAxis.Normalize();
            yAxis.Normalize();
            normal.Normalize();

            Name   = name;
            Center = center;
            XAxis  = xAxis;
            YAxis  = yAxis;
            Normal = normal;
            Width  = width;
            Height = height;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates an approximation of a circle given its center, two orthonormal basis vectors for the plane, and its radius.
        /// </summary>
        /// <param name="center">The circle's center</param>
        /// <param name="u">First basis vector. This is the "X" axis.</param>
        /// <param name="v">Second basis vector. This is the "Y" axis.</param>
        /// <param name="radius">Circle's radius.</param>
        /// <param name="count">Number of points that approximate the circle</param>
        /// <returns>An array of points that form the circle's approximation</returns>
        public static Point3D[] GenerateCircle(Point3D center, Vector3D u, Vector3D v, double radius, int count)
        {
            Contract.Requires(MathUtils3D.AreOrthogonal(u, v));
            Contract.Requires(NumericUtils.AlmostEqual(u.LengthSquared, 1, 10));
            Contract.Requires(NumericUtils.AlmostEqual(v.LengthSquared, 1, 10));
            Contract.Requires(radius > 0);
            Contract.Requires(count >= 3);
            Contract.Ensures(Contract.Result <Point3D[]>() != null);
            Contract.Ensures(Contract.Result <Point3D[]>().Length == count);
            // we cannot really ensure that (?)
            //Contract.Ensures(Contract.ForAll(
            //    Contract.Result<Point3D[]>(),
            //    pnt => NumericUtils.AlmostEqual((pnt - center).LengthSquared, radius * radius, 100)));

            var result = new Point3D[count];

            for (int i = 0; i < count; ++i)
            {
                var fraction = i / (double)count;
                var angle    = 2 * Math.PI * fraction;
                result[i] = center + radius * (Math.Cos(angle) * u + Math.Sin(angle) * v);
            }
            return(result);
        }