Re: Help with drawing
Re: Help with drawing
- Subject: Re: Help with drawing
- From: Graham Cox <email@hidden>
- Date: Sat, 16 May 2009 17:24:20 +1000
On 16/05/2009, at 5:01 PM, Development wrote:
theX = turretBottom.x + 103* sin(angle * PI/180);
Above is what I am using to get the X coord now I need it exactly
opposite the point it appears at. 103 is the height of the turret.
angle is the angle it is in relation to the platform it sits on.
(moves from 0 to 75 degrees)
Any one out there who knows more about math than me who might be
able to help me invert this X coord?
X co-ordinates require the cosine of the angle, not sine. so it should
be:
x = turretBottom.x + ( height * cos( angle ));
To draw it on the other side, it would then be:
x = turretBottom.x - ( height * cos( angle ));
where angle is in radians - if you are using degrees multiply the
angle by 0.0174532925199432958
Fairly obviously by subtracting the value from the turret location it
places it to the left of the turret instead of the right. Is this what
you mean? Your description is a bit vague. I'm visualising a turret
that moves horizontally across the screen with an elevating gun with
the barrel length <height>. Note that the y co-ordinate must also be
computed if you want the barrel length to remain constant and not
mysteriously lengthen and shorten:
y = turretBottom.y + ( height * sin( angle ));
Easy thing to remember when converting from polar to cartesian co-
ordinates, X -> cos, Y -> sin.
Also, don't hardcode values like <height> into your code. #define it
somewhere. You'll be grateful you did when you want to change it.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden