Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Today we know that ratio to be PI, or **Math.PI** in JAVA, but HOW?
![Inscribed Polygons](images/geometry003.png)
* With this observation, and a little more geometry, we can create an algorithm to calculate the perimeter of larger and larger **inscribed** polygons.
* Remember, the more sides, (n represents the number of sides in the polygon), the more accurate our perimeter estimation is, so let's do the math...
![General Equation](./images/geometry001.jpg)

![General Equation](images/geometry001.jpg)
* From the image above, you can see the **octagon** is divided into **isosceles triangles**, the bottom of which (labeled **s**) is the length we need to know.
* If we draw a line from the circle center perpendicular to the base of the triangle **s**, we divide **s** in half, so it becomes ${1 \over 2}s$ as depicted.
* From the picture, we can simplify our lives by assuming $h = 1$, and that the circle is a **Unit circle**.
Expand All @@ -21,7 +22,10 @@ Today we know that ratio to be PI, or **Math.PI** in JAVA, but HOW?
* WELL, we can calculate B, so let's start there. Remember, a Circle is **360°** and we are equally dividing that by **n** sides ($n = 8$ in the example).
* So... $B = {360° \over 8}$ or $45°$ and $A = {1 \over 2} * B$ so $A = 22.5°$ in our example.
* Now we can calculate ${1 \over 2}s$ if we recall $sin(A) = {{1 \over 2}s \over h}$ as shown in the below diagram of the triangle.
![Geometry Reminder](images/geometry002.jpg)

![Geometry Reminder](images/geometry002.jpg)

* ...continued...
* Solving for *s* we see $s = 2 * h * sin(A)$
* And since we agreed $h = 1$, that simplifies to $s = 2 * sin(A)$
* Now we have *s*, so to get the **polygon perimeter**, we just multiply by the number of sides to get it.
Expand Down
19 changes: 17 additions & 2 deletions src/ArchimedesPiMethod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import java.util.Scanner;

/* Chris Shortt's homework Java Assignment-002 */
public class ArchimedesPiMethod {
public static void main(String[] args) {
while (true) {
System.out.println("please type the number of sides");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n < 1){
break;
}
double b = 360.0 / n;
double a = b / 2;
double s = 2 * Math.sin(Math.toRadians(a));
double p = n * s;
double pi = p / 2;
System.out.printf("Our PI estimate is: %.10f %n", pi);
System.out.println(pi);

}
}
}
}