public void objectGroundCollision2()
    {
        long t = System.currentTimeMillis();
        IFunction func = new IFunction()
        {
            @Override
            public double function(double x)
            {
                return scene.getGround().function((int) x);
            }
        };
        
        for (ObjectProperties object : scene.getObjects())
        {
            if (object.isPinned)
                continue;
            // this helps to define an interval
            // double range = object.velocity.getX() * 2;
            double range = object.getRadius() * 5;
            de.engine.math.Vector nextPos = object.getNextPosition();
            
            distCalcer.setPoint(nextPos);
            distCalcer.setFunction(func);
            double dist = distCalcer.calculateDistanceBetweenFunctionPoint(nextPos.getX() - range, nextPos.getX() + range);
            
            object.closest_point = new de.engine.math.Vector(distCalcer.getLastSolvedX(), scene.getGround().function((int) distCalcer.getLastSolvedX()));
            
            if (dist < object.getRadius())
            {
                if (object instanceof Circle)
                {
                    object.isPinned = true;
                }
                else if (object instanceof Polygon)
                {
                    Polygon polygon = (Polygon) object;
                    List<Vector> rotatedPoints = new ArrayList<>();
                    
                    for (Vector point : polygon.points)
                    {
                        
                        rotatedPoints.add(Util.add(polygon.world_position.rotation.getMatrix().multVector(point),
                                polygon.getPosition()));
                    }
                    
                    int length = polygon.points.length;
                    
                    for (int i = 0; i < length; i++)
                    {
                        Vector p1 = rotatedPoints.get(i);
                        Vector p2 = rotatedPoints.get((i + 1)% length);
                        
                        if (p1.getX() == p2.getX())
                        {
                            continue;
                        }
                        
                        StraightLine line = new StraightLine(p1, p2);
                        
                        distCalcer.setStraightLine(line);
                        dist = distCalcer.findRootBetweenFunctionLine();
                        
                        if (dist <= 0.1)
                        {
                            double x = distCalcer.getLastSolvedX();
                            double y = line.function(x);
                            
                            polygon.closest_point = new Vector(x, y);
                            polygon.isPinned = true;
                            break;
                        }
                    }
                }
            }
        }
        DebugMonitor.getInstance().updateMessage("distCalc", "" + (System.currentTimeMillis() - t));
    }