### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: For those who love geometry  (Read 1501 times)

#### julkas

• Guest
##### For those who love geometry
« on: January 12, 2020, 03:06:56 pm »

#### Bart

• Hero Member
• Posts: 4222
##### Re: For those who love geometry
« Reply #1 on: January 12, 2020, 04:43:07 pm »
I think I can only figure out the answer for p being infinite (and q <> p div 2)

Bart

#### VTwin

• Hero Member
• Posts: 973
• Former Turbo Pascal 3 user
##### Re: For those who love geometry
« Reply #2 on: January 12, 2020, 09:17:55 pm »
I think I can only figure out the answer for p being infinite (and q <> p div 2)

Bart

“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

#### VTwin

• Hero Member
• Posts: 973
• Former Turbo Pascal 3 user
##### Re: For those who love geometry
« Reply #3 on: January 13, 2020, 02:22:52 am »
Some progress, the algorithm is:

1. Calculate the polygram, a self-intersecting polygon, complicated by the fact that some require two polygons.
2. Determine the intersection points that are a maximum distance dmax from the center, but less than the radius.
3. Calculate a simple polygram which is is not self-intersecting. Vertices alternate between radius and dmax.
4. Calculate the simple polygram area using a trapazoid sum algorithm.

Steps 1, 2, and 4 are complete. 3 is in progress.

VTwin
« Last Edit: January 13, 2020, 03:55:30 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

#### VTwin

• Hero Member
• Posts: 973
• Former Turbo Pascal 3 user
##### Re: For those who love geometry
« Reply #4 on: January 13, 2020, 09:03:23 pm »
3 was actually the easiest part. I can now generate both the self-intersecting polygrams and the corresponding simple polygons, and can verify the test cases for area. I'm cleaning up the code, it is longer than I expected because of the special cases.

I am working on a github library of routines and will include this unit with a graphical example.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

#### VTwin

• Hero Member
• Posts: 973
• Former Turbo Pascal 3 user
##### Re: For those who love geometry
« Reply #5 on: January 13, 2020, 09:43:29 pm »
The simple (non self-intersecting) polygons, and the area calculation, appear to work in (nearly) all cases, but there are still some issues with generating the polygrams. Cases like 9,6 and 12,4 are generated by more than 2 triangles or squares, which I did not deal with yet. More to do when I have time...

It looks like the number of polygons required to generate a polygram is the largest coprime of the number of vertices (p) and the next vertex value (q).

EDIT: Some of the polygrams get pretty weird, 15,6 for example is composed of 3 pentagrams. I abandoned my functional approach, and made a class with linked nodes and segments, and a visited property to traverse the nodes. It now works for all cases.

BTW, p,1 approaches Bart's solution with increasing p
« Last Edit: January 14, 2020, 10:56:23 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)