Algorithm / Formula on a coordinate value (x,y) to retrieve something like ((x,y),(x,y)) (Re-worded)

79 Views Asked by At

I'm trying to find a mathematical formula/function that gets 2 coordinates (x,y) and returns 4 coordinates (x1,y1,x2,y2) or ((x,y), (x,y)) (however you want to format it as)

so for example, sending: (7,2) would return: 3, -2, -2, 3 instead of your basic (7/2,1)

Conditions:

  • can't return something like #,0,#,0; it's just a basic slope formula (unless it's impossible and 100% needed)
  • needs to reach to reach the end coordinate (what you originally sent to it) by adding the first set of values with the secondary as many times as needed ex: (1,2,3,4) or ((1,2),(3,4)) var x,y = 0,0 -- Starting coordinates 1,2 (add 1,2) 4,6 (add 3,4) 5,8 (add 1,2) 8,12 (add 3,4) ... ETC -- Keep going until it hits the original coordinate (whatever you inputted into the function)
  • Integer (whole number), positive or negative, cannot be a decimal

The code I'm looking for:

function calculate( x, y )
   *insert code*
   return #, #, #, #;
end

Proof: (7,2) -> (3,-2,-2,3) or ((3,-2),(-2,3))

First set: 3,-2 Second set: -2,3

    0,0 (start at)
    3,-2 (add 3,-2) -- 1
    1, 1 (add -2,3) -- 2
    4,-1 (add 3,-2) -- 1
    2,2 (add -2,3) -- 2
    5,0 (add 3,-2) -- 1
    3,3 (add -2,3) -- 2
    6,1 (add 3,-2) -- 1
    4,4 (add -2,3) -- 2
    7,2 (add 3,-2) -- END

Code (somewhat) for the proof above:

ogX/Y - original X/Y (before you send it into the calculate function
a,b - x1,y1
c,d - x2,y2
function getPath( ogX, ogY, a,b, c,d )
    local Paths = {};
    local x, y = 0, 0;
    for index = 1, <already done>, 1 do
       if index%2 == 0 then // or have it == 1 for the flipped version
           x+=a; y+=b;
       else
           x+=c; y+=d;
       end
       if x == ogX and y == ogY then return Paths; end
    end
end

Basically from the code, this system is supposed to be a sort of path for a coordinate field. If you plot the points, it should somewhat visually resemble a zig-zag. There are probably many possibilities, so what I'm looking for is one that isn't the most extreme or exaggerated line far from the original flat slope line while not also being the slope line

Goal: I'm making a very large long-term project, and this project uses hexagonal cells to move around (it's like a normal coordinate graph except the Y axis is tilted a bit) Anyways, basically in my game, there's this thing called DIRECTION (value of 1-6) When you move non-linearly, the player can drag their mouse either to the left or right of their screen while holding down their mouse to pick which direction they want to face. But here's the thing, choosing the direction also affects the movement of cells you walk across (which is important). (see the image, red for one side, pink for the other) With the usage of the 4 numbers (or 2 coordinates), depending on the direction (which is just set to a true/false for left/right) I can either start with the first set or the second set to get the path

I kinda already have a setup, but it isn't what I need and breaks when you get to further coordinates (the current code barely has any relation to what I'm looking for rn, aka the function above)

Pseudocode, Java, Python, Lua, just text, explanations, anything would help

Coordinate Field; Left - Red, Right - Pink

0

There are 0 best solutions below