コード例 #1
0
        /** Creates a Line from the given start with the given length in the given direction
         * This function should only be used for the first pathpart which needs a startpoint.
         * All other pathparts should take their start and direction from the previous pathpart,
         * see the other functions.
         *
         * - Direction is given in degree, starting at 3 o'clock (0) and rotating clockwise
         * - Direction can be any number but should be between 0-360
         * **/
        public static LinePathPart line(double length, double direction, Point2D start)
        {
            // Default values, not needed right now. May need to fix later
            double speed   = 0.0;
            bool   reverse = false;

            // Generates the genomePart equal to this PathPart and adds it to the genome
            // Length is length * 2 -1 because it is generated as a random number 0-7 and then multiplied by 0.5 and added 0.5
            // The original number 0-7 is needed here however for the genome
            // Same for the angle. (*(-10/5))
            GenomePart part = new GenomePart(false, length * 2 - 1, 0, false);

            Variables.genome.add(part);

            // 27 Pixels are 1 meter
            length *= 27;

            double directionR = direction;

            // The new endpoint is to the right of the startpoint ("3 o'clock) and will be rotated later
            Point2D endpoint = new Point2D(start.x + length, start.y);

            // Endpoint is rotated by 'direction' around the start
            endpoint = EZPathFollowing.Point2D.rotateAround(endpoint, start, directionR);
            return(new LinePathPart(start, endpoint, reverse, speed, direction));
        }
コード例 #2
0
        /**
         * This function is used for all lines except the first one. It needs neither direction nor
         * start since it starts at the end of the previous line/curve and also shares its direction
         * **/
        public static LinePathPart line(double length)
        {
            // Default values, not needed right now. May need to fix later
            double speed   = 0.0;
            bool   reverse = false;

            // Generates the genomePart equal to this PathPart and adds it to the genome
            GenomePart part = new GenomePart(false, length * 2 - 1, 0, false);

            Variables.genome.add(part);

            // 27 Pixels are 1 meter
            length *= 27;

            // Takes the start and direction from the previous pathpart
            Point2D start     = Variables.path.Last.Value.getEnd();
            double  direction = Variables.path.Last.Value.orientationDouble();

            double directionR = direction;

            // The new endpoint is to the right of the startpoint ("3 o'clock) and will be rotated later
            Point2D endpoint = new Point2D(start.x + length, start.y);

            // Endpoint is rotated by 'direction' around the start
            endpoint = EZPathFollowing.Point2D.rotateAround(endpoint, start, directionR);
            return(new LinePathPart(start, endpoint, reverse, speed, direction));
        }
コード例 #3
0
        /**
         * This function is used for all curves except the first one. It needs neither direction nor
         * start since it starts at the end of the previous line/curve and also shares its direction
         * **/
        public static CirclePathPart curve(double radius, double angle, bool driveRight)
        {
            // Default values, not needed right now. May need to fix later
            double speed   = 0.0;
            bool   reverse = false;

            // Generates the genomePart equal to this PathPart and adds it to the genome
            GenomePart part = new GenomePart(true, radius * 2 - 1, ((angle * 180 / Math.PI) - 10) / 5, driveRight);

            Variables.genome.add(part);

            // 27 Pixels are 1 meter
            radius *= 27;

            // Takes the start and direction from the previous pathpart
            Point2D start     = Variables.path.Last.Value.getEnd();
            double  direction = Variables.path.Last.Value.orientationDouble();

            double directionR = (direction > 180)
                ? 360 - direction
                : direction;

            // The new center is to the right of the startpoint ("3 o'clock) and will be rotated later
            Point2D center = new Point2D(start.x + radius, start.y);

            // Center is rotated by 'direction' around the start.
            if (direction > 180)
            {
                center = EZPathFollowing.Point2D.rotateAroundCW(center, start, directionR);
            }
            else
            {
                center = EZPathFollowing.Point2D.rotateAround(center, start, directionR);
            }

            // To get the center the current center point has to be moved by 90° or -90° around the start, depending on driveRight
            double rightAngle = (driveRight == true)
                ? Math.PI / 2
                : -Math.PI / 2;

            center = EZPathFollowing.Point2D.rotateAround(center, start, rightAngle);

            // Initializes the endpoint
            Point2D endpoint;

            // Again, for driveRight = false the angles have to be reversed and angle has to be converted to radian
            double angleR = (driveRight == true)
                ? angle
                : -angle;

            // Now the startpoint is rotated around the center by angle to get the endpoint
            endpoint = EZPathFollowing.Point2D.rotateAround(start, center, angleR);

            return(new CirclePathPart(start, endpoint, center, driveRight, reverse, speed, angle, direction));
        }
コード例 #4
0
        /**
         * This function is used for all curves except the first one. It needs neither direction nor
         * start since it starts at the end of the previous line/curve and also shares its direction
         * **/
        public static CirclePathPart curve(double radius, double angle, bool driveRight)
        {
            // Default values, not needed right now. May need to fix later
            double speed = 0.0;
            bool reverse = false;

            // Generates the genomePart equal to this PathPart and adds it to the genome
            GenomePart part = new GenomePart(true, radius * 2 - 1, ((angle * 180 / Math.PI) - 10) / 5, driveRight);
            Variables.genome.add(part);

            // 27 Pixels are 1 meter
            radius *= 27;

            // Takes the start and direction from the previous pathpart
            Point2D start = Variables.path.Last.Value.getEnd();
            double direction = Variables.path.Last.Value.orientationDouble();

            double directionR = (direction > 180)
                ? 360 - direction
                : direction;

            // The new center is to the right of the startpoint ("3 o'clock) and will be rotated later
            Point2D center = new Point2D(start.x + radius, start.y);

            // Center is rotated by 'direction' around the start.
            if (direction > 180)
                center = EZPathFollowing.Point2D.rotateAroundCW(center, start, directionR);
            else
                center = EZPathFollowing.Point2D.rotateAround(center, start, directionR);

            // To get the center the current center point has to be moved by 90° or -90° around the start, depending on driveRight
            double rightAngle = (driveRight == true)
                ? Math.PI / 2
                : -Math.PI / 2;

            center = EZPathFollowing.Point2D.rotateAround(center, start, rightAngle);

            // Initializes the endpoint
            Point2D endpoint;

            // Again, for driveRight = false the angles have to be reversed and angle has to be converted to radian
            double angleR = (driveRight == true)
                ? angle
                : -angle;

            // Now the startpoint is rotated around the center by angle to get the endpoint
            endpoint = EZPathFollowing.Point2D.rotateAround(start, center, angleR);

            return new CirclePathPart(start, endpoint, center, driveRight, reverse, speed, angle, direction);
        }
コード例 #5
0
        /**
         * This function is used for all lines except the first one. It needs neither direction nor
         * start since it starts at the end of the previous line/curve and also shares its direction
         * **/
        public static LinePathPart line(double length)
        {
            // Default values, not needed right now. May need to fix later
            double speed = 0.0;
            bool reverse = false;

            // Generates the genomePart equal to this PathPart and adds it to the genome
            GenomePart part = new GenomePart(false, length * 2 - 1, 0, false);
            Variables.genome.add(part);

            // 27 Pixels are 1 meter
            length *= 27;

            // Takes the start and direction from the previous pathpart
            Point2D start = Variables.path.Last.Value.getEnd();
            double direction = Variables.path.Last.Value.orientationDouble();

            double directionR = direction;

            // The new endpoint is to the right of the startpoint ("3 o'clock) and will be rotated later
            Point2D endpoint = new Point2D(start.x + length, start.y);

            // Endpoint is rotated by 'direction' around the start
            endpoint = EZPathFollowing.Point2D.rotateAround(endpoint, start, directionR);
            return new LinePathPart(start, endpoint, reverse, speed, direction);
        }
コード例 #6
0
        /** Creates a Line from the given start with the given length in the given direction
         * This function should only be used for the first pathpart which needs a startpoint.
         * All other pathparts should take their start and direction from the previous pathpart,
         * see the other functions.
         *
         * - Direction is given in degree, starting at 3 o'clock (0) and rotating clockwise
         * - Direction can be any number but should be between 0-360
         * **/
        public static LinePathPart line(double length, double direction, Point2D start)
        {
            // Default values, not needed right now. May need to fix later
            double speed = 0.0;
            bool reverse = false;

            // Generates the genomePart equal to this PathPart and adds it to the genome
            // Length is length * 2 -1 because it is generated as a random number 0-7 and then multiplied by 0.5 and added 0.5
            // The original number 0-7 is needed here however for the genome
            // Same for the angle. (*(-10/5))
            GenomePart part = new GenomePart(false, length * 2 -1, 0, false);
            Variables.genome.add(part);

            // 27 Pixels are 1 meter
            length *= 27;

            double directionR = direction;

            // The new endpoint is to the right of the startpoint ("3 o'clock) and will be rotated later
            Point2D endpoint = new Point2D(start.x + length, start.y);

            // Endpoint is rotated by 'direction' around the start
            endpoint = EZPathFollowing.Point2D.rotateAround(endpoint, start, directionR);
            return new LinePathPart(start, endpoint, reverse, speed, direction);
        }