给定 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

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

问题描述

我有一个点(粉红色圆圈),它有一个已知的 X 坐标和一个已知的 Y 坐标,但是 Y> 坐标不正确.它当前停留在目标贝塞尔曲线(部分为白色方块的曲线)所在的点上,如果它是两点之间的一条线.我需要为我的圆圈点计算正确的 Y 坐标,以便它最终出现在红十字上.

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.

我是一名 C# 程序员,而不是数学家,所以如果这个答案可以用代码表达或对方程中涉及的每个参数进行解释,那么这对我来说最有意义.如果我能得到我想要的答案,我什至可能会为此使用 Python 脚本扩展 Blender.

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.

更新:我修改了问题及其图片,以更好地表达我遇到的问题.我只是想要一种方法来找出 Y 坐标在红十字上的位置.考虑到这一点,它可能是三角学,与贝塞尔曲线无关,但我需要一种方法来计算放置在该曲线上任何点的标记的 Y 坐标,不只是在它的第一段/第一行.

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.

推荐答案

真正的数学答案:如果你想要精确的答案,你需要数学,结束;Bezier 曲线是参数曲线,对于一个 x 值可以有多个 y 值(反之亦然),所以你不会在没有真正理解你的情况下找到它们正在做.

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.

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

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.

又好又简单.

但是,如果您想要精确解决方案,作为程序员,您真的应该关心这一点,那么您想要的是沿着您试图为其找到值的线"重新定向曲线(例如,某些 x 的所有 y 值"意味着您正在寻找曲线和线之间的所有交点 (x=a, y=-inf)--(x=a,y=inf)) 然后您只需检查在进行交叉检测时获得哪些 t 值.

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.

如果您想在这里得到真正的答案,请查看 上的 Bezier Curves 部分的入门曲线和直线之间的交点检测(这反过来又依赖于关于寻根).如果您正在处理三次曲线,则需要了解如何对齐曲线求交点简化为求根,之后您需要运行卡尔达诺的算法来找到您感兴趣的(可能是三个)值.

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天全站免登陆