Μαθηματικά#

Εισαγωγή#

The C++ standard library provides basic math functionality through <cmath>, which is supported in VEXcode IQ. These functions let you perform common mathematical operations such as trigonometry, rounding, exponentiation, and more.

Χρησιμοποιήστε τα για τον υπολογισμό θέσεων, γωνιών, αποστάσεων ή για την εκτέλεση μετατροπών μεταξύ μοιρών και ακτινίων.

Παρακάτω είναι μια λίστα με τις διαθέσιμες μαθηματικές συναρτήσεις, σταθερές και βοηθητικά προγράμματα:

Κοινές Μαθηματικές Συναρτήσεις – Κοινά μαθηματικά εργαλεία.

  • abs – Returns the absolute value of a number.

  • fmin – Returns the smallest of the input values.

  • fmax – Returns the largest of the input values.

  • pow – Raises a number to a power.

Constants – Predefined values from <cmath>.

  • M_PI – The constant π (pi).

  • M_E – Euler’s number, base of the natural log.

Τριγωνομετρία – Υπολογισμός γωνιών και σχέσεων μεταξύ πλευρών.

  • sin – Sine of an angle in radians.

  • cos – Cosine of an angle in radians.

  • tan – Tangent of an angle in radians.

  • atan – Arctangent of a value in radians.

  • atan2 – Arctangent of y/x in radians, considering the quadrant.

  • asin – Arcsine of a value in radians.

  • acos – Arccosine of a value in radians.

Στρογγυλοποίηση & Απόλυτη Τιμή – Προσαρμογή ακρίβειας ή κατεύθυνσης.

  • ceil – Rounds up to the nearest integer.

  • floor – Rounds down to the nearest integer.

  • trunc – Removes the decimal portion.

Εκθέτες & Λογάριθμοι – Υπολογισμοί δύναμης, ρίζας και λογαρίθμου.

  • sqrt – Returns the square root.

  • exp – Calculates e to the power of x.

  • log – Natural logarithm (base e).

  • log10 – Base-10 logarithm.

Πράξεις κινητής υποδιαστολής – Έλεγχος ή ανάλυση τιμών κινητής υποδιαστολής.

  • fmod – Remainder with sign of the dividend.

  • copysign – Returns a value with the sign of another.

Κοινές Μαθηματικές Συναρτήσεις#

abs#

Επιστρέφει την απόλυτη τιμή ενός αριθμού, αφαιρώντας οποιοδήποτε αρνητικό πρόσημο.

Available Functions

1 Επιστρέφει την απόλυτη τιμή ενός ακέραιου αριθμού.

int abs( int x );

2 Επιστρέφει την απόλυτη τιμή ενός διπλού.

double abs( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

int or double

Ένας ακέραιος ή διπλός αριθμός.

Return Values

Επιστρέφει την απόλυτη τιμή της εισόδου ως του ίδιου τύπου.

Examples
// Display the absolute value of -10
Brain.Screen.print("%d", abs(-10));

// Output: 10

fmin#

Επιστρέφει τη χαμηλότερη από τις δύο τιμές ως διπλάσια.

Available Functions
double fmin( double value1, double value2 );

Parameters

Παράμετρος

Τύπος

Περιγραφή

value1

double

Η πρώτη τιμή προς σύγκριση.

value2

double

Η δεύτερη τιμή προς σύγκριση.

Return Values

Returns a double representing the smaller of the two input values.

Examples
// Display the lower of two values
Brain.Screen.print("%f", fmin(7, 4));

// Output: 4.000000

fmax#

Επιστρέφει την υψηλότερη από δύο τιμές ως διπλάσια.

Available Functions
double fmax( double value1, double value2 );

Parameters

Παράμετρος

Τύπος

Περιγραφή

value1

double

Η πρώτη τιμή προς σύγκριση.

value2

double

Η δεύτερη τιμή προς σύγκριση.

Return Values

Returns a double representing the larger of the two input values.

Examples
// Display the higher of two values
Brain.Screen.print("%f", fmax(7, 4));

// Output: 7.000000

pow#

Επιστρέφει έναν αριθμό υψωμένο σε δύναμη ως διπλάσιο.

Available Functions
double pow( double base, double exponent );

Parameters

Παράμετρος

Τύπος

Περιγραφή

base

double

Ο βασικός αριθμός.

exponent

double

Ο εκθέτης.

Return Values

Returns a double representing the base raised to the power of the exponent.

Examples
// Display 2 to the power of 3
Brain.Screen.print("%f", pow(2, 3));

// Output: 8.000000

Σταθερές#

Οι σταθερές είναι προκαθορισμένες τιμές που παραμένουν σταθερές κατά τη διάρκεια ενός έργου. Μπορούν να χρησιμοποιηθούν σε υπολογισμούς χωρίς να απαιτείται ορισμός ή ανάθεση.

M_PI#

M_PI gives the mathematical constant π, the ratio of a circle’s circumference to its diameter.

Available Constants
const double M_PI;

Parameters

Αυτή η σταθερά δεν έχει παραμέτρους.

Return Values

Returns the mathematical constant π as a double.

Examples
// Calculate the area of a circle with radius 5
double area = M_PI * 5 * 5;

Brain.Screen.print("%f", area);  

// Output: 78.539816

M_E#

Η μαθηματική σταθερά e (αριθμός του Όιλερ), η βάση του φυσικού λογαρίθμου.

Available Constants
const double M_E;

Parameters

Αυτή η σταθερά δεν έχει παραμέτρους.

Return Values

Returns the mathematical constant e as a double.

Examples
// Calculate e raised to the power of 2
double result = pow(M_E, 2);

Brain.Screen.print("%f", result);  

// Output: 7.389056

Τριγωνομετρία#

sin#

Υπολογίζει το ημίτονο μιας γωνίας σε ακτίνια και επιστρέφει διπλάσιο.

Available Functions
double sin( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό που αντιπροσωπεύει μια γωνία σε ακτίνια.

Return Values

Returns a double representing the sine of the angle.

Examples
// Convert 30 degrees to radians
double radians = 30 * M_PI / 180.0;

// Display the sine of 30 degrees
Brain.Screen.print("%f", sin(radians));

// Output: 0.500000

cos#

Υπολογίζει το συνημίτονο μιας γωνίας σε ακτίνια και επιστρέφει διπλάσιο.

Available Functions
double cos( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό που αντιπροσωπεύει μια γωνία σε ακτίνια.

Return Values

Returns a double representing the cosine of the angle.

Examples
// Convert 60 degrees to radians
double radians = 60 * M_PI / 180.0;

// Display the cosine of 60 degrees
Brain.Screen.print("%f", cos(radians));

// Output: 0.500000

tan#

Υπολογίζει την εφαπτομένη μιας γωνίας σε ακτίνια και επιστρέφει διπλάσια τιμή.

Available Functions
double tan( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό που αντιπροσωπεύει μια γωνία σε ακτίνια.

Return Values

Returns a double representing the tangent of the angle.

Examples
// Convert 45 degrees to radians
double radians = 45 * M_PI / 180.0;

// Compute tangent of 45 degrees
Brain.Screen.print("%f", tan(radians));

// Output: 1.000000

atan#

Υπολογίζει την αντίστροφη εφαπτομένη (εφαπτομένη τόξου) ενός αριθμού και επιστρέφει ένα διπλάσιο που αντιπροσωπεύει τη γωνία σε ακτίνια.

Available Functions
double atan( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Διπλή αξία.

Return Values

Returns a double representing the arc tangent in radians.

Examples
// Calculate the arc tangent of 1 in degrees
double degrees = atan(1.0) * 180.0 / M_PI;

Brain.Screen.print("%f", degrees);

// Output: 45.000000

atan2#

Υπολογίζει την κύρια τιμή της αντίστροφης εφαπτομένης του y/x και επιστρέφει μια διπλή τιμή που αντιπροσωπεύει τη γωνία σε ακτίνια.

Available Functions
double atan2( double y, double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

y

double

Ένα διπλό που αντιπροσωπεύει τη συντεταγμένη y.

x

double

Ένα διπλό που αντιπροσωπεύει τη συντεταγμένη x.

Return Values

Returns a double representing the arc tangent of y/x in radians.

Examples
// Calculate the inverse tangent of 1/1 in degrees
double degrees = atan2(1.0, 1.0) * 180.0 / M_PI;

Brain.Screen.print("%f", degrees);

// Output: 45.000000

asin#

Υπολογίζει το αντίστροφο ημίτονο (τόξο ημιτόνου) ενός αριθμού και επιστρέφει ένα διπλάσιο που αντιπροσωπεύει τη γωνία σε ακτίνια.

Available Functions
double asin( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό μεταξύ -1 και 1.

Return Values

Returns a double representing the arc sine in radians.

Examples
// Calculate the arc sine of 0.5 in degrees
double degrees = asin(0.5) * 180.0 / M_PI;

Brain.Screen.print("%f", degrees);

// Output: 30.000000

acos#

Υπολογίζει το αντίστροφο συνημίτονο (τοξικό συνημίτονο) ενός αριθμού και επιστρέφει ένα διπλάσιο που αντιπροσωπεύει τη γωνία σε ακτίνια.

Available Functions
double acos( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό μεταξύ -1 και 1.

Return Values

Returns a double representing the arc cosine in radians.

Examples
// Calculate the arc cosine of 0.5 in degrees
double degrees = acos(0.5) * 180.0 / M_PI;

Brain.Screen.print("%f", degrees);  

// Output: 60.000000

Στρογγυλοποίηση & Απόλυτη Τιμή#

ceil#

Επιστρέφει έναν αριθμό στρογγυλοποιημένο προς τα πάνω ως διπλάσιο.

Available Functions
double ceil( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό που πρέπει να στρογγυλοποιηθεί προς τα πάνω.

Return Values

Returns a double representing the smallest integer greater than or equal to x.

Examples
// Round up 9.7
Brain.Screen.print("%f", ceil(9.7));

// Output: 10.000000

floor#

Επιστρέφει έναν αριθμό στρογγυλοποιημένο προς τα κάτω ως διπλάσιο.

Available Functions
double floor( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό που στρογγυλοποιείται προς τα κάτω.

Return Values

Returns a double representing the largest integer less than or equal to x.

Examples
// Round down 9.7
Brain.Screen.print("%f", floor(9.7));

// Output: 9.000000

trunc#

Επιστρέφει έναν αριθμό ως διπλάσιο, με το δεκαδικό του μέρος να έχει οριστεί σε μηδέν.

Available Functions
double trunc( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλό που πρέπει να περικοπεί.

Return Values

Returns a double with the decimal portion removed.

Examples
// Truncate 9.7
Brain.Screen.print("%f", trunc(9.7));

// Output: 9.000000

Εκθέτες & Λογάριθμοι#

sqrt#

Επιστρέφει την τετραγωνική ρίζα ενός αριθμού.

Available Functions
double sqrt( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα μη αρνητικό διπλάσιο.

Return Values

Returns a double representing the square root of x.

Examples
// Display the square root of 121
Brain.Screen.print("%f", sqrt(121));

// Output: 11.000000

exp#

Υπολογίζει την εκθετική ενός αριθμού.

Available Functions
double exp( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα διπλάσιο για τον υπολογισμό της εκθετικής του.

Return Values

Returns a double representing e raised to the power of x.

Examples
// Calculate e raised to the power of 1
double result = exp(1);

Brain.Screen.print("%f", result);
  
// Output: 2.718282

log#

Υπολογίζει τον φυσικό λογάριθμο ενός αριθμού.

Available Functions
double log( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα θετικό διπλό.

Return Values

Returns a double representing the natural logarithm of x.

Examples
// Calculate the natural logarithm (base e) of e
double result = log(M_E);

Brain.Screen.print("%f", result);  
  
// Output: 1.000000

log10#

Υπολογίζει τον λογάριθμο με βάση το 10 ενός αριθμού.

Available Functions
double log10( double x );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Ένα θετικό διπλό.

Return Values

Returns a double representing the base-10 logarithm of x.

Examples
// Calculate the base-10 logarithm of 1000
double result = log10(1000);

Brain.Screen.print("%f", result);  
  
// Output: 3.000000

Λειτουργίες κινητής υποδιαστολής#

fmod#

Επιστρέφει το υπόλοιπο της διαίρεσης διατηρώντας το πρόσημο του διαιρετέου.

Available Functions
double fmod( double x, double y );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Το μέρισμα.

y

double

Ο διαιρέτης.

Return Values

Returns a double representing the remainder of x/y with the sign of x.

Examples
// Calculate remainder of 10 / -3
// that preserves the sign of 10
double result = fmod(10.0, -3.0);

Brain.Screen.print("%f", result);  

// Output: 1.000000

copysign#

Επιστρέφει έναν αριθμό με μέγεθος x και πρόσημο y.

Available Functions
double copysign( double x, double y );

Parameters

Παράμετρος

Τύπος

Περιγραφή

x

double

Η τιμή της οποίας το μέγεθος θα χρησιμοποιηθεί.

y

double

Η τιμή της οποίας το πρόσημο θα χρησιμοποιηθεί.

Return Values

Returns a double with the magnitude of x and the sign of y.

Examples
// Return -10 with the sign of -3 (negative)
double result = copysign(10, -3);

Brain.Screen.print("%f", result);  
  
// Output: -10.000000