0

I need to draw characters like alpha(α) beta(β) and gamma(γ) using bezier curve. I am not able to find the correct control points combination. So should I make any changes in the program or should I change it completely.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
#include<conio.h>
#include<math.h>
#define POINTS 10
int x[POINTS],y[POINTS],no,endl,i,k;
double factorial(double number)
{
    double product=1;
    for(i=1;i<number;i++)
    product*=i;
return product;
}
void getData()
{
    printf("enter no. of points:");
    scanf("%d",&no);
    printf("enter points:%d",endl);
    for(i=0;i<no;i++)
    {
    printf("x=%d ",i);
    scanf("%d",&x[i]);
    printf("y=%d ",i);
    scanf("%d", &y[i]);
    }
    for(i=1;i<no;i++)
    line(x[i-1],y[i-1],x[i],y[i]);
}
void Bezier() 
{
    double b=0,f=0;
    double u=0.0001;
    while(u<=1)
    {
    double xu=0,yu=0;
        for(k=0;k<=no;k++)
        {        
        f=factorial(no)/(factorial(k)*factorial(no-k));
        b=pow(u,k)*pow((1-u),(no-k));
        xu+=x[k]*f*b;
        yu+=y[k]*f*b;
        }
        putpixel(xu,yu,WHITE);
        u+=0.0001;
    }
}

void main()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");
getData();
no--;
Bezier();
getch();
closegraph();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Aniket
  • 27
  • 1
  • 1
  • 9
  • Why not just first draw the curves you want in any of the great many free-or-payed vector drawing programs, then just look what the associated coordinates are? If you need to design letters, design first, then implement. Or at the very least draw some stuff out first, so you can guess wrong-but-at-least-close-enough coordinates. Also, it's a good idea to tag your post with the language/technology you're using. This looks like arduino code. – Mike 'Pomax' Kamermans Sep 14 '15 at 16:09
  • Alpha and Gamma can be done with four control points, not Beta. You can rely on the property that the curve is tangent to the segments from the first to the second vertex and from the third to the fourth. –  Sep 14 '15 at 16:14
  • @YvesDaoust Not able to draw alpha or beta..Keep getting random curves. – Aniket Sep 15 '15 at 13:24
  • @Monty I'm seeing `cout` and `cin`, so you're definitely not using C. At the very least, you're using C++ (very different beast). But again: get something like [inkscape](https://inkscape.org/en), **just draw your curve**, and then see what that means in terms of coordinates. – Mike 'Pomax' Kamermans Sep 15 '15 at 16:45
  • @Monty as I mentioned to your predecessors question about this homework you will need more than 1 Bezier curve per letter or use higher order Bezier polynomial. alpha/gamma is doable with single one but beta is not (too complex shape for single cubic curve). As mentioned by others draw the letters in some vector editor and get the control points from there (use SVG editor of some kind like INKSCAPE and then open SVG in notepad to get the coordinates...) If you want to code the capture for yourself look here [SVG Paths and the Catmull-Rom algorithm](http://stackoverflow.com/a/30750626/2521214) – Spektre Sep 16 '15 at 07:52
  • @YvesDaoust Thanks a lot! – Aniket Sep 16 '15 at 11:31
  • @Mike'Pomax'Kamermans Thanks a lot! – Aniket Sep 16 '15 at 11:31
  • @YvesDaoust I tried using inkscape, I drew alpha using inkscapes bezier function, but when take its coordinate and insert in my c++ program, all I get is a straight line(maybe I am doing it wrong idk).. Please can you help me out..Is there any other method where I can get control points? – Aniket Sep 22 '15 at 14:59
  • @Mike'Pomax'Kamermans I tried using inkscape, I drew alpha using inkscapes bezier function, but when take its coordinate and insert in my c++ program, all I get is a straight line(maybe I am doing it wrong idk).. Please can you help me out..Is there any other method where I can get control points? – Aniket Sep 22 '15 at 14:59
  • 1
    Show us your coordinates. –  Sep 22 '15 at 15:06
  • as per @YvesDaoust's comment, if you get new information (like coordinates), update your post with that information. In this case I'd say "show a picture of what you draw, show which coordinates that gave you, and show what your code drew instead"? – Mike 'Pomax' Kamermans Sep 22 '15 at 16:04
  • @Mike'Pomax'Kamermans..Hey I just changed my entire code..Now I can select no. of control points..Btw I am still stuck at control points problem where with the inkscape I am not able to get correct coordinates :(.. Maybe because the desired origin is Top-Left corner and in inkscape its reverse of that..I tried opening .svg from a text editor and changing height and width but it didnt help..I drew a rough sketch of alpha and its coordinates were:- 5 points (x,y):- (163,534), (445, 237), (722, 782), (448, 885) (88, 314) – Aniket Sep 25 '15 at 15:25
  • @YvesDaoust Hey I just changed my entire code..Now I can select no. of control points..Btw I am still stuck at control points problem where with the inkscape I am not able to get correct coordinates :(.. Maybe because the desired origin is Top-Left corner and in inkscape its reverse of that..I tried opening .svg from a text editor and changing height and width but it didnt help..I drew a rough sketch of alpha and its coordinates were:- 5 points (x,y):- (163,534), (445, 237), (722, 782), (448, 885) (88, 314) – Aniket Sep 25 '15 at 15:29

0 Answers0