English 中文(简体)
物体的轮换是不适当的——
原标题:object rotation is not proper - iPhone application

I am facing a typical problem in rotating an object. Description is as given below
I have taken two CGPoint let say point1 and point2
point1 = (50,50)
point2 = (150, 50)
this point will draw a horizontal line.

Now i am drawing a rectangle with that point on it. Width is 100 and height is 10. Angle is 0.
see screen shot
enter image description here

works fine
now i change the point let say
point1 = (50,50)
point2 = (50,150)
this point will draw a vertical line.

For rectangle Angle is 90.
With this point rectangle is not drawing properly
see screen shot
enter image description here

我的《精彩法》是:

    CGPoint mid = CGPointMake((point1.x+point2.x)/2, (point1.y+point2.y)/2)
    CGPoint UL = CGPointMake(mid.x + ( Width / 2 ) * cos (A) - ( Height / 2 ) * sin (A) ,  mid.y + ( Height / 2 ) * cos (A)  + ( Width / 2 ) * sin (A));
    CGContextMoveToPoint(context, UL.x,routeView.frame.size.height - UL.y);
    CGPoint UR = CGPointMake(mid.x - ( Width / 2 ) * cos (A) - ( Height / 2 ) * sin (A) ,  mid.y + ( Height / 2 ) * cos (A)  - ( Width / 2 ) * sin (A));
    CGContextAddLineToPoint(context, UR.x,routeView.frame.size.height - UR.y);
    CGPoint BR = CGPointMake(mid.x - ( Width / 2 ) * cos (A) + ( Height / 2 ) * sin (A) ,  mid.y - ( Height / 2 ) * cos (A)  - ( Width / 2 ) * sin (A));
    CGContextAddLineToPoint(context, BR.x,routeView.frame.size.height - BR.y);
    CGPoint BL = CGPointMake(mid.x + ( Width / 2 ) * cos (A) + ( Height / 2 ) * sin (A) ,  mid.y - ( Height / 2 ) * cos (A)  + ( Width / 2 ) * sin (A));
    CGContextAddLineToPoint(context, BL.x,routeView.frame.size.height - BL.y);
    CGContextAddLineToPoint(context, UL.x,routeView.frame.size.height - UL.y);

    CGContextStrokePath(context);

这里的A角不是静态的,中间点1和点2

https://stackoverflow.com/questions/644378/drawing-a-rotated-rectangle”

Am I missing something? Please help me if you have any idea.......

感谢

最佳回答

Let me guess, it s actually rotated about 26 degrees too far, right?

(90 x 180) / Pi ~= 5156.62 = (360 x 14) + 90 + 26.62

You rotated it 90 radians by mistake.

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签