Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何根据与其碰撞的路径旋转拍子_Android_Canvas_Path_Rotation_Uicollisionbehavior - Fatal编程技术网

Android 如何根据与其碰撞的路径旋转拍子

Android 如何根据与其碰撞的路径旋转拍子,android,canvas,path,rotation,uicollisionbehavior,Android,Canvas,Path,Rotation,Uicollisionbehavior,我想在我的绘图应用程序中应用物理,我使用自定义画布进行绘图,我想做的是:假设有两个rect,rect_a和rect_b,假设用户用手指移动rect_a(我通过对路径应用偏移来实现),一段时间后rect_a与rect_b发生碰撞(按区域检查碰撞),现在我想要的是,rect_b应该以与rect_a移动相同的偏移量移动(我成功地做到了这一点),这样rect_b和rect_a就不会相互重叠,并且rect_b也应该沿着相对于rect_a的方向旋转(我做了很多事情,但是失败了,,,如果路径是一个未旋转的矩形

我想在我的绘图应用程序中应用物理,我使用自定义画布进行绘图,我想做的是:假设有两个rect,rect_a和rect_b,假设用户用手指移动rect_a(我通过对路径应用偏移来实现),一段时间后rect_a与rect_b发生碰撞(按区域检查碰撞),现在我想要的是,rect_b应该以与rect_a移动相同的偏移量移动(我成功地做到了这一点),这样rect_b和rect_a就不会相互重叠,并且rect_b也应该沿着相对于rect_a的方向旋转(我做了很多事情,但是失败了,,,如果路径是一个未旋转的矩形,旋转只发生在right direct中,如果我旋转矩形路径,旋转将被写入),有人明白我的意思吗?我想要的是在现实生活中像推一样的东西,假设在我推的地方有两件东西,第一件和第二件碰撞时,第二件也会向前移动,在现实生活中也会旋转,这是我想要实现的,我尝试了每件事但都失败了, 我在做什么旋转,,请参阅此代码

//rectf is the path which is being moving by user through finger
PointF pointCMoving =  new PointF(rectF.centerX(),rectF.centerY());
//rectf1 is the second path to which path 1(rectf) collides.
PointF pointCMove =  new PointF(rectF1.centerX(),rectF1.centerY());
//getting the angle between rect1,and rect2 through their center points
double an = angleOf(pointCMoving,pointCMove);
boolean rotation = false;
Matrix matrix = new Matrix();
//dividing path in to 8 quadric  (360/45) 
//assuming 0-45 collide from left side, 45-90 collide from top left side and 
so on
//rotatepathvalue = 1 means matrix will rotate on right side and -1 means 
//matrix will rotate on left side


                    if(an >10 && an <= 45){
                        rotatePathValue = 1;
                        rotation = true;
                    }
                    if(an >55 && an <= 85){
                        rotatePathValue = -1;
                        rotation = true;
                    }
                    if(an > 100 && an <= 135){

                        rotatePathValue = 1;
                        rotation = true;
                    }
                    if(an >135 && an <= 175){
                        rotatePathValue = -1;
                        rotation = true;
                    }
                    if(an > 180 && an <= 220){
                        rotatePathValue = 1;
                        rotation = true;
                    }
                    if(an > 225 && an <= 270){
                        rotatePathValue = -1;
                        rotation = true;
                    }
                    if(an > 270 && an <= 315){
                        rotatePathValue = 1;
                        rotation = true;

                    }
                    if(an > 315 && an <= 355){
                        rotatePathValue = -1;
                        rotation = true;

                    }
                    if(rotation){
                        matrix.postRotate(rotatePathValue, rectF1.centerX(), rectF1.centerY());
                        movepath.transform(matrix);
                        matrix.mapRect(rectF1);
                    }
//rectf是用户通过手指移动的路径
PointF pointCMoving=新点F(rectF.centerX(),rectF.centerY());
//rectf1是路径1(rectf)碰撞到的第二条路径。
PointF pointCMove=新点F(rectF1.centerX(),rectF1.centerY());
//通过中心点获取rect1和rect2之间的角度
双an=角度(点移动,点移动);
布尔旋转=假;
矩阵=新矩阵();
//将路径划分为8个二次曲面(360/45)
//假设从左侧碰撞0-45,从左上方碰撞45-90,然后
等等
//rotatepathvalue=1表示矩阵将在右侧旋转,-1表示
//矩阵将在左侧旋转
如果(an>10&&an 55&&an 100&&an 135&&an 180&&an 225&&an 270&&an 315&&an