Mathematics in VCS?

#1

I’m looking to see if there’s Math in Vex C++ as ROBOTC used to have it.
I’ve no luck in finding “PI” and other mathematical constants and functions

0 Likes

#2

what are you trying to calculate?
edit: you could just use 3.14159 as a replacement

0 Likes

#3

Pi isn’t a standard in C++. There are various suggestions about the best approach. It is available in some libraries. But it’s probably just easiest to make sure you write it properly and declare it globally yourself.

1 Like

#4

atan(1) * 4 = pi mathematically.

The atan library is available.

You could set that to a constant in the program.

0 Likes

#5

I’m trying to get the circumference of the wheels and such. I’m also in need of calculating absolute values of numbers and finding square roots.

0 Likes

#6

We should be supporting all standard math functions.
http://www.cplusplus.com/reference/cmath/

1 Like

#7

Pi is defined as M_PI


Brain.Screen.printAt(20, 20, "%f", M_PI );

(which I should add is not really standard C but happens to be defined for now in VCS as it’s part of math.h)

1 Like

math.h in VCS
#8

Ah, good to know it’s not just standard C, that math.h is included. Thanks.

0 Likes

#10

How do I generate random Numbers in VCS C++?

0 Likes

#11

rand() works, you need a good seed value for srand.

See the example here:
http://www.cplusplus.com/reference/cstdlib/rand/?kw=rand

They use time. and I’m not familiar enough with the V5 API to tell you how to get time from the clock into srand. but you should be able to seed rand and use it in V5.

1 Like