You are not logged in.
Pages: 1
This function returns percentage position of path, nearest to given point (may be mouse_x/mouse_y for example).
Precision is between how many pixels it should check (for image below and precision = 1 it will be 1800 checks for example, as it checks each 1 pixel, and 180 checks if precision = 10).
This could be probably done by binary search, but since path lines may overlay on each other, I found no solution to make it good (it would work then only on convex paths probably).
// @param path
// @param x
// @param y
// @param pixel_precision
var dst = 9999;
var pos = 0;
var _precision = 1/path_get_length(argument0) * clamp(argument3, 1, 100);
for(var i = 0; i < 1; i += _precision;) {
var _dst = point_distance(
argument1, argument2,
path_get_x(0, i),
path_get_y(0, i)
);
if _dst < dst {
pos = i;
dst = _dst;
}
}
return pos;
you can use later pos value with functions path_get_x/path_get_y to get x/y coordinates on path of closests points.
Offline
Pages: 1