简体   繁体   English

根据x坐标获取Path的Y坐标

[英]get Y coordinate of Path depending on the x coordinate

How can I get the Y coordinate of path depends of the X coordinate? 如何获得路径的Y坐标取决于X坐标? For example let's say we have one line (path) from the starting point [100,50] to the ending point [200,50]. 例如,假设从起点[100,50]到终点[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). 我想知道X坐标等于150时Y坐标的值。(这只是简单的示例,我的路径可能弯曲很多)。 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)". 我正在寻找类似“ getYCoordinate(myPath,xCoordinate)”的东西。

Mathematics. 数学。 Interesting. 有趣。

You can get the value of y from x only if you can define a relationship with them. 仅当您可以定义与x的关系时,才可以从x获得y的值。

For example, the linear equation function could be given as 例如,线性方程函数可以表示为

y = mx + c y = mx + c

or 要么

f(x) = mx + c f(x)= mx + c

Which means to say that in the above examples, there is an explicit relationship between x and y. 这意味着在上述示例中,x和y之间存在显式关系。 "The value of y depends on the change in value of x". “ y的值取决于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. 如果没有定义这种关系,由于x值的变化,不可能获得y的值。

I think the PathInterpolator Class is what you are looking for. 我认为PathInterpolator类是您想要的。

Unfortunately the PathInterpolator is only supported since API level 21 so it may not be a valid solution for all apps. 不幸的是,仅从API级别21开始才支持PathInterpolator因此它可能不是所有应用程序的有效解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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