public static Matrix4x4 CreateFromAxisAngleOrigin(PointDirection3 p, float angle)
 {
     return
         (Matrix4x4.CreateTranslation(-p.Point)
          * Matrix4x4.CreateFromAxisAngle(p.Direction.Unit(), angle)
          * Matrix4x4.CreateTranslation(p.Point));
 }
 public static void GLVertex3AndNormal3(this PointDirection3 @this)
 {
     if ([email protected](default(Vector3)))
     {
         @this.Direction.GLNormal3();
     }
     @this.Point.GLVertex3();
 }
Beispiel #3
0
        public static ISurface CreatePlanarSurface(this IModeler activeModeler, PointDirection3 plane)
        {
            var planeDirection = plane.Direction;
            var vRef           = planeDirection.Orthogonal();
            var mathVector     = planeDirection;
            var vRootPoint     = plane.Point;

            return((ISurface)activeModeler.CreatePlanarSurface2(vRootPoint.ToDoubles(), mathVector.ToDoubles(), vRef.ToDoubles()));
        }
        public void IntersectingShouldBeMatched(Matrix4x4 transform, Triangle triangle)
        {
            var plane = new PointDirection3(Vector3.Zero, Vector3.UnitX);

            var ttriangle = triangle.ApplyTransform(transform);
            var pplane    = plane.ApplyTransform(transform);

            var intersectionO = ttriangle.IntersectPlane(pplane);

            intersectionO.IsSome.Should().Be(true);
        }
        public void NonIntersectingLinesShouldReturnNone_v2(Vector3 position, Vector3 forward, Vector3 up)
        {
            var line  = new Edge3(new Vector3(-1, -2, -3) * 0.001, new Vector3(-1, -2, -3));
            var plane = new PointDirection3(Vector3.Zero, Vector3.UnitX);

            var transform = Matrix4x4.CreateWorld(position, forward, up);

            var tline  = line.ApplyTransform(transform);
            var tplane = plane.ApplyTransform(transform);

            tline.IntersectPlane(tplane).IsSome.Should().BeFalse();
        }
        public void IntersectingLineWithPlaneShouldReturnIntersectionPoint(Vector3 position, Vector3 forward, Vector3 up)
        {
            var line  = new Edge3(new Vector3(1, 2, 3), new Vector3(-1, -2, -3));
            var plane = new PointDirection3(Vector3.Zero, Vector3.UnitX);

            var transform = Matrix4x4.CreateWorld(position, forward, up);

            var tline  = line.ApplyTransform(transform);
            var tplane = plane.ApplyTransform(transform);

            var intersectPlane = tline.IntersectPlane(tplane).__Value__();
            var intersectPlaneExpectedValue = Vector3.Transform(Vector3.Zero, transform);

            intersectPlane.Should().BeApproximately(intersectPlaneExpectedValue, 1e-6);
        }
Beispiel #7
0
        /// <summary>
        /// Doesn't work when intersecting with wire bodies.
        /// </summary>
        /// <param name="modelDoc"></param>
        /// <param name="ray"></param>
        /// <param name="bodies"></param>
        /// <param name="hitRadius"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static List <RayIntersection> GetRayIntersections(this IModelDoc2 modelDoc, PointDirection3 ray, IBody2[] bodies, double hitRadius, double offset)
        {
            var icount = modelDoc.RayIntersections
                             (BodiesIn: bodies
                             , BasePointsIn: ray.Point.ToDoubles()
                             , VectorsIn: ray.Direction.ToDoubles()
                             , Options: (int)(swRayPtsOpts_e.swRayPtsOptsENTRY_EXIT | swRayPtsOpts_e.swRayPtsOptsNORMALS |
                                              swRayPtsOpts_e.swRayPtsOptsTOPOLS | swRayPtsOpts_e.swRayPtsOptsUNBLOCK)
                             , HitRadius: hitRadius
                             , Offset: offset);
            var result = modelDoc.GetRayIntersectionsPoints().CastArray <double>();

            const int fields = 9;

            return(Enumerable.Range(0, icount)
                   .Select(i =>
            {
                var baseOffset = i * fields;

                var bodyIndex = result[baseOffset + 0];
                var rayIndex = result[baseOffset + 1];
                var intersectionType = result[baseOffset + 2];
                var x = result[baseOffset + 3];
                var y = result[baseOffset + 4];
                var z = result[baseOffset + 5];
                var nx = result[baseOffset + 6];
                var ny = result[baseOffset + 7];
                var nz = result[baseOffset + 8];

                return new RayIntersection(
                    bodies[(int)bodyIndex],
                    (int)rayIndex,
                    (swRayPtsResults_e)intersectionType,
                    new [] { x, y, z }.ToVector3(),
                    new[] { nx, ny, nz }.ToVector3()
                    );
            }).ToList());
        }