有人可以帮我解决几何变换问题吗?

发布于 2024-12-04 23:35:06 字数 525 浏览 1 评论 0原文

我需要在两个给定点之间绘制圆弧。我还有圆弧的半径。我知道这可以使用标准 canvas API 来完成,但我也需要处理椭圆弧的情况。这段代码是一个通用的解决方案。现在唯一的问题是它不起作用!

此代码背后的数学概念位于 https://math。 stackexchange.com/questions/53093/how-to-find-the-the-center-of-an-ellipse

我的 JS 代码就是它的实现。我的 JS 代码可以在 http://jsfiddle.net/BkEnz/2/ 找到。理想情况下,两个圆圈都应该穿过两个粉红色的小点。

我希望有人能指出我正确的方向。过去几天我一直在努力解决这个问题!

I need to draw a circular arc between two given points. I also have the arc's radius. I understand that this can be done using standard canvas APIs but I need to handle the case of elliptical arcs too. This code is a generalized solution. The only problem right now is that it doesn't work!

The mathematical concept behind this code is at https://math.stackexchange.com/questions/53093/how-to-find-the-center-of-an-ellipse.

My JS code is implementation of that. My JS code can be found at http://jsfiddle.net/BkEnz/2/. Ideally both the circles there should pass through the two little pink dots.

I hope somebody can point me towards the right direction. I have been trying to solve this for past few days now!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛放△進行李 2024-12-11 23:35:06

修复了这个问题。更正后的工作代码位于 http://jsfiddle.net/ZxRBT

请注意,

var t = translate(-R1R2x, -R1R2y, IDENTITY_TRANSFORM());

在我之前版本的代码中,这一行是

var t = translate(-R1R2x, -R1R2y, sr);

因此,当我计算 C1C2 的值时,使用以下代码

C1 = compose(vut, [[R1x],[R1y],[1]]);
C2 = compose(vut, [[R2x],[R2y],[1]]);

我还应用了 sr 合成在 R1x,R1yR2x,R2y 上,但这些点已经在 sr 坐标中。

这是一个严重的错误,我很长一段时间都忽略了它。

Fixed this issue. The corrected working code is at http://jsfiddle.net/ZxRBT.

Notice the line

var t = translate(-R1R2x, -R1R2y, IDENTITY_TRANSFORM());

In my previous version of the code this line was

var t = translate(-R1R2x, -R1R2y, sr);

So when I was calculating the value of C1 and C2, using the following code

C1 = compose(vut, [[R1x],[R1y],[1]]);
C2 = compose(vut, [[R2x],[R2y],[1]]);

I was also applying the sr composition over R1x,R1y and R2x,R2y, but these points were already in sr coordinate.

This was a grave mistake which I overlooked for really a long time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文