Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to calculate the center of a rectangle in Pascal

2 Answers

0 votes
program RectangleCenter;
 
type
  Point = record
    x, y: Real;
  end;
 
  Rectangle = record
    topLeft: Point;
    bottomRight: Point;
  end;
 
// Function to calculate the center point of a rectangle
function GetCenter(rect: Rectangle): Point;
begin
  GetCenter.x := (rect.topLeft.x + rect.bottomRight.x) / 2.0;
  GetCenter.y := (rect.topLeft.y + rect.bottomRight.y) / 2.0;
end;
 
var
  rect: Rectangle;
  center: Point;
begin
  // Initialize the rectangle with top-left and bottom-right corners
  rect.topLeft.x := 10.0;
  rect.topLeft.y := 20.0;
  rect.bottomRight.x := 110.0;
  rect.bottomRight.y := 70.0;
 
  // Compute the center
  center := GetCenter(rect);
 
  WriteLn('Center of the rectangle: (', center.x:0:2, ', ', center.y:0:2, ')');
end.
 
 
 
 
(*
run:
 
Center of the rectangle: (60.00, 45.00)
 
*)

 



answered Jun 22, 2025 by avibootz
edited Jun 22, 2025 by avibootz
0 votes
program RectangleCenter;

uses
  Types;

var
  Rectt: TRect;
  Center: TPoint;

begin
  // Define the rectangle using its corners (x1, y1, x2, y2)
  Rectt := Rect(10, 20, 110, 70); 

  // Calculate the center point of the rectangle
  Center := CenterPoint(Rectt);

  WriteLn('Center of the rectangle: (', Center.X, ', ', Center.Y, ')');
end.



(*
run:

Center of the rectangle: (60, 45)

*)

 



answered Jun 22, 2025 by avibootz
edited Jun 22, 2025 by avibootz

Related questions

1 answer 109 views
1 answer 77 views
1 answer 53 views
1 answer 72 views
2 answers 92 views
...