rat_trig package¶
Submodules¶
rat_trig.skeleton module¶
This is a skeleton file that can serve as a starting point for a Python
console script. To run this script uncomment the following lines in the
[options.entry_points] section in setup.cfg:
console_scripts =
fibonacci = rat_trig.skeleton:run
Then run pip install . (or pip install -e . for editable mode)
which will install the command fibonacci inside your current environment.
Besides console scripts, the header (i.e. until _logger…) of this file can
also be used as template for Python modules.
Note
This file can be renamed depending on your needs or safely removed if not needed.
References
- rat_trig.skeleton.main(args: List[str]) None[source]¶
Wrapper allowing
fib()to be called with string arguments in a CLI fashionInstead of returning the value from
fib(), it prints the result to thestdoutin a nicely formatted message.- Parameters:
args (List[str]) – command line parameters as list of strings (for example
["--verbose", "42"]).
- rat_trig.skeleton.parse_args(args: List[str]) Namespace[source]¶
Parse command line parameters
- Parameters:
args (List[str]) – command line parameters as list of strings (for example
["--help"]).- Returns:
command line parameters namespace
- Return type:
rat_trig.trigonom module¶
Rational Trigonometry is a new approach to classical trigonometry, developed by Norman Wildberger, that aims to simplify and clarify the subject by using only rational numbers and operations, rather than irrational numbers and limits.
In traditional trigonometry, concepts such as the sine, cosine, and tangent of an angle are typically defined using circles and the unit circle in particular. These definitions involve irrational numbers and limits, which can make the subject more difficult to understand and work with.
In rational trigonometry, Wildberger replaces these circular definitions with ones based on lines and line segments, which allows for a more straightforward and intuitive approach. The fundamental concepts in rational trigonometry are the “quadaverage” and the “dilated directed angle,” which are defined in terms of lines and line segments, rather than circles.
Rational trigonometry has been gaining popularity in recent years, as it provides a useful alternative to traditional trigonometry for certain applications, such as computer graphics, robotics, and physics. It can also be a helpful tool for students who struggle with the irrational numbers and limits used in traditional trigonometry.
In summary, Rational Trigonometry is a new approach to classical trigonometry that uses rational numbers and operations, rather than irrational numbers and limits, making it a more straightforward and intuitive subject to understand and work with.
- class rat_trig.trigonom.NumType¶
Type variable for numeric types: int or Fraction.
alias of TypeVar(‘NumType’, int, ~fractions.Fraction)
- rat_trig.trigonom.Numeric¶
int or Fraction.
- Type:
Type alias for numeric types
- rat_trig.trigonom.archimedes(q_1: int | Fraction, q_2: int | Fraction, q_3: int | Fraction) int | Fraction[source]¶
Archimedes’ formula for the quadrea of a triangle.
Given three side quadrances \(q_1, q_2, q_3\), the quadrea (signed area squared) is:
\[\mathcal{A} = 4 q_1 q_2 - (q_1 + q_2 - q_3)^2\]This is also used to test whether four points \(Q_1, Q_2, Q_3, Q_4\) lie on a circle.
- Parameters:
q_1 – First quadrance
q_2 – Second quadrance
q_3 – Third quadrance
- Returns:
The quadrea of the triangle
Example
>>> from fractions import Fraction >>> q_1 = Fraction(1, 2) >>> q_2 = Fraction(1, 4) >>> q_3 = Fraction(1, 6) >>> archimedes(q_1, q_2, q_3) Fraction(23, 144)
- rat_trig.trigonom.cross(v_1: Sequence[int | Fraction], v_2: Sequence[int | Fraction]) int | Fraction[source]¶
Scalar cross product of two 2D vectors.
For vectors \(\mathbf{v}_1 = (x_1, y_1)\) and \(\mathbf{v}_2 = (x_2, y_2)\):
\[\mathbf{v}_1 \times \mathbf{v}_2 = x_1 y_2 - y_1 x_2\]This equals the signed area of the parallelogram spanned by the vectors.
- Parameters:
v_1 – A sequence of two numbers
v_2 – A sequence of two numbers
- Returns:
The scalar cross product
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> cross(v_1, v_2) -2
- rat_trig.trigonom.dot(v_1: Sequence[int | Fraction], v_2: Sequence[int | Fraction]) int | Fraction[source]¶
Dot product of two 2D vectors.
For vectors \(\mathbf{v}_1 = (x_1, y_1)\) and \(\mathbf{v}_2 = (x_2, y_2)\):
\[\mathbf{v}_1 \cdot \mathbf{v}_2 = x_1 x_2 + y_1 y_2\]- Parameters:
v_1 – A sequence of two numbers
v_2 – A sequence of two numbers
- Returns:
The dot product
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> dot(v_1, v_2) 11
- rat_trig.trigonom.quad(vector: Sequence[int | Fraction]) int | Fraction[source]¶
Quadrance (squared length) of a 2D vector.
In rational trigonometry, quadrance replaces the classical notion of distance. For a vector \(\mathbf{v} = (x, y)\):
\[Q(\mathbf{v}) = x^2 + y^2\]This is the squared Euclidean norm, always a rational number when \(x, y\) are rational.
- Parameters:
vector – A sequence of two numbers
- Returns:
The quadrance of the vector
Example
>>> vector = [3, 4] >>> quad(vector) 25
- rat_trig.trigonom.spread(v_1: Sequence[int | Fraction], v_2: Sequence[int | Fraction]) int | Fraction[source]¶
Spread between two 2D vectors.
In rational trigonometry, spread replaces the classical angle. It is the square of the sine of the angle between \(\mathbf{v}_1\) and \(\mathbf{v}_2\):
\[s(\mathbf{v}_1, \mathbf{v}_2) = \frac{(\mathbf{v}_1 \times \mathbf{v}_2)^2} {Q(\mathbf{v}_1) \; Q(\mathbf{v}_2)}\]The result is always a rational number between 0 and 1.
- Parameters:
v_1 – A sequence of two numbers
v_2 – A sequence of two numbers
- Returns:
The spread between the two vectors
Example
>>> from fractions import Fraction >>> v_1 = [Fraction(1), Fraction(2)] >>> v_2 = [Fraction(3), Fraction(4)] >>> spread(v_1, v_2) Fraction(4, 125)
- rat_trig.trigonom.spread_law(q_1: int | Fraction, q_2: int | Fraction, q_3: int | Fraction) int | Fraction[source]¶
Law of spreads for a triangle.
In any triangle with quadrances \(q_1, q_2, q_3\), the spread \(S_3\) opposite side \(q_3\) is:
\[S_3 = \frac{\mathcal{A}}{4 q_1 q_2} = \frac{4 q_1 q_2 - (q_1 + q_2 - q_3)^2}{4 q_1 q_2}\]where \(\mathcal{A}\) is the quadrea from Archimedes’ formula.
- Parameters:
q_1 – First quadrance
q_2 – Second quadrance
q_3 – Third quadrance (opposite the angle whose spread is found)
- Returns:
The spread \(S_3\) opposite \(q_3\)
Example
>>> from fractions import Fraction >>> q_1 = 5 >>> q_2 = 25 >>> q_3 = 20 >>> spread_law(q_1, q_2, q_3) Fraction(4, 5)
- rat_trig.trigonom.triple_quad_formula(q_1: int | Fraction, q_2: int | Fraction, s_3: int | Fraction) int | Fraction[source]¶
Triple quad formula relating two quadrances and a spread.
This formula relates two quadrances \(q_1, q_2\) and a spread \(s_3\) through the identity:
\[T(q_1, q_2, s_3) = (q_1 + q_2)^2 - 4 q_1 q_2 (1 - s_3) = (q_1 - q_2)^2 + 4 q_1 q_2 s_3\]When \(s_3 = 1\) (right spread), this reduces to \((q_1 + q_2)^2\); when \(s_3 = 0\) (collinear), it reduces to \((q_1 - q_2)^2\).
- Parameters:
q_1 – First quadrance
q_2 – Second quadrance
s_3 – Spread value
- Returns:
Result of the triple quad formula
Example
>>> from fractions import Fraction >>> q_1 = 5 >>> q_2 = 25 >>> s_3 = Fraction(4, 125) >>> triple_quad_formula(q_1, q_2, s_3) Fraction(416, 1)
Module contents¶
rat_trig - Rational Trigonometry
A Python implementation of Norman Wildberger’s Rational Trigonometry, which replaces traditional trigonometry concepts with quadrance (squared distance) and spread (squared sine of angle) for exact rational calculations.
Main functions: - archimedes: Calculate the quadrea of a triangle - cross: Calculate the cross product of two vectors - dot: Calculate the dot product of two vectors - quad: Calculate the quadrance of a vector - spread: Calculate the spread between two vectors - spread_law: Apply the law of spreads to a triangle - triple_quad_formula: Apply the triple quad formula
- rat_trig.archimedes(q_1: int | Fraction, q_2: int | Fraction, q_3: int | Fraction) int | Fraction[source]¶
Archimedes’ formula for the quadrea of a triangle.
Given three side quadrances \(q_1, q_2, q_3\), the quadrea (signed area squared) is:
\[\mathcal{A} = 4 q_1 q_2 - (q_1 + q_2 - q_3)^2\]This is also used to test whether four points \(Q_1, Q_2, Q_3, Q_4\) lie on a circle.
- Parameters:
q_1 – First quadrance
q_2 – Second quadrance
q_3 – Third quadrance
- Returns:
The quadrea of the triangle
Example
>>> from fractions import Fraction >>> q_1 = Fraction(1, 2) >>> q_2 = Fraction(1, 4) >>> q_3 = Fraction(1, 6) >>> archimedes(q_1, q_2, q_3) Fraction(23, 144)
- rat_trig.cross(v_1: Sequence[int | Fraction], v_2: Sequence[int | Fraction]) int | Fraction[source]¶
Scalar cross product of two 2D vectors.
For vectors \(\mathbf{v}_1 = (x_1, y_1)\) and \(\mathbf{v}_2 = (x_2, y_2)\):
\[\mathbf{v}_1 \times \mathbf{v}_2 = x_1 y_2 - y_1 x_2\]This equals the signed area of the parallelogram spanned by the vectors.
- Parameters:
v_1 – A sequence of two numbers
v_2 – A sequence of two numbers
- Returns:
The scalar cross product
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> cross(v_1, v_2) -2
- rat_trig.dot(v_1: Sequence[int | Fraction], v_2: Sequence[int | Fraction]) int | Fraction[source]¶
Dot product of two 2D vectors.
For vectors \(\mathbf{v}_1 = (x_1, y_1)\) and \(\mathbf{v}_2 = (x_2, y_2)\):
\[\mathbf{v}_1 \cdot \mathbf{v}_2 = x_1 x_2 + y_1 y_2\]- Parameters:
v_1 – A sequence of two numbers
v_2 – A sequence of two numbers
- Returns:
The dot product
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> dot(v_1, v_2) 11
- rat_trig.quad(vector: Sequence[int | Fraction]) int | Fraction[source]¶
Quadrance (squared length) of a 2D vector.
In rational trigonometry, quadrance replaces the classical notion of distance. For a vector \(\mathbf{v} = (x, y)\):
\[Q(\mathbf{v}) = x^2 + y^2\]This is the squared Euclidean norm, always a rational number when \(x, y\) are rational.
- Parameters:
vector – A sequence of two numbers
- Returns:
The quadrance of the vector
Example
>>> vector = [3, 4] >>> quad(vector) 25
- rat_trig.spread(v_1: Sequence[int | Fraction], v_2: Sequence[int | Fraction]) int | Fraction[source]¶
Spread between two 2D vectors.
In rational trigonometry, spread replaces the classical angle. It is the square of the sine of the angle between \(\mathbf{v}_1\) and \(\mathbf{v}_2\):
\[s(\mathbf{v}_1, \mathbf{v}_2) = \frac{(\mathbf{v}_1 \times \mathbf{v}_2)^2} {Q(\mathbf{v}_1) \; Q(\mathbf{v}_2)}\]The result is always a rational number between 0 and 1.
- Parameters:
v_1 – A sequence of two numbers
v_2 – A sequence of two numbers
- Returns:
The spread between the two vectors
Example
>>> from fractions import Fraction >>> v_1 = [Fraction(1), Fraction(2)] >>> v_2 = [Fraction(3), Fraction(4)] >>> spread(v_1, v_2) Fraction(4, 125)
- rat_trig.spread_law(q_1: int | Fraction, q_2: int | Fraction, q_3: int | Fraction) int | Fraction[source]¶
Law of spreads for a triangle.
In any triangle with quadrances \(q_1, q_2, q_3\), the spread \(S_3\) opposite side \(q_3\) is:
\[S_3 = \frac{\mathcal{A}}{4 q_1 q_2} = \frac{4 q_1 q_2 - (q_1 + q_2 - q_3)^2}{4 q_1 q_2}\]where \(\mathcal{A}\) is the quadrea from Archimedes’ formula.
- Parameters:
q_1 – First quadrance
q_2 – Second quadrance
q_3 – Third quadrance (opposite the angle whose spread is found)
- Returns:
The spread \(S_3\) opposite \(q_3\)
Example
>>> from fractions import Fraction >>> q_1 = 5 >>> q_2 = 25 >>> q_3 = 20 >>> spread_law(q_1, q_2, q_3) Fraction(4, 5)
- rat_trig.triple_quad_formula(q_1: int | Fraction, q_2: int | Fraction, s_3: int | Fraction) int | Fraction[source]¶
Triple quad formula relating two quadrances and a spread.
This formula relates two quadrances \(q_1, q_2\) and a spread \(s_3\) through the identity:
\[T(q_1, q_2, s_3) = (q_1 + q_2)^2 - 4 q_1 q_2 (1 - s_3) = (q_1 - q_2)^2 + 4 q_1 q_2 s_3\]When \(s_3 = 1\) (right spread), this reduces to \((q_1 + q_2)^2\); when \(s_3 = 0\) (collinear), it reduces to \((q_1 - q_2)^2\).
- Parameters:
q_1 – First quadrance
q_2 – Second quadrance
s_3 – Spread value
- Returns:
Result of the triple quad formula
Example
>>> from fractions import Fraction >>> q_1 = 5 >>> q_2 = 25 >>> s_3 = Fraction(4, 125) >>> triple_quad_formula(q_1, q_2, s_3) Fraction(416, 1)