Esempio n. 1
0
        private static Vector3D CalculateMove(Body body, Vector3D axis, Axis3D startMoveRay, Axis3D endMoveRay)
        {
            var axisOffset    = body.Frame.Offset;
            var axisDirection = body.Frame * axis;
            var moveAxis      = new Axis3D(axisOffset, axisDirection);

            var(startExist, startPlump) = moveAxis.CalculatePerpendicularPoint(startMoveRay);
            var(endExist, endPlump)     = moveAxis.CalculatePerpendicularPoint(endMoveRay);
            var moveVector = startExist && endExist ? endPlump - startPlump : new Vector3D();

            return(moveVector);
        }
Esempio n. 2
0
        public void CalculatePerpendicularPointTest_WhenTwoCrossingLines_ThenPlumpPointIsCrossPoint()
        {
            var baseAxis   = new Axis3D(new Position3D(0, 0, 100), new Vector3D(1, 1, -1));
            var secondAxis = new Axis3D(new Position3D(0, 0, -100), new Vector3D(1, 1, 1));

            var(success, plumpOnBaseAxis) = baseAxis.CalculatePerpendicularPoint(secondAxis);

            Assert.True(success);
            Assert.Equal(new Position3D(100, 100, 0), plumpOnBaseAxis);
        }
Esempio n. 3
0
        public void CalculatePerpendicularPointTest_WhenTwoLinesInPararllelPlaneXY_ThenPlumpPointIsCalculated()
        {
            var baseAxis   = new Axis3D(new Position3D(10, 20, 0), new Vector3D(1, 0, 0));
            var secondAxis = new Axis3D(new Position3D(10, 20, 100), new Vector3D(0, 1, 0));

            var(success, plumpOnBaseAxis) = baseAxis.CalculatePerpendicularPoint(secondAxis);

            Assert.True(success);
            Assert.Equal(baseAxis.Offset, plumpOnBaseAxis);
        }
Esempio n. 4
0
        private static (bool, Position3D) GetRayIntersectionWithEdge(Axis3D rayAxis, EdgeHL edge)
        {
            var edgeEnd       = edge.End;
            var edgeOffset    = edge.Start;
            var edgeDirection = edgeEnd - edgeOffset;
            var edgeAxis      = new Axis3D(edgeOffset, edgeDirection);

            var(success, intersection) = edgeAxis.CalculatePerpendicularPoint(rayAxis);

            return(success, intersection);
        }
Esempio n. 5
0
        public void CalculatePerpendicularPointTest_WhenLineInPlaneXYAndPosition_ThenPlumpPointIsCalculated()
        {
            var position = new Position3D(100, 100, 200);
            var axis     = new Axis3D(new Position3D(), new Vector3D(1, 1, 0));

            var plump  = axis.CalculatePerpendicularPoint(position);
            var plump2 = position.CalculatePerpendicularPoint(axis);

            var expected = new Position3D(100, 100, 0);

            Assert.Equal(expected, plump);
            Assert.Equal(expected, plump2);
        }
Esempio n. 6
0
        private static double CalculateAngleForAxisLieingInCanvas(
            Position3D bodyTouchPosition,
            double startX,
            double startY,
            Axis3D endMoveRay,
            Axis3D cylinderAxis,
            double canvasWidth,
            double canvasHeight,
            Camera camera
            )
        {
            var angle           = 0.0;
            var cameraDirection = camera.Frame.Ey;

            var direction     = (cameraDirection & cylinderAxis.Direction).Normalize() * 10000.0;
            var offset        = ViewProjection.ProjectCanvasToSceneSystem(startX, startY, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
            var p1            = offset - direction;
            var p2            = offset + direction;
            var projectedAxis = new Axis3D(p1, p2 - p1);

            var(success, plump) = projectedAxis.CalculatePerpendicularPoint(endMoveRay);
            if (success)
            {
                // Ermitteln des Vorzeichens für Drehung
                var sign = (plump - p1).Length < (plump - p2).Length ? -1.0 : 1.0;

                // Ermitteln der Länge der Mausbewegung in Richtung senkrecht zur Rotationsachse
                var(endX, endY) = ViewProjection.ProjectSceneSystemToCanvas(plump, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
                double delta = Vector2DMath.Length(startX, startY, endX, endY);

                // Projektion Berührungspunkt auf Rotationsachse.
                // Ermittel Scheitelpunkte der Rotation auf Achse senkrecht zur Kamera und Rotationsachse.
                // Projektion der Scheitelpunkte auf Canvas.
                // Abstand Scheitelpunkte auf Achse ist die Mausbewegung für 180°.
                // Winkel ist Verhältnis Länge Mausbewegung zur Länge für 180°.
                var plumpPoint = cylinderAxis.CalculatePerpendicularPoint(bodyTouchPosition);
                var distance   = (bodyTouchPosition - plumpPoint).Length;
                direction = direction.Normalize() * distance;
                var startPosition = cylinderAxis.Offset - direction;
                var endPosition   = cylinderAxis.Offset + direction;
                (startX, startY) = ViewProjection.ProjectSceneSystemToCanvas(startPosition, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
                (endX, endY)     = ViewProjection.ProjectSceneSystemToCanvas(endPosition, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
                var lengthOfHalfRotation = Vector2DMath.Length(startX, startY, endX, endY);

                var angleInDegree = 180.0 * delta / lengthOfHalfRotation;

                angle = sign * angleInDegree.DegToRad();
            }

            return(angle);
        }