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, Fraction, or float.
alias of TypeVar(‘NumType’, int, ~fractions.Fraction, float)
- rat_trig.trigonom.Numeric¶
int, Fraction, or float.
- Type:
Type alias for numeric types
- rat_trig.trigonom.archimedes(q_1: int | Fraction | float, q_2: int | Fraction | float, q_3: int | Fraction | float) int | Fraction | float[source]¶
The function archimedes calculates the quadrea of a triangle using Archimedes’ formula with the lengths of the three sides q_1, q_2, and q_3. It can also be used to check if a quadraple with length Q1, Q2, Q3, Q4 is on a circle.
- Parameters:
q_1 (Numeric) – The function archimedes takes three parameters q_1, q_2, and q_3 of type Numeric and returns a value of type Numeric
q_2 (Numeric) – The q_2 parameter in the archimedes function represents a value of type Numeric. It is one of the input parameters along with q_1 and q_3. The function performs a calculation using these parameters and returns a result of type Numeric
q_3 (Numeric) – The function archimedes takes three parameters q_1, q_2, and q_3, all of type Numeric. It then calculates a value based on these parameters and returns the result
- Returns:
the result of the expression (4 times q_1 times q_2 - text{temp}^2), where (text{temp} = q_1 + q_2 - q_3).
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 | float], v_2: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The cross function calculates the cross product of two vectors v_1 and v_2.
- Parameters:
- Returns:
The cross product of the two vectors.
- Return type:
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> cross(v_1, v_2) -2
- rat_trig.trigonom.dot(v_1: Sequence[int | Fraction | float], v_2: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The dot function calculates the dot product of two vectors v_1 and v_2.
- Parameters:
- Returns:
The dot product of the two vectors.
- Return type:
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> dot(v_1, v_2) 11
- rat_trig.trigonom.quad(vector: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The quad function calculates the quadrance of a vector vector.
- Parameters:
vector (Sequence[Numeric]) – A sequence of two numbers (integers, fractions, or floats).
- Returns:
The quadrance of the vector.
- Return type:
Example
>>> vector = [3, 4] >>> quad(vector) 25
- rat_trig.trigonom.spread(v_1: Sequence[int | Fraction | float], v_2: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The spread function calculates the spread between two vectors v_1 and v_2. The spread is the square of the cross product divided by the product of the quadrances. It represents the square of the sine of the angle between the vectors.
- Parameters:
- Returns:
The spread between the two vectors.
- Return type:
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 | float, q_2: int | Fraction | float, q_3: int | Fraction | float) int | Fraction | float[source]¶
The spread_law function calculates the spread of a triangle using the law of spreads. In rational trigonometry, the spread law states that for a triangle with quadrances Q1, Q2, Q3, the spread S3 opposite to Q3 can be calculated by: S3 = 4*Q1*Q2 - (Q1 + Q_2 - Q3)^2 / (4*Q1*Q2)
- Parameters:
- Returns:
The spread S3 opposite to the quadrance q_3
- Return type:
Example
>>> q_1 = 5 >>> q_2 = 25 >>> q_3 = 20 >>> spread_law(q_1, q_2, q_3) 0.8
- rat_trig.trigonom.triple_quad_formula(q_1: int | Fraction | float, q_2: int | Fraction | float, s_3: int | Fraction | float) int | Fraction | float[source]¶
The triple_quad_formula function calculates a value based on two quadrances and a spread. In rational trigonometry, this formula is related to the relationship between three quadrances and the spread between them.
- Parameters:
- Returns:
A calculated value using the triple quad formula
- Return type:
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 | float, q_2: int | Fraction | float, q_3: int | Fraction | float) int | Fraction | float[source]¶
The function archimedes calculates the quadrea of a triangle using Archimedes’ formula with the lengths of the three sides q_1, q_2, and q_3. It can also be used to check if a quadraple with length Q1, Q2, Q3, Q4 is on a circle.
- Parameters:
q_1 (Numeric) – The function archimedes takes three parameters q_1, q_2, and q_3 of type Numeric and returns a value of type Numeric
q_2 (Numeric) – The q_2 parameter in the archimedes function represents a value of type Numeric. It is one of the input parameters along with q_1 and q_3. The function performs a calculation using these parameters and returns a result of type Numeric
q_3 (Numeric) – The function archimedes takes three parameters q_1, q_2, and q_3, all of type Numeric. It then calculates a value based on these parameters and returns the result
- Returns:
the result of the expression (4 times q_1 times q_2 - text{temp}^2), where (text{temp} = q_1 + q_2 - q_3).
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 | float], v_2: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The cross function calculates the cross product of two vectors v_1 and v_2.
- Parameters:
- Returns:
The cross product of the two vectors.
- Return type:
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> cross(v_1, v_2) -2
- rat_trig.dot(v_1: Sequence[int | Fraction | float], v_2: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The dot function calculates the dot product of two vectors v_1 and v_2.
- Parameters:
- Returns:
The dot product of the two vectors.
- Return type:
Example
>>> v_1 = [1, 2] >>> v_2 = [3, 4] >>> dot(v_1, v_2) 11
- rat_trig.quad(vector: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The quad function calculates the quadrance of a vector vector.
- Parameters:
vector (Sequence[Numeric]) – A sequence of two numbers (integers, fractions, or floats).
- Returns:
The quadrance of the vector.
- Return type:
Example
>>> vector = [3, 4] >>> quad(vector) 25
- rat_trig.spread(v_1: Sequence[int | Fraction | float], v_2: Sequence[int | Fraction | float]) int | Fraction | float[source]¶
The spread function calculates the spread between two vectors v_1 and v_2. The spread is the square of the cross product divided by the product of the quadrances. It represents the square of the sine of the angle between the vectors.
- Parameters:
- Returns:
The spread between the two vectors.
- Return type:
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 | float, q_2: int | Fraction | float, q_3: int | Fraction | float) int | Fraction | float[source]¶
The spread_law function calculates the spread of a triangle using the law of spreads. In rational trigonometry, the spread law states that for a triangle with quadrances Q1, Q2, Q3, the spread S3 opposite to Q3 can be calculated by: S3 = 4*Q1*Q2 - (Q1 + Q_2 - Q3)^2 / (4*Q1*Q2)
- Parameters:
- Returns:
The spread S3 opposite to the quadrance q_3
- Return type:
Example
>>> q_1 = 5 >>> q_2 = 25 >>> q_3 = 20 >>> spread_law(q_1, q_2, q_3) 0.8
- rat_trig.triple_quad_formula(q_1: int | Fraction | float, q_2: int | Fraction | float, s_3: int | Fraction | float) int | Fraction | float[source]¶
The triple_quad_formula function calculates a value based on two quadrances and a spread. In rational trigonometry, this formula is related to the relationship between three quadrances and the spread between them.
- Parameters:
- Returns:
A calculated value using the triple quad formula
- Return type:
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)