112 lines
5.1 KiB
Text
112 lines
5.1 KiB
Text
|
|
[
|
||
|
|
// Geometry formulas extracted from formulas.d4rt
|
||
|
|
// Area of Circle
|
||
|
|
{
|
||
|
|
"name": "Area of Circle",
|
||
|
|
"description": r'''\nArea enclosed by a circle\n\n$$A = \pi r^2$$\n\nWhere:\n- $A$: Area (square meters)\n- $r$: Radius (meters)\n- $\pi$: Pi ($\approx 3.14159$)\n\nThe area is proportional to the square of the radius.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "r", "unit": "meter"} // Radius
|
||
|
|
],
|
||
|
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||
|
|
"d4rtCode": "A = pi * pow(r, 2);",
|
||
|
|
"tags": ["geometry", "circle", "area"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Circumference of Circle
|
||
|
|
{
|
||
|
|
"name": "Circumference of Circle",
|
||
|
|
"description": r'''\nPerimeter (distance around) a circle\n\n$$C = 2\pi r$$\n\nWhere:\n- $C$: Circumference (meters)\n- $r$: Radius (meters)\n- $\pi$: Pi ($\approx 3.14159$)\n\nThe circumference is proportional to the radius.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "r", "unit": "meter"} // Radius
|
||
|
|
],
|
||
|
|
"output": {"name": "C", "unit": "meter"}, // Circumference
|
||
|
|
"d4rtCode": "C = 2 * pi * r;",
|
||
|
|
"tags": ["geometry", "circle", "perimeter"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Area of Triangle
|
||
|
|
{
|
||
|
|
"name": "Area of Triangle",
|
||
|
|
"description": r'''\nArea enclosed by a triangle\n\n$$A = \frac{1}{2}bh$$\n\nWhere:\n- $A$: Area (square meters)\n- $b$: Base length (meters)\n- $h$: Height perpendicular to base (meters)\n\nThis formula works for any triangle.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "b", "unit": "meter"}, // Base
|
||
|
|
{"name": "h", "unit": "meter"} // Height
|
||
|
|
],
|
||
|
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||
|
|
"d4rtCode": "A = 0.5 * b * h;",
|
||
|
|
"tags": ["geometry", "triangle", "area"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Area of Rectangle
|
||
|
|
{
|
||
|
|
"name": "Area of Rectangle",
|
||
|
|
"description": r'''\nArea enclosed by a rectangle\n\n$$A = lw$$\n\nWhere:\n- $A$: Area (square meters)\n- $l$: Length (meters)\n- $w$: Width (meters)\n\nThe area is the product of length and width.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "l", "unit": "meter"}, // Length
|
||
|
|
{"name": "w", "unit": "meter"} // Width
|
||
|
|
],
|
||
|
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||
|
|
"d4rtCode": "A = l * w;",
|
||
|
|
"tags": ["geometry", "rectangle", "area"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Area of Trapezoid
|
||
|
|
{
|
||
|
|
"name": "Area of Trapezoid",
|
||
|
|
"description": r'''\nArea enclosed by a trapezoid\n\n$$A = \frac{1}{2}(a+b)h$$\n\nWhere:\n- $A$: Area (square meters)\n- $a, b$: Lengths of parallel sides (meters)\n- $h$: Height (perpendicular distance between parallel sides, meters)\n\nThe area is the average of parallel sides times height.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "a", "unit": "meter"}, // Parallel side 1
|
||
|
|
{"name": "b", "unit": "meter"}, // Parallel side 2
|
||
|
|
{"name": "h", "unit": "meter"} // Height
|
||
|
|
],
|
||
|
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||
|
|
"d4rtCode": "A = 0.5 * (a + b) * h;",
|
||
|
|
"tags": ["geometry", "trapezoid", "area"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Area of Regular Polygon
|
||
|
|
{
|
||
|
|
"name": "Area of Regular Polygon",
|
||
|
|
"description": r'''\nArea of a regular polygon with n sides\n\n$$A = \frac{1}{4}ns^2\cot(\frac{\pi}{n})$$\n\nWhere:\n- $A$: Area (square meters)\n- $n$: Number of sides\n- $s$: Side length (meters)\n- $\pi$: Pi ($\approx 3.14159$)\n\nThis formula works for any regular polygon (equal sides and angles).''',
|
||
|
|
"input": [
|
||
|
|
{"name": "n", "unit": "scalar"}, // Number of sides
|
||
|
|
{"name": "s", "unit": "meter"} // Side length
|
||
|
|
],
|
||
|
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||
|
|
"d4rtCode": "A = 0.25 * n * pow(s, 2) * (cos(pi/n) / sin(pi/n));",
|
||
|
|
"tags": ["geometry", "polygon", "area"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Sum of Interior Angles of Polygon
|
||
|
|
{
|
||
|
|
"name": "Sum of Interior Angles",
|
||
|
|
"description": r'''\nSum of interior angles of a polygon\n\n$$S = (n - 2) \times 180°$$\n\nWhere:\n- $S$: Sum of interior angles (degrees)\n- $n$: Number of sides\n\nThis formula works for any simple polygon.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "n", "unit": "scalar"} // Number of sides
|
||
|
|
],
|
||
|
|
"output": {"name": "S", "unit": "degree"}, // Sum of angles
|
||
|
|
"d4rtCode": "S = (n - 2) * 180;",
|
||
|
|
"tags": ["geometry", "polygon", "angles"]
|
||
|
|
},
|
||
|
|
|
||
|
|
// Heron's Formula (Area of Triangle)
|
||
|
|
{
|
||
|
|
"name": "Heron's Formula",
|
||
|
|
"description": r'''\nArea of a triangle using only side lengths\n\n$$A = \sqrt{s(s-a)(s-b)(s-c)}$$\n\nWhere:\n- $A$: Area (square meters)\n- $a, b, c$: Side lengths (meters)\n- $s$: Semi-perimeter $= \frac{a+b+c}{2}$\n\nThis formula is useful when height is unknown.\n\n**Note:** The side lengths must satisfy the triangle inequality: the sum of any two sides must be greater than the third side (a+b>c, a+c>b, b+c>a). If this condition is not met, the formula returns NaN.''',
|
||
|
|
"input": [
|
||
|
|
{"name": "a", "unit": "meter"}, // Side 1
|
||
|
|
{"name": "b", "unit": "meter"}, // Side 2
|
||
|
|
{"name": "c", "unit": "meter"} // Side 3
|
||
|
|
],
|
||
|
|
"output": {"name": "A", "unit": "square meter"}, // Area
|
||
|
|
"d4rtCode": """
|
||
|
|
if( a + b < c || a+c < b || b+c < a ){
|
||
|
|
signal( "There is not a valid triangle with those longitudes" );
|
||
|
|
}
|
||
|
|
var s = (a + b + c) / 2;
|
||
|
|
A = sqrt(s * (s - a) * (s - b) * (s - c));
|
||
|
|
""",
|
||
|
|
"tags": ["geometry", "triangle", "area"]
|
||
|
|
}
|
||
|
|
]
|