コード例 #1
0
        /// <summary>
        /// Gets the control point at the given (u, v) index.
        /// </summary>
        /// <param name="u">Index of control-point along surface U direction.</param>
        /// <param name="v">Index of control-point along surface V direction.</param>
        /// <returns>The control point at the given (u, v) index.</returns>
        public ControlPoint GetControlPoint(int u, int v)
        {
            if (u < 0)
            {
                throw new IndexOutOfRangeException("u must be larger than or equal to zero.");
            }
            if (v < 0)
            {
                throw new IndexOutOfRangeException("v must be larger than or equal to zero.");
            }
            if (u >= CountU)
            {
                throw new IndexOutOfRangeException("u must be less than CountU.");
            }
            if (v >= CountV)
            {
                throw new IndexOutOfRangeException("v must be less than CountV.");
            }

            Point4d pt  = new Point4d();
            IntPtr  ptr = m_surface.ConstPointer();

            if (UnsafeNativeMethods.ON_NurbsSurface_GetCV(ptr, u, v, ref pt))
            {
                return(new ControlPoint(pt));
            }

            return(ControlPoint.Unset);
        }
コード例 #2
0
    public static Matrix4d buildReflection(Point4d point)
    {
        float xx = point.x * point.x;
        float xy = point.x * point.y;
        float xz = point.x * point.z;
        float xw = point.x * point.w;

        float yy = point.y * point.y;
        float yz = point.y * point.z;
        float yw = point.y * point.w;

        float zz = point.z * point.z;
        float zw = point.z * point.w;

        float ww = point.w * point.w;

        float pp_h = xx + yy + zz - ww;
        float temp = -2.0f / pp_h;

        Matrix4d ppTI31 = new Matrix4d();

        ppTI31.SetRow(0, new Point4d(xx * temp + 1, xy * temp, xz * temp, -xw * temp));
        ppTI31.SetRow(1, new Point4d(xy * temp, yy * temp + 1, yz * temp, -yw * temp));
        ppTI31.SetRow(2, new Point4d(xz * temp, yz * temp, zz * temp + 1, -zw * temp));
        ppTI31.SetRow(3, new Point4d(xw * temp, yw * temp, zw * temp, -ww * temp + 1));

        return(ppTI31);
    }
コード例 #3
0
    public static Point4d GetMidpoint(Point4d pointA, Point4d pointB)
    {
        float coefficientA = Mathf.Sqrt(MinkowskiInnerProduct(pointB, pointB) * MinkowskiInnerProduct(pointA, pointB));
        float coefficientB = Mathf.Sqrt(MinkowskiInnerProduct(pointA, pointA) * MinkowskiInnerProduct(pointA, pointB));

        return(new Point4d(pointA.x * coefficientA + pointB.x * coefficientB, pointA.y * coefficientA + pointB.y * coefficientB, pointA.z * coefficientA + pointB.z * coefficientB, pointA.w * coefficientA + pointB.w * coefficientB));
    }
コード例 #4
0
 public void sub(Point4d t1)
 {
     this.x = this.x - (t1.x);
     this.y = this.y - (t1.y);
     this.z = this.z - (t1.z);
     this.w = this.w - (t1.w);
 }
コード例 #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const int degree     = 2;
            const int cv_count   = 7;
            const int knot_count = cv_count + degree - 1;
            const int order      = degree + 1;

            var points = new Point3d[cv_count];

            points[0] = new Point3d(2.500, 0.000, 0.000);
            points[1] = new Point3d(5.000, 0.000, 0.000);
            points[2] = new Point3d(3.750, 2.165, 0.000);
            points[3] = new Point3d(2.500, 4.330, 0.000);
            points[4] = new Point3d(1.250, 2.165, 0.000);
            points[5] = new Point3d(0.000, 0.000, 0.000);
            points[6] = new Point3d(2.500, 0.000, 0.000);

            var weights = new double[cv_count];

            weights[0] = 1.0;
            weights[1] = 0.5;
            weights[2] = 1.0;
            weights[3] = 0.5;
            weights[4] = 1.0;
            weights[5] = 0.5;
            weights[6] = 1.0;

            var knots = new double[knot_count];

            knots[0] = 0.000;
            knots[1] = 0.000;
            knots[2] = 0.333;
            knots[3] = 0.333;
            knots[4] = 0.667;
            knots[5] = 0.667;
            knots[6] = 1.000;
            knots[7] = 1.000;

            var curve = new NurbsCurve(3, true, order, cv_count);

            for (var ci = 0; ci < cv_count; ci++)
            {
                var cv = new Point4d(points[ci].X * weights[ci], points[ci].Y * weights[ci], points[ci].Z * weights[ci], weights[ci]);
                curve.Points.SetPoint(ci, cv);
            }

            for (var ki = 0; ki < knot_count; ki++)
            {
                curve.Knots[ki] = knots[ki];
            }

            if (curve.IsValid)
            {
                doc.Objects.AddCurve(curve);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
コード例 #6
0
        public void CanBe_Created()
        {
            var pt3  = new Point3d(1, 0, 0);
            var pt4  = new Point4d(1, 0, 0, 1);
            var pt42 = new Point4d(pt3);

            Assert.Equal(pt42, pt4);
        }
コード例 #7
0
 public static float getThetaByPoint(Point4d p)
 {
     if (p.y == 0.0f)
     {
         return(0.0f);
     }
     return(Mathf.Atan(p.y / p.x));
 }
コード例 #8
0
 public static float getPhiByPoint(Point4d p)
 {
     if (p.z == 0.0f)
     {
         return(0.0f);
     }
     return(Mathf.Atan(Mathf.Sqrt(p.x * p.x + p.y * p.y) / p.z));
 }
コード例 #9
0
    public static Vector3 projectAndGetVect3(Point4d p)
    {
        float tx = p.x / (p.w);
        float ty = p.y / (p.w);
        float tz = p.z / (p.w);

        return(new Vector3(tx, ty, tz));
    }
コード例 #10
0
    // The usual vector dot product computed from x, y, and z only.
    public float vectorDot3(Point4d v1)
    {
        float tx = this.x * (v1.x);
        float ty = this.y * (v1.y);
        float tz = this.z * (v1.z);

        return(tx + (ty) + (tz));
    }
コード例 #11
0
        public void CanToggle_IsUnset_OnWeightChange()
        {
            var pt = new Point4d();

            Assert.True(pt.IsUnset);
            pt.Weight += 1;
            Assert.False(pt.IsUnset);
        }
コード例 #12
0
    public static void makeUnitVector(Point4d p)
    {
        float s = p.w * vectorLength(p);

        p.x /= s;
        p.y /= s;
        p.z /= s;
        p.w  = 1.0f;
    }
コード例 #13
0
    public static Vector3 projectAndGetVect3FromHypToEuc(Point4d p)
    {
        Vector3 temp = projectAndGetVect3(p);

        temp.x = HyperbolicMath.euclideanDistance(temp.x);
        temp.y = HyperbolicMath.euclideanDistance(temp.y);
        temp.z = HyperbolicMath.euclideanDistance(temp.z);
        return(temp);
    }
コード例 #14
0
    // Returns the Minkowski inner product of this with y.
    public float minkowski(Point4d v)
    {
        float tx = this.x * (v.x);
        float ty = this.y * (v.y);
        float tz = this.z * (v.z);
        float tw = this.w * (v.w);

        return(tx + (ty) + (tz) - (tw));
    }
コード例 #15
0
    // Euclidean norm of homogeneous coordinates [and equivalent to
    // Point4d.distance(new Point4d(0, 0, 0, 0))].
    public float vectorLength(Point4d p)
    {
        float x2 = this.x * this.x;
        float y2 = this.y * this.y;
        float z2 = this.z * this.z;
        float w2 = this.w * this.w;

        return(x2 + (y2) + (z2) / Mathf.Sqrt(w2));
    }
コード例 #16
0
    // this = s*t1 + t2
    public void scaleAdd(float s, Point4d t1, Point4d t2)
    {
        float tx = t1.x * s + (t2.x);
        float ty = t1.y * s + (t2.y);
        float tz = t1.z * s + (t2.z);
        float tw = t1.w * s + (t2.w);

        this.x = tx; this.y = ty; this.z = tz; this.w = tw;
    }
コード例 #17
0
    public void transform(Point4d v)
    {
        float x = this.matrix4d.m00 * v.x + (this.matrix4d.m01 * v.y) + (this.matrix4d.m02 * v.z) + (this.matrix4d.m03 * v.w);
        float y = this.matrix4d.m10 * v.x + (this.matrix4d.m11 * v.y) + (this.matrix4d.m12 * v.z) + (this.matrix4d.m13 * v.w);
        float z = this.matrix4d.m20 * v.x + (this.matrix4d.m21 * v.y) + (this.matrix4d.m22 * v.z) + (this.matrix4d.m23 * v.w);
        float w = this.matrix4d.m30 * v.x + (this.matrix4d.m31 * v.y) + (this.matrix4d.m32 * v.z) + (this.matrix4d.m33 * v.w);

        v.x = x; v.y = y; v.z = z; v.w = w;
    }
コード例 #18
0
        public void CanCreate_FromPointAndWeight()
        {
            var       pt     = new Point3d(1, 0, 1);
            const int weight = 1;
            var       pt4    = new Point4d(pt, weight);

            Assert.Equal(pt, pt4.Position);
            Assert.Equal(weight, pt4.Weight);
        }
コード例 #19
0
 public SliceBasedVoxelDataStructure() : base()
 {
     _positionCache = new Point4d(0, 0, 0, 1);
     _indexCache    = new Point4d(0, 0, 0, 1);
     _slices        = new List <DicomSlice>();
     GlobalMax      = new Voxel()
     {
         Value = float.MinValue
     };
     Voxels = new Voxels(this);
 }
コード例 #20
0
        public void CanBe_Negated()
        {
            const double a = 3.3;
            const double b = 2.2;
            const double c = 4.11;
            const double d = 1.344;

            var ptA      = new Point4d(a, b, c, d);
            var ptResult = new Point4d(-a, -b, -c, d);

            Assert.True(-ptA == ptResult);
        }
コード例 #21
0
        public void CanBe_Divided()
        {
            const double a        = 3.3;
            const double b        = 2.2;
            const double c        = 4.11;
            const double d        = 1.344;
            const double m        = 1.45;
            var          ptA      = new Point4d(a, b, c, d);
            var          ptResult = new Point4d(a / m, b / m, c / m, d / m);

            Assert.True(ptA / m == ptResult);
        }
コード例 #22
0
        public void CanBe_Multiplied()
        {
            const double a        = 3.3;
            const double b        = 2.2;
            const double c        = 4.11;
            const double d        = 1.344;
            const double m        = 1.45;
            var          ptA      = new Point4d(a, b, c, d);
            var          ptResult = new Point4d(a * m, b * m, c * m, d * m);

            Assert.True(ptA * m == ptResult);
            Assert.True(m * ptA == ptResult);
        }
コード例 #23
0
        public void CanBe_Created()
        {
            var pt2  = new Point2d(1, 0);
            var pt3  = new Point3d(1, 0, 0);
            var pt4  = new Point4d(1, 0, 0, 1);
            var npt2 = new Point3d(pt2);
            var npt4 = new Point3d(pt4);
            var npt5 = ( Point3d )pt4;

            Assert.True(pt3 == npt2);
            Assert.True(pt3 == npt4);
            Assert.True(pt3 == npt5);
        }
コード例 #24
0
        public void CanBe_Added()
        {
            const double a = 3.3;
            const double b = 2.2;
            const double c = 4.11;
            const double d = 1.344;

            var ptA      = new Point4d(a, b, c, d);
            var ptB      = new Point4d(b, c, a, d);
            var ptResult = new Point4d(a + b, b + c, c + a, d + d);

            Assert.True(ptA + ptB == ptResult);
        }
コード例 #25
0
        public void CanBe_Added_WithVector()
        {
            const double a = 3.3;
            const double b = 2.2;
            const double c = 4.11;
            const double d = 1.344;

            var ptA      = new Point4d(a, b, c, d);
            var v        = new Vector3d(b, c, a);
            var ptResult = new Point4d(a + b, b + c, c + a, d);

            Assert.True(ptA + v == ptResult);
        }
コード例 #26
0
    public static float getRotAngleY(Point4d p)
    {
        float yAngRot;

        if (p.z == 0.0f)
        {
            yAngRot = 0.0f;
        }
        else
        {
            yAngRot = Mathf.Atan(p.x / p.z);
        }
        return(yAngRot);
    }
コード例 #27
0
        public void CanBe_Subtracted()
        {
            const double a = 3.3;
            const double b = 2.2;
            const double c = 4.11;
            const double d = 1.344;

            var ptA      = new Point4d(a, b, c, d);
            var ptB      = new Point4d(b, c, a, d);
            var expected = new Point4d(a - b, b - c, c - a, d - d);
            var actual   = ptA - ptB;

            Assert.Equal(expected, actual);
        }
コード例 #28
0
    public static float getRotAngleX(Point4d p)
    {
        float xAngRot;

        if (p.z == 0.0f)
        {
            xAngRot = 0.0f;
        }
        else
        {
            xAngRot = Mathf.Atan(p.y / p.z);
        }
        return(xAngRot);
    }
コード例 #29
0
    public static Matrix4d buildCanonicalOrientationEuclidean(Point4d a, Point4d b)
    {
        Point4d orientation = new Point4d(b.x - a.x, b.y - a.y, b.z - a.z);
        //float r = Mathf.Sqrt(orientation.x * orientation.x + orientation.y * orientation.y + orientation.z * orientation.z);
        float    theta       = Mathf.Atan(orientation.y / orientation.x);
        float    phi         = Mathf.Atan(Mathf.Sqrt(orientation.x * orientation.x + orientation.y * orientation.y) / orientation.z);
        Matrix4d rotationMat = new Matrix4d();

        rotationMat.rotX(theta);
        Matrix4d rotationMatResult = new Matrix4d();

        rotationMatResult.rotZ(phi);
        rotationMatResult *= rotationMat;
        return(rotationMatResult); //TODO: implement
    }
コード例 #30
0
        public Point4d GetControlVertex4d(int index)
        {
            if (index < 0 || index >= ControlVertexCount)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            var    rc             = new Point4d();
            IntPtr const_ptr_this = ConstPointer();

            if (!UnsafeNativeMethods.ON_BezierCurve_GetCV4d(const_ptr_this, index, ref rc))
            {
                return(Point4d.Unset);
            }
            return(rc);
        }
コード例 #31
0
 internal static extern bool ON_4dPoint_Normalize(ref Point4d a);
コード例 #32
0
 internal static extern bool ON_4dPoint_Equality(Point4d a, Point4d b);
コード例 #33
0
 internal static extern bool ON_NurbsSurface_SetCV(IntPtr pNurbsSurface, int u, int v, ref Point4d point);
コード例 #34
0
 internal static extern bool ON_NurbsCurve_GetCV2(IntPtr pCurve, int cvIndex, ref Point4d point);
コード例 #35
0
 internal static extern bool ON_BezierCurve_GetCV4d(IntPtr pConstBezierCurve, int index, ref Point4d point);
コード例 #36
0
 internal static extern IntPtr ON_BezierCurve_New4d(int count, Point4d[] points);
コード例 #37
0
 internal static extern void Rdk_ContentField_SetPoint4dValue(IntPtr pField, Point4d v, int iCC);
コード例 #38
0
 internal static extern void Rdk_ContentField_Point4dValue(IntPtr pField, ref Point4d p);
コード例 #39
0
 internal static extern int Rdk_Variant_Get4dPointValue(IntPtr pV, ref Point4d v);
コード例 #40
0
 internal static extern void Rdk_Variant_Set4dPointValue(IntPtr pV, Point4d v);
コード例 #41
0
 /// <summary>Get location of a control vertex.</summary>
 /// <param name="index">
 /// Control vertex index (0 &lt;= index &lt; ControlVertexCount)
 /// </param>
 /// <returns>
 /// Homogenous value of control vertex. If the bezier is not
 /// rational, the weight is 1.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">when index is out of range</exception>
 public Point4d GetControlVertex4d(int index)
 {
   if( index<0 || index>=ControlVertexCount )
     throw new ArgumentOutOfRangeException("index");
   Point4d rc = new Point4d();
   IntPtr pConstThis = ConstPointer();
   if (!UnsafeNativeMethods.ON_BezierCurve_GetCV4d(pConstThis, index, ref rc))
     return Point4d.Unset;
   return rc;
 }