Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modifying mathematical function 1

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
US
I got some help here a while back to find this function. It's used for identifying an X/Y location (TPoint) around a circle of a center point based on the X/Y of Focus (TPoint), distance from Focus (Integer) and Degrees around Focus (Integer). I've simplified it as much as possible and it works and I'm using it everywhere, except for one little issues now - there's only 360 possible positions. When it's enlarged across the screen, I'm doing a smooth-moving second hand on a clock. It still jumps because there's only 6 possible points between each second tick mark on the clock (1 second = approx. 6 degree range).

How can I modify this function to take a Single instead of an Integer? I'm horrible with math and didn't make this function. I'd like instead of 6 possible points in 1 second to be more like 600 (depending on the user's screen resolution of course).

Code:
function NewPosition(Center: TPoint; Distance: Integer; Degrees: Integer): TPoint;
var
  Radians: Real;
begin
  //Convert angle from degrees to radians; Subtract 135 to bring position to 0 Degrees
  Radians:= ((Degrees - 135) * Pi / 180.0);
  Result.X:= Trunc(Distance*Cos(Radians)-Distance*Sin(Radians))+Center.X;
  Result.Y:= Trunc(Distance*Sin(Radians)+Distance*Cos(Radians))+Center.Y;
end;

JD Solutions
 
Just change degrees to Single instead of integer and you should be fine.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
It was painless, just had to modify any place which was calculating the degrees to single instead of integer as well, now the second hand floats like a feather perfectly instead of jumping around. I'm afraid to change formulas which I don't know how they work - took me a week to figure out I had to subtract 135 to make 0 degrees at the top, rather than pointing to the bottom-right. All good now, thanks.

Code:
function NewPosition(Center: TPoint; Distance: Integer; Degrees: Single): TPoint;
var
  Radians: Real;
begin
  //Convert angle from degrees to radians; Subtract 135 to bring position to 0 Degrees
  Radians:= (Degrees - 135) * Pi / 180.0;
  Result.X:= Trunc(Distance*Cos(Radians)-Distance*Sin(Radians))+Center.X;
  Result.Y:= Trunc(Distance*Sin(Radians)+Distance*Cos(Radians))+Center.Y;
end;


JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top