(*----------------------------------------------------------* * Unele transformari asupra coordonatelor punctelor, * * sau poligoanelor, sau multimilor de puncte. * *----------------------------------------------------------*) {$N+} unit Transf; interface (*----------------------------------------------------------------*) uses Types; (*----------------------------------------------------------------*) (* Lab 1, Var 1 *) (*----------------------------------------------------------------*) procedure calc_coef_rot(alfa: TCoord; var c, s: TCoord); procedure rot_punct(var r: TPunct; p: TPunct; var c, s: TCoord); procedure rot_set_puncte(var r, p: TabelPuncte; nr: integer; alfa: TCoord); (*----------------------------------------------------------------*) (* Lab 1, Var 2 *) (*----------------------------------------------------------------*) procedure depl_punct(var r, p: TPunct; a, b: TCoord); procedure depl_set_puncte(var r, p: TabelPuncte; nr: integer; a, b: TCoord); (*----------------------------------------------------------------*) (* Lab 1, Var 3 *) (*----------------------------------------------------------------*) procedure depl_rot_set_puncte(var r, p: TabelPuncte; nr: integer; a, b, alfa: TCoord); (*----------------------------------------------------------------*) (* Lab 1, Var 4 *) (*----------------------------------------------------------------*) procedure polar_punct(var pol: TPunct; cart: TPunct); procedure cartez_punct(var cart: TPunct; pol: TPunct); procedure polar_set_puncte(var r, p: TabelPuncte; nr: integer); procedure cartez_set_puncte(var r, p: TabelPuncte; nr: integer); (*----------------------------------------------------------------*) (*----------------------------------------------------------------*) implementation (*----------------------------------------------------------------*) uses IOGeom, Punct; (*----------------------------------------------------------------*) (* Lab 1, Var 1 *) (*----------------------------------------------------------------*) procedure calc_coef_rot(alfa: TCoord; var c, s: TCoord); begin alfa := rad(alfa); c := cos(alfa); s := sin(alfa); end; procedure rot_punct(var r: TPunct; p: TPunct; var c, s: TCoord); begin r.x := c * p.x - s * p.y; r.y := s * p.x + c * p.y; end; procedure rot_set_puncte(var r, p: TabelPuncte; nr: integer; alfa: TCoord); var c, s: TCoord; i: integer; begin calc_coef_rot(alfa, c, s); for i :=nr-1 downto 0 do rot_punct(r[i], p[i], c, s); end; (*----------------------------------------------------------------*) (* Lab 1, Var 2 *) (*----------------------------------------------------------------*) procedure depl_punct(var r, p: TPunct; a, b: TCoord); begin r.x := p.x + a; r.y := p.y + b; end; procedure depl_set_puncte(var r, p: TabelPuncte; nr: integer; a, b: TCoord); var i: integer; begin for i := nr-1 downto 0 do with p[i] do begin r[i].x := x + a; r[i].y := y + b; end; end; (*----------------------------------------------------------------*) (* Lab 1, Var 3 *) (*----------------------------------------------------------------*) procedure depl_rot_set_puncte(var r, p: TabelPuncte; nr: integer; a, b, alfa: TCoord); begin depl_set_puncte(r, p, nr, a, b); rot_set_puncte (r, p, nr, alfa); end; (*----------------------------------------------------------------*) (* Lab 1, Var 4 *) (*----------------------------------------------------------------*) procedure polar_punct(var pol: TPunct; cart: TPunct); begin (* pol.x - ro, pol.y - fi *) pol.x := sqrt(sqr(cart.x)+sqr(cart.y)); pol.y := ArcTan2(cart.y, cart.x); {Cazurile speciale sunt analizate in ArcTan2} { if(cart.x <> 0)then pol.y := ArcTan2(cart.y, cart.x) else (* cart.x = 0 *) begin if(cart.y > 0) then pol.y := M_PI / 2 else if(cart.y < 0) then pol.y := -M_PI / 2 else pol.y := 0; end; } end; procedure cartez_punct(var cart: TPunct; pol: TPunct); begin (* pol.x - ro, pol.y - fi *) cart.x := pol.x * cos(pol.y); cart.y := pol.x * sin(pol.y); end; procedure polar_set_puncte(var r, p: TabelPuncte; nr: integer); var i: integer; begin for i := nr-1 downto 0 do polar_punct(r[i], p[i]) end; procedure cartez_set_puncte(var r, p: TabelPuncte; nr: integer); var i: integer; begin for i := nr-1 downto 0 do cartez_punct(r[i], p[i]) end; (*----------------------------------------------------------------*) end.