坐标网格中的现实球反弹(离线)

杰克

问题

因此,我正在尝试创建一个程序,通过计算球与该线所成的角度(如果它是相交的线)并围绕相交点旋转该线来创建从线反弹的球,新坡度。algorithms除了将坡度递回给球动量的那一部分之外,我拥有所有函数的所有公式和公式。所有计算的最终产品(我已经确定要进行工作)是直线和交点(或反弹点)的斜率。如果我只有一个斜坡,那么我如何分辨反弹后球在斜坡上的运动方向?

旁注:我正在使用的语言Java 1.8带有一些任意的外部语言graphics library,但是我不是在寻找要插入到我先前存在的代码中的代码,而是在寻找关于您认为我可以做到的一般性想法。同样,对该问题至关重要的是,整个项目都是基于坐标的。

非常感谢您的任何输入或可能的答案,并询问我是否需要有关此问题的说明!

查理·永利

https://cwynn.com/ball-bounce/是我几年前做的一点html5画布,它说明了op如何处理“反弹”

您有球B,它将在碰撞点C上撞到线L。B-> C线。在C以外的那条线上取一点,并在L上进行反射,以得到反射点R。当球击中C时,您可以删除它的方向向量,并将其向量设为C-> R。但是,您需要重置其速度。因此,获取方向矢量的大小,然后缩放新的方向矢量以使其匹配。

编辑:决定添加代码(这使我意识到我忘记了扩展速度)

    //closestCollPt[0] is the line the 'player' will hit next
    var dist = player.position.dist(closestCollPt[0]);

    //the 'player' in my case is a circle, so this indicates collision
    if(dist < player.radius*2)
    {
        //the collision point to the reflection like I mentioned
        //in the text above
        var newDir = closestCollPt[0].vecTo(reflection);

        //I break out their parts, b/c I want to scale the vector
        //doable in one line, but hard to debug
        var newDirX = newDir.x;
        var newDirY = newDir.y;
        var newDirDist = newDir.dist(new Vector(0,0));
        //for whatever reason I was calling the size of a vector
        //'dist' when I wrote this


        var currDirDist = player.direction.dist(new Vector(0,0));

        //give the player the direction we got from Coll->Ref
        //scale it so their speed doesn't change
        player.direction = newDir.scale(currDirDist).scale(1/newDirDist);
    }

决定添加图片...

唯一的“真实”东西是球和棕线

“球”是粉红色的,朝向光线“路径”中心的“接触”点,

投影是球在接触点上的反射,反射是投影点在线上的反射。

球接触到棕色线后,其方向向量应从“路径”更改为“新路径”(位于接触和反射线上)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章