GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2013-08-21 17:50:10

brac37
Member
Registered: 2010-02-12
Posts: 18

line_xtoy and line_ytox

Some easy scripts. But they might be useful. smile

Expand/*
**  Usage:
**      y3 = line_xtoy  (x1,y1, x2,y2, x3)
**
**  Arguments:
**      x1,y1, x2,y2:       coordinates of two points of the line
**      x3:                 x coordinate of third point of the line
**      
**  Returns:
**      y coordinate of third point of the line
**
**
**  brac37
*/
{
    return ((argument4-argument0)*argument3 + 
            (argument2-argument4)*argument1) /
           (argument2-argument0);
}
Expand/*
**  Usage:
**      x3 = line_xtoy  (x1,y1, x2,y2, y3)
**
**  Arguments:
**      x1,y1, x2,y2:       coordinates of two points of the line
**      y3:                 y coordinate of third point of the line
**      
**  Returns:
**      x coordinate of third point of the line
**
**
**  brac37
*/
{
    return ((argument4-argument1)*argument2 + 
            (argument3-argument4)*argument0) /
           (argument3-argument1);
}

Offline

#2 2013-08-22 17:34:51

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: line_xtoy and line_ytox

Yeah, easy, but a good way to express the operation in a way that people might use. Divide-by-zero is something they will have to watch out for. I can never decide if it is better to return an error value that might be misinterpreted or just allow the error to happen.

I usually do this with x3 = lerp(x1, x2, boxstep(y1, y2, y3)).


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB