gpt4 book ai didi

ios - 圆几何上的点

转载 作者:行者123 更新时间:2023-11-29 10:43:56 26 4
gpt4 key购买 nike

enter image description here

我想实现以下内容:

我在一个圆圈上有两个可触摸的对象。

如果我触摸并移动红色框中的对象,我希望左侧的对象沿着蓝色圆圈相应地移动——就好像它被一根透明的绳子拉到第一个对象后面一样。

最佳答案

这应该可以解决问题,按钮将位于 buttonFinger 的同一轴上。如果您想要一个不同的,请向 touchAngle 添加一个偏移量:

float    centerX; //Center of your Circle on X
float centerY; //Center of your Circle on Y
float touchAngle; //Angle of the touch
int touchHash;
XxX button; //Your "button" to be kept in the bluecircle
XxX buttonFinger; //Your "button" that follow your finger

int maxRadius; //The maximum radius: from center to the end of the blue circle
int minRadius; //The minimum radius: from center to the beginning of the blue circle
CGRect CGRectPantone; //The CGRect of your available touch zone

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
{
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(CGRectPantone, touchLocation))
{
touchHash = [touch hash];
buttonFinger.center = touchLocation;
}
}
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
{
if ([touch hash] == touchHash)
{
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(CGRectPantone, touchLocation))
{
buttonFinger.center = touchLocation;
float dx = centerX - (float)touchLocation.x;
float dy = centerY - (float)touchLocation.y;
touchAngle = -atan2f(dx, dy)+(M_PI/2.0);

button.center = CGPointMake(centerX-((minRadius+(maxRadius-minRadius)/2.0)*cosf(touchAngle)), centerY-((minRadius+(maxRadius-minRadius)/2.0)*sinf(touchAngle)));
}
}
}

关于ios - 圆几何上的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23126901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com