HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

Cubic "bezier" curve of grade n

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
gradecurvebeziercubic

Problem

This is code I wrote for calculating bezier curves as quickly and RAM efficiently as possible.

I would like to know if there are faster ways to optimize anything, because I am very new to C++ and efficiency methods.

Lastly, if there is a variable that could be more explicitly named, also let me know.

#include 

double* bezier_interp (double* points, double* temp_space, int temp_space_size, int points_total, double t_step_t) {
    memcpy(temp_space, points, temp_space_size);
    for (int pointsi = points_total; pointsi > 1; --pointsi){
        for (int pointsj = 1; pointsj 

int main() {
    double numbers_x[] = {
        0, 0, 4, 4
    };
    double numbers_y[] = {
        0, 4, 4, 0
    };
    int definition = 8;
    double* xs = bezier_t(numbers_x, 4, definition);
    double* ys = bezier_t(numbers_y, 4, definition);
    for (int dix = 0; dix < definition; dix++){ std::cout << xs[dix] << "\t"; }
    std::cout << "\n";
    for (int diy = 0; diy < definition; diy++){ std::cout << ys[diy] << "\t"; }
    std::cin.get();
    return 0;
}

Solution

-
#include is pointless. There is no vectors in the code.

-
Unless I am missing something obvious, temp_space plays no role in the calculations.

-
pointsi and pointsj do not sound right (too much of visual noise makes it hard to tell them apart). It is one of the rear cases where I'd go for plain i and j.

-
t_step_t is confusing, and strictly speaking unnecessary. You may calculate it at the point of invocation as

result[t] = *besier_interp(..., t * t_step);

Code Snippets

result[t] = *besier_interp(..., t * t_step);

Context

StackExchange Code Review Q#79107, answer score: 2

Revisions (0)

No revisions yet.