c++ - How to get sampling points by rotating a direction in a for loop? -


i need loop on given number of sampling points. sampling points normalized vectors representing directions. should calculate them in code. starting forward vector 1, 0, want rotate around origin came given number of directions.

for(int = 0; < number_of_sampling_points; ++i) {     // direction vector based on , number_of_sampling_points     // ... } 

for example, number_of_sampling_points 4 inside loop want value pairs 1, 0, 0, 1, -1, 0, 0, -1. order doesn't matter.

try this:

const double pi = 3.14159265358979323846; const int number_of_sampling_points = 4; (int = 0; < number_of_sampling_points; ++i) {     const double = pi * 2 * (1.0 - i) / number_of_sampling_points;      double x = sin(a);     double y = cos(a);      cout << "(" << x << " , " << y << ")" << endl; } 

output (rounded):

(1 , 0) (0 , 1) (-1 , 0) (0 , -1) 

Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -