给定X坐标,我如何计算一个点的Y坐标,使其位于贝塞尔曲线上 [英] Given an X co-ordinate, how do I calculate the Y co-ordinate for a point so that it rests on a Bezier Curve

查看:334
本文介绍了给定X坐标,我如何计算一个点的Y坐标,使其位于贝塞尔曲线上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个点(用粉红色圈出)具有已知的X坐标和已知的Y坐标,但是Y坐标不正确.当前,它位于目标贝塞尔曲线(该曲线部分为白色正方形)将位于其两点之间的直线的点上.我需要为圈出的点计算正确的Y坐标,以使其最终出现在红叉上.

我是C#程序员,而不是数学家,因此,如果此答案可以用代码表达或对方程中涉及的每个参数进行解释,则这对我而言最有意义.如果我能得到想要的答案,我甚至可能最终为此目的用Python脚本扩展Blender.

更新:我已经修改了问题及其图像,以更好地表达我遇到的问题.我只是想要找出红十字上的Y坐标是什么的方法.考虑了这可能是三角函数,与贝塞尔曲线无关,但我将需要一种方法来找出放置在该曲线上任意点的标记的Y坐标,而不仅仅是在第一个坐标上段/线.

解决方案

正确的数学答案:如果需要精确的答案,则需要数学,最后;贝塞尔曲线是参数曲线,并且对于单个x值可以具有多个y值(反之亦然),因此您在没有真正了解自己的工作的情况下就不会找到它们.

不精确地执行此操作的更简单方法是编程,只需为每个对象简单地构建坐标 L ook U p T 曲线(例如{t=0 -> {x:...,y:...}, t=0.01 -> {x:...y:...}, ...}),然后简单地在LUT中搜索给定的xy值,以找到(可能是多个)相应的yx值.如果您需要某些xy值,请对x的LUT进行排序,然后进行二进制搜索以找到最佳匹配项.如果某些y需要x,则对y进行排序并执行相同的操作.

好又简单.

但是,如果您想真正地关心程序员的问题 precise 解决方案,那么您想要的就是沿着直线"重新定位曲线,您将尝试为其寻找值. (例如,某些x的所有y值"表示您正在查找曲线和直线(x=a, y=-inf)--(x=a,y=inf)之间的所有交点),然后只需检查进行交点检测时得到的t值即可.

如果您想在此处找到真正的真实答案,请参阅曲线和直线之间的交点检测(依次依赖于有关寻根).如果要处理三次曲线,则需要了解如何对齐曲线将找到交集简化为求根,然后需要运行Cardano算法来找到您感兴趣的(可能是三个)值.

I have a point (circled in pink) which has a known X co-ordinate and a known Y co-ordinate but the Y co-ordinate is incorrect. It is currently resting upon the point where the target bezier curve (the curve partially in a white square) would be if it were a line between its two points. I need to calculate the correct Y co-ordinate for my circled point so that it ends up on the red cross.

I am a C# programmer and not a mathematician so if this answer could be expressed in code or with an explanation of each parameter involved in the equation then this would be of most meaning to me. I may even end up extending Blender with a Python script for this purpose if I can get the answer I'm after.

UPDATE: I have amended the question and its image to better express the problem I'm having. I simply want a means of finding out what the Y co-ordinate is on the red cross. Having thought about this it may be trigonometry and have nothing to do with bezier curves but I will need to have a means of figuring out the Y co-ordinate for a marker placed at any point on that curve, not just on the first segment/line of it.

解决方案

True maths answer: if you want precise answers, you need maths, the end; Bezier curves are parametric curves and can have multiple y values for a single x value (and vice versa) so you're not going to find those without actually understanding what you're doing.

The easier way to do this, imprecisely, as a programming exercise is to simply build coordinate LookUp Tables for each curve (e.g. {t=0 -> {x:...,y:...}, t=0.01 -> {x:...y:...}, ...}), and then simply search your LUT for a given x or y value in order to find (possibly multiple) corresponding y or x values. If you need y values for some x, you sort your LUT on x, and then do a binary search to find best matches. If you need x for some y, you sort on y and do the same.

Nice and simple.

But, if you want precise solutions, which as a programmer you really should care about, then what you want is to reorient the curve along the "line" you're trying to find values for (for instance, "all y values for some x" means you're looking for all intersections between the curve and the line (x=a, y=-inf)--(x=a,y=inf)) and then you simply check which t values you get when you do intersection detection.

If you want the actual true answers here, have a look at this Primer on Bezier Curves' section on intersection detection between curves and lines (which in turn relies on the section about root finding). If you're dealing with cubic curves, you'll need to understand how to align curves so that finding intersections is reduced to root finding, after which you need to run Cardano's algorithm to find the (possibly three) values you're interested in.

这篇关于给定X坐标,我如何计算一个点的Y坐标,使其位于贝塞尔曲线上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆