fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. float bezier(float x2, float y2, float x3, float y3, float t)
  5. {
  6. if(t > 1)t = 1;
  7. else if (t < 0)t = 0;
  8. float x1, y1 = 0;
  9. float x4, y4 = 1;
  10. std::cout << "X: " <<(pow((1-t), (1 / 3.0))*x1) + (pow((1-t), (1 / 2.0))*x2*(3*t))+ ((3*pow((t), (1 / 2.0)))*(1-t)*x3)+(pow((t), (1 / 3.0))*x4) << std::endl;
  11. std::cout << "Y: " <<(pow((1-t), (1 / 3.0))*y1) + (pow((1-t), (1 / 2.0))*y2*(3*t))+ ((3*pow((t), (1 / 2.0)))*(1-t)*y3)+(pow((t), (1 / 3.0))*y4) << std::endl;
  12. std::cout << "x: " << (pow( (1-t),( 1 / 3.0 ) )*x1)+(3*(pow( (1-t),( 1 / 2.0 ) ))*t*x2)+(3*(t-1)*(pow( t,( 1 / 2.0 ) ))*x3)+((pow( t,( 1 / 3.0 ) ))*x4) << std::endl;
  13. std::cout << "y: " <<(pow( (1-t),( 1 / 3.0 ) )*y1)+(3*(pow( (1-t),( 1 / 2.0 ) ))*t*y2)+(3*(t-1)*(pow( t,( 1 / 2.0 ) ))*y3)+((pow( t,( 1 / 3.0 ) ))*y4) << std::endl;
  14. std::cout << "t: " << t << std::endl;
  15. }
  16. int main() {
  17. for(float t = 0; t <= 1.1; t+=0.1)
  18. bezier(0, 0, 1, 1, t);
  19. return 0;
  20. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
X: 0
Y: 0
x: 0
y: 0
t: 0
X: 0.853815
Y: 1.31797
x: -0.853815
y: -0.389656
t: 0.1
X: 1.07331
Y: 1.65812
x: -1.07331
y: -0.488509
t: 0.2
X: 1.15022
Y: 1.81965
x: -1.15022
y: -0.480784
t: 0.3
X: 1.13842
Y: 1.87523
x: -1.13842
y: -0.401614
t: 0.4
X: 1.06066
Y: 1.85436
x: -1.06066
y: -0.26696
t: 0.5
X: 0.929516
Y: 1.77295
x: -0.929516
y: -0.0860833
t: 0.6
X: 0.752994
Y: 1.6409
x: -0.752994
y: 0.13491
t: 0.7
X: 0.536656
Y: 1.46497
x: -0.536656
y: 0.391662
t: 0.8
X: 0.284605
Y: 1.25009
x: -0.284605
y: 0.680885
t: 0.9
X: 0
Y: 1
x: 0
y: 1
t: 1