Difference between revisions of "ToPolarOffset"

From SCAR Divi Manual
Jump to: navigation, search
(Created page with "==Definition== <source lang="scar" lines="false"> function ToPolarOffset(const Point, Offset: TPoint): PPoint; </source> ===Source Code=== <source lang="scar"> function ToPolarO...")
 
(Source Code)
 
Line 7: Line 7:
 
<source lang="scar">
 
<source lang="scar">
 
function ToPolarOffset(const Point, Offset: TPoint): PPoint;
 
function ToPolarOffset(const Point, Offset: TPoint): PPoint;
 +
var
 +
  p: TPoint;
 
begin
 
begin
   Point.X := Point.X - Offset.X;
+
   p.X := Point.X - Offset.X;
   Point.Y := Point.Y - Offset.Y;
+
   p.Y := Point.Y - Offset.Y;
   Result.R := Sqrt(Sqr(Point.X) + Sqr(Point.Y));
+
   Result.R := Sqrt(Sqr(p.X) + Sqr(p.Y));
   Result.T := ArcTan2(Point.Y, Point.X);
+
   Result.T := ArcTan2(p.Y, p.X);
 
   Result.T := RadToDeg(Result.T);
 
   Result.T := RadToDeg(Result.T);
 
end;
 
end;

Latest revision as of 22:59, 3 July 2011

Definition

function ToPolarOffset(const Point, Offset: TPoint): PPoint;

Source Code

function ToPolarOffset(const Point, Offset: TPoint): PPoint;
var
  p: TPoint;
begin
  p.X := Point.X - Offset.X;
  p.Y := Point.Y - Offset.Y;
  Result.R := Sqrt(Sqr(p.X) + Sqr(p.Y));
  Result.T := ArcTan2(p.Y, p.X);
  Result.T := RadToDeg(Result.T);
end;

Availability

SCAR Divi 3.00 > Current

Description

Converts a given cartesian coordinate defined by the TPoint Point with an offset given by Offset to a polar coordinate defined by a PPoint.

Example

var
  p: PPoint;

begin
  p := ToPolarOffset(Point(3, 4), Point(2, 2));
  WriteLn('PPoint(' + FloatToStr(p.R) + ';' + FloatToStr(p.T) + ')');
end.

Output:

PPoint(2,23606797749979;63,434948822922)

See Also