The Geometer

There’s a course about computational geometry which I scripted from the source in maXbox. The origin you can find at:

http://www.delphiforfun.org/programs/Library/geometry1.htm

The script with the 9 Tasks in one file you can find at:

http://www.softwareschule.ch/examples/geometry.txt

Three new routines were added to the UGeometry unit today and Version 3 of the Geometry test program illustrates their use. The routines, PolygonArea, InflatePolygon, and PolygonClockwise help to “inflate” (or deflate) a given polygon by given amount. The value is the distance which the edges are to be moved while retaining their slope.

But we start from the beginning. 1. Intersect takes two line definitions as input and returns true if the two line intersect. An additional parameter, PointOnBorder, is set to true if the lines touch but do not cross, . This is a faster, but harder-to-understand version of the IntersectingLines routine presented earlier.

2. PointPerpendicularLine

Given a line and a point not on the line, construct a line through the point and perpendicular to the line. The trick here is to determine the slope of the given line, m, and take advantage of the fact that the slope of a perpendicular line is -1/m. Given the equations of the two lines we can solve them as decribed in Intersecting Lines to determine the point of intersection.

3. AngledLineFromLine

Given a line, a point on (or near) the line, an angle, and a length, construct a line through the point with the specified length and at the specified angle from the given line. The simplest approach to this problem is to draw a line segment of a given length, L, at a given angle, A, through a given point, P. The new point is defined by P2.X=P1.X+Lcos(A) and P2.Y=P1.Y+Lsin(A). The only problem remaining is to determine angle A. The required angle equals the angle of the given line from the horizon plus the given angle, and the angle of the given line from the horizon is given by the inverse tangent of its slope. Here’s the bit of Delphi code that does that for line L1 with endpoints p1 and p2:

4. Point In Polygon

Given an arbitrary polygon and a point, determine if the point is inside or outside of the polygon. (The red point in the image at left is outside of the polygon.)

The algorithm extends a line from the point to “infinity: and counts how many times it intersects the polygon. If odd, the point is internal; if even, the point is external to the polygon. There are a few messy details here in detecting cases where the point is on an edge or vertex of the polygon or when the extension line passes through a vertex.

5. InflatePolygon, and PolygonClockwise help to “inflate” (or deflate) a given polygon by given amount. The value is the distance which the edges are to be moved while retaining their slope. In order to decide which direction to move each edge, we need to know whether the polygon was built in a clockwise or counterclockwise direction.

6. Translate / Rotate: These routines to translate and rotates lines are required for the Circle-Circle intersection operations.

7. CircleCircleIntersect function to return the intersection points of 2 passed circles and CircleCircleExtTangentLines function calculates the 2 exterior tangent lines, if they exist, between 2 given circles.

8. PointCircleTangentLines function calculates the two tangent lines to a given circle from a given exterior point.

9. CircleCircleExtTangentLines function calculates the 2 exterior tangent lines, if they exist, between 2 given circles.

Click the button below to draw 2 random circles for which the the 2 exterior lines tangent to both circles will be calculated.
The algorithm is:

Originally published at http://softwareschule.code.blog on December 15, 2020.

BitBang Exposition

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Max Kleiner

Max Kleiner's professional environment is in the areas of OOP, UML and coding - among other things as a trainer, developer and consultant.