Mega Code Archive

 
Categories / Delphi / Examples
 

Calculating a point using angles and distance

Question: How do I calculate the x and y coordinates of a point that is at some distance and angle away? Answer: The following example shows how to convert a polar coordinate to a rectangular coordinate: procedure TForm1.Button1Click(Sender: TObject); var Angle : Double; x : Double; y : Double; Distance : Double; Radians : Double; begin Distance := 100; Angle := 270; Radians := Angle * DegToRad; x := Round(Distance * Cos(Radians)); y := Round(Distance * Sin(Radians)); ShowMessage(FloatToStr(x) + ' ' + FloatToStr(y)); end;