pythonmathcoordinates

Calculate the distance on a document from point to point in relative units


I have a template pdf file (although for solving this problem it is absolutely not important, the file can be like an image). The file size is

dimensions = (5725, 4015), where dimensions[0] - axis x, dimensions[1] - axis y

In this template document, information is presented as key: value. Conditional example: Name - Mark, Profession - plumber, etc.

I have the coordinates of the upper right corners of the key and value. For example, for the string "Name - Mark":

point_for_key = (2027.1044921875, 1610.15625)

point_for_value = (2725.0244140625, 1610.15625)

Next, I look for the distance between these two points, so that in the following documents, knowing the coordinates for the key and the distance to the value, I can correctly find the value

distance_value_tag = math.dist(point_for_key, point_for_value)
print(distance_value_tag) # *697.919921875*

It is clear that I get distance_value_tag in absolute units. That is (it was not in vain that I specified the document size at the beginning), if the dimensions of the next document changes (but it will correspond to the template document), then as I understand it, distance_value_tag will not be relevant. I somehow need to calculate distance_value_tag in relative units ​​and recalculate distance_value_tag for each subsequent document depending on its size.

For example, if I get a document of the same template, but with dimensions = (7442, 5220), then the distance_value_tag that I calculated for the template document will be irrelevant on the new document, and I will not find the value for the key I need.

How to recalculate the distance_value_tag in relative units?


Solution

  • your second template is 1.3 larger than the first thus all X & Y units in one need to be transformed by 1.3 or 0.7692. This is simply any ratio or proportion taken from both same length thus approximately.

    7442, 5220  =  1.3   1.3
    ----, ----     --- & ---
    5725, 4015      1     1
    

    Ans 697.919921875 x 1.3 = 907.2958984375

    Actually to be more precise you could do the 2 separately and use Pythagoras such that

    new = ²√( (newW/oldW x (ValueX-KeyX))² + (newH/oldH x (ValueY-KeyY))² )
    new = ²√(      (7442/5725 x 697.919921875)² + (5220/4015 x 0)² )
    

    Correct Answer = 907.2349447325328

    Using diagonal lengths rather than the simpler same X or same Y.

    enter image description here

    SIDE NOTE I did not use any ChatBot but was interested to compare notes afterwards to see if it fared better and it gives me my incorrect earlier answer! I had suggested incorrectly then Ans = 895.6398ish

    what is final value ?
    The final value for the new absolute distance, based on the new document size, is approximately 895.64.
    
    : Stack Overflow
    Try again that is wrong !
    Let's correct that calculation. The correct approach involves using the Pythagorean theorem to account for changes in both the x and y dimensions.
    When you run this code, the new absolute distance should be approximately 895.64
    

    Artificial Idiot its correction is the same wrong answer each time. Finally after pointing out its errors in maths it agrees closer but not perfect, sorry the sqrt is not included in plain text!

    Now, we use these scaling factors to find the new distance:
    new_distance_value_tag = (1.299×697.919921875)*2 + (1.300×0)*2
    This simplifies to:
    new_distance_value_tag = ( 906.8 )*2 + 0*2
    = 906.8
    

    So, the correct new absolute distance is approximately 906.8.

    I hope this clears up the confusion! If you have any further questions, feel free to ask.
    better but not perfect
    I appreciate your patience. Let's refine the calculation to ensure accuracy.
    So, the correct new absolute distance is approximately 906.8.

    I give up, it is very poor maths if repeating the same poor answer.