Prasad De Zoysa
Prasad De Zoysa

Reputation: 2567

Get x,y point from angle and radius

I need to get a specific point with specified angle and distance(Radius) from center point of my base UIView. I found this question How to calculate a point with an given center, angle and radius? but this doesn't give me correct point. I'm using below code to find the point,

Basically i need to find the x,y point from 100px distance and 90 degrees(clock wise) from center point of my base view.

int angle = 90 * M_PI / 180;//need to find the point of 90 degrees
int distance = 100;
int line_end_x = 160 + cos(angle)*distance;//160 is my center x
int line_end_y = 274 + sin(angle)*distance;//274 is my center y
myView.center = CGPointMake(line_end_x, line_end_y);

Above code gives me below output,

Red box is "myView" with (20px x 20px)

enter image description here

May be someone can tell me whats wrong i'm doing?

Upvotes: 1

Views: 520

Answers (1)

Olotiar
Olotiar

Reputation: 3274

I doubt that you want your angle to be expressed as an int. Your angle is Pi/2 which is 1.57.

Maybe try float angle = 90 * M_PI / 180;

Upvotes: 4

Related Questions