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 check if a point is inside a rectangle in Pascal

2 Answers

0 votes
program PointInRectangle;

type
  Point = record
    x, y: Real;
  end;

  Rectangle = record
    topLeft: Point;
    bottomRight: Point;
  end;

function IsPointInsideRectangle(p: Point; rect: Rectangle): Boolean;
begin
  IsPointInsideRectangle := (p.x >= rect.topLeft.x) and (p.x <= rect.bottomRight.x) and
                            (p.y >= rect.topLeft.y) and (p.y <= rect.bottomRight.y);
end;

var
  rect: Rectangle;
  p: Point;
begin
  rect.topLeft.x := 0.0;
  rect.topLeft.y := 0.0;
  rect.bottomRight.x := 7.0;
  rect.bottomRight.y := 7.0;

  p.x := 3.0;
  p.y := 2.0;

  if IsPointInsideRectangle(p, rect) then
    WriteLn('The point is inside the rectangle.')
  else
    WriteLn('The point is outside the rectangle.');
end.



(*
run:

The point is inside the rectangle.

*)

 



answered Jun 22, 2025 by avibootz
0 votes
program PointInRectangle;

uses
  Types;

var
  Rectt: TRect;
  Pointt: TPoint;
  IsInside: Boolean;
  x1, y1, x2, y2, x, y: Integer;

begin
  // Define the rectangle using its top-left (x1, y1) and bottom-right (x2, y2) coordinates
  x1 := 10; y1 := 10; // Top-left corner
  x2 := 60; y2 := 60; // Bottom-right corner
  Rectt := Rect(x1, y1, x2, y2);

  // Define the point to check
  x := 30; y := 20; // Coordinates of the point
  Pointt := Point(x, y);

  if PtInRect(Rectt, Pointt) then
    WriteLn('The point is inside the rectangle.')
  else
    WriteLn('The point is outside the rectangle.');
end.



(*
run:

The point is inside the rectangle.

*)

 



answered Jun 22, 2025 by avibootz
...