Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    GD Polygons and Custom Coordinates

    Hi,

    I have a page that's written in jQuery and PHP. It's for censoring vehicle registration plates. What it allows you to do is upload an image, place 4 markers over your number plate and it will draw a filled polygon box over it for you.

    The system works fine in rendering the polygon, except for one thing. For the polygon to actually form a solid shape you have to place the markers starting from the top left and working your way round clockwise as this is how it draws the polygon. If you do the top 2 from the left, then go back to the left side for the bottom you get 2 triangles where the lines cross over; obviously not creating a solid polygon box.

    There are 8 values in an array thats sent into the image function. It takes each 2 numbers out of the array to create 4 marker point coordinates on the image. What I need to do is figure out how to make sure they are sent in the correct order to make the polygon and so the user could place them anywhere, it would still know which was top left, which was top right etc.

    Any ideas? I know my array is 8 figures, however I could if it makes things easier change it so there is 4 arrays within 1 big array; although not sure if that would help matters.

    Hope that makes sense, if not I can explain better with some pictures.

    Thanks,
    Jason

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you could sort the 4 points by adding them together then assending then assign them to an array or something


    PHP Code:
    <?php
    $input
    [0] = '200'//1st click
    $input[1] = '300';
    $input[2] = '500'//2nd click
    $input[3] = '302';
    $input[4] = '198'//3rd click
    $input[5] = '400';
    $input[6] = '505'//4th click
    $input[7] = '401';

    $point[0] = ($input[0] + $input[1]); //=500
    $point[1] = ($input[2] + $input[3]); //=802
    $point[2] = ($input[4] + $input[5]); //=598
    $point[3] = ($input[6] + $input[7]); //=906

    sort($point);
    var_dump($point);
    foreach (
    $point as $k => $v){
        if ((
    $input[0] + $input[1]) == $point[0]){
            
    $output[1][1] = $input[0];
            
    $output[1][2] = $input[1];
        }
        if ((
    $input[2] + $input[3]) == $point[0]){
            
    $output[1][1] = $input[2];
            
    $output[1][2] = $input[3];
        }
        if ((
    $input[4] + $input[5]) == $point[0]){
            
    $output[1][1] = $input[4];
            
    $output[1][2] = $input[5];
        }
        if ((
    $input[6] + $input[7]) == $point[0]){
            
    $output[1][1] = $input[6];
            
    $output[1][2] = $input[7];
        }
    }
    foreach (
    $point as $k => $v){
        if ((
    $input[0] + $input[1]) == $point[2]){
            
    $output[2][1] = $input[0];
            
    $output[2][2] = $input[1];
        }
        if ((
    $input[2] + $input[3]) == $point[2]){
            
    $output[2][1] = $input[2];
            
    $output[2][2] = $input[3];
        }
        if ((
    $input[4] + $input[5]) == $point[2]){
            
    $output[2][1] = $input[4];
            
    $output[2][2] = $input[5];
        }
        if ((
    $input[6] + $input[7]) == $point[2]){
            
    $output[2][1] = $input[6];
            
    $output[2][2] = $input[7];
        }
    }
    foreach (
    $point as $k => $v){
        if ((
    $input[0] + $input[1]) == $point[3]){
            
    $output[3][1] = $input[0];
            
    $output[3][2] = $input[1];
        }
        if ((
    $input[2] + $input[3]) == $point[3]){
            
    $output[3][1] = $input[2];
            
    $output[3][2] = $input[3];
        }
        if ((
    $input[4] + $input[5]) == $point[3]){
            
    $output[3][1] = $input[4];
            
    $output[3][2] = $input[5];
        }
        if ((
    $input[6] + $input[7]) == $point[3]){
            
    $output[3][1] = $input[6];
            
    $output[3][2] = $input[7];
        }
    }
    foreach (
    $point as $k => $v){
        if ((
    $input[0] + $input[1]) == $point[1]){
            
    $output[4][1] = $input[0];
            
    $output[4][2] = $input[1];
        }
        if ((
    $input[2] + $input[3]) == $point[1]){
            
    $output[4][1] = $input[2];
            
    $output[4][2] = $input[3];
        }
        if ((
    $input[4] + $input[5]) == $point[1]){
            
    $output[4][1] = $input[4];
            
    $output[4][2] = $input[5];
        }
        if ((
    $input[6] + $input[7]) == $point[1]){
            
    $output[4][1] = $input[6];
            
    $output[4][2] = $input[7];
        }
    }

    var_dump($output);
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    JasonO (05-22-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •