简体   繁体   中英

get Y coordinate of Path depending on the x coordinate

How can I get the Y coordinate of path depends of the X coordinate? For example let's say we have one line (path) from the starting point [100,50] to the ending point [200,50]. I want to know the value of Y coordinate when X coordinate is equals to 150. (This is just simple example my path can be much curved). Thanks for any help.

I can get the both coordinates of path like this:

    //Count coordinates of path of lineChart
    PathMeasure pm = new PathMeasure(myPath, false);

    //coordinates will be here
    float aCoordinates[] = {0f, 0f};

    pm.getPosTan(pm.getLength() * 0.5, aCoordinates, null);

For example this will return coordinates to the middle point of path. Im looking for something like "getYCoordinate(myPath, xCoordinate)".

Mathematics. Interesting.

You can get the value of y from x only if you can define a relationship with them.

For example, the linear equation function could be given as

y = mx + c

or

f(x) = mx + c

Which means to say that in the above examples, there is an explicit relationship between x and y. "The value of y depends on the change in value of x". Without a relationship of this kind defined, it is impossible to get the value of y due to a change in the value of x.

I think the PathInterpolator Class is what you are looking for.

Unfortunately the PathInterpolator is only supported since API level 21 so it may not be a valid solution for all apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM