are there sample codes made with : Midpoint, Cohen-Sutherland, Scan-line algorythm?

Hi,

i'm completely beginner. I have to do a "homework" for a universiy couse.

There are many tasks, and there are roles:

1, i can use just point() function

2, the structure must be:
setup{}
draw{}
own line drawer function{}
other functions{}
mousepressed{}
keypressed{}

the algorythms should be:
Midpoint
Cohen-Sutherland
Scan line

the drawings are lines, rectangles, konvex poligone.

How can I begin the tasks? Can you link me some examples?

Thanks!

Tagged:

Answers

  • edited May 2017 Answer ✓

    try to read this and try to translate it onto processing values

    is that what you want ? can i have more details for what you wanna do ?

  • read the wikipedia article on this and do some research

    to learn research is the idea of university

    there are tutorials and examples on the web site (after the video there are textual tutorials) and in processing

    you are not allowed to use the command line it seems

    write your own attempt and show your entire code

    then ask specific questions where you are stuck

    nobody is doing it for you

  • hi, i need to do this for 17 Juni, but i have four more exams before this termin. I think i dont have time for many researches, because i work 40 hours a week. I know what is an univesity for, because it will be my FIFTH UNIVERSITY degree, but if you work hard, and have family you dont have time to do researches. i m not a 18 year old student, who has his or her whole life just for learning, and nothing more to do (no work , no family, just sport and clubs). i m 43 years old (woman) , working full time and have a family. I hope you can understand why i dont have much time or so much time as you.

  • Answer ✓

    This will get you started:

    // ---------------------------------------------------------
    
    void setup() {
      size(1300, 800);
      strokeWeight(5);
    }
    
    void draw() {
      background(192);
      lineMy(100, 100, 200, 100);
    }
    
    void lineMy(float x1, float y1, float x2, float y2) {
      if (y1==y2&&x1<x2) {
        for (float i=x1; i<x2; i++)
          point(i, y1);
      }
    }
    //
    
  • edited May 2017 Answer ✓

    do you need diagonals ?

        void setup() {
          size(1300, 800);
          strokeWeight(5);
        }
    
        void draw() {
          background(192);
          lineMy(100, 100, 200, 100);
          lineMy(100, 500, 50, 500);
          lineMy(500, 200, 500, 100);
          lineMy(500, 300, 500, 350);
          lineMy(300, 100, 400, 200);
          lineMy(500, 500, 200, 300);
          lineMy(300, 100, 200, 200);
        }
    
        void lineMy(float x1, float y1, float x2, float y2) {
          if (y1==y2&&x1<x2) {
            for (float i=x1; i<x2; i++) {               //
              stroke(0);
              point(i, y1);
            }
          } else if (y1==y2&&x2<x1) {
            for (float i=x2; i<x1; i++) {              //Horyzontal
              stroke(0, 0, 255);
              point(i, y1);
            }
          } else if (x1==x2&&y1<y2) {
            for (float i=y1; i<y2; i++) {               //Vertical
              stroke(0, 255, 0);
              point(x1, i);
            }
          } else if (x1==x2&&y2<y1) {
            for (float i=y2; i<y1; i++) {              //Vertical
              stroke(255, 0, 0);
              point(x1, i);
            }
          } else if (x1<x2&&y1<y2) {              
            for (float i=x1, j=y1; i<x2; i++, j++) {   //Diagonal
              stroke(255, 255, 0);
              point(i, j);
            }
          } else if (x2<x1&&y2<y1) {              
            for (float i=x2, j=y2; i<x1; i++, j++) {   //Diagonal
              stroke(0, 255, 255);
              point(i, j);
            }
          } 
        }
    
  • edited May 2017

    these are the task traslated from my language into english. sometimes i dont understand everything in my mother language, so i used quotation marks if it is not understandable, i could try it translate again or we could discuss, what the teacher thinks it is not easy for me because of the many rules

    Thanks in advance for any help or advice !!!

    In the task you have to choose just point() function.

    The structure should be: setup{} draw{} line drawing{} other own functions{} mousepressed{} keypressed{}

    The points of the modell should be stored in a Table object and should be loaded with the loadTable() function.

    TASK 1: line drawing with midpoint algorythm it is waiting from the user the coordinates of the two points of the line, if we change the coordinates it draws th same line, if we give the programm 2 points which coordinates are the same , it should draw a „point” line.

    TASK 2 : rectangle cut function (cohen-sutherland algorythm) it is waiting 4 poits coordinates from the user the first 2 points define a line the other two points give the opposite peaks of the rectangle „cutting rectangle” The function should return the endpoints of the line , wich created because of the cut.

    If we change the coordinates, the line and the „cutting rectangle” should be the same.

    TASK 3: a function , which fills out a convex poligon scanning the graphic window it fills out an already drown , closed, convex „broken line” with the color of the line (using the scan-line algorythm)

    TASK 4 : making a programm, which uses the 1st tasks function , and draws ANY line , in the way, that we give the end points , with mouse pressing the graphic windows should be 640 * 480 size

    TASK 5 : using the solution of the 4th task, wicht contains the points of the „cutting rectangle” as in the code given constant , the points which define the lines, can be given through mousepressing The lines, which we give with mousepress, during the running of the programm, should appear „cutted” to the given rectangle the graphic windows should be 640 * 480 size

    TASK 6 : using the function of the 3rd task wich fills the convex poligon with the colour of its lines , if we press the key „t” the points of the convex poligon, should be given as constant in the programm

    TASK 7: the task is to make a .csv file of the 3D object , wich contains reference data and supports the appearance by visibility the object should be a „cutted cube” in 3D in any position , and with 50 „unit” edges

    the cut should start from one apex of the cube the flat of the cut should fit to „bisecting” of 2 edes of the cube and should be paralel of the third edge our model is the „7 page body”

    TASK 8: write a code using the „cutted cube” from the task 7. and turn this cutted cube in any coordinate system if we start the programm the v(1,2,3) paralel projection model should appear with all edges if we press the „l” key we must see just the visible edges if we press the „v” it should be rotate until the running of the programm , and we should see just the visible edges tha appearance should be v(1,2,3) way paralel projection

  • edited May 2017 Answer ✓

    @judit740521 --

    Homework like this should be done in order, one task at a time. You should start with Task 1. Only once it is complete should you do Task 2.

    First -- do you understand the midpoint algorithm? Do you have a textbook, or class notes, or online readings such as the CourseHero page that NoName linked to above? That is key.

    In the task you have to choose just point() function.

    I don't understand "have to choose" in that sentence. "may only use"? Ah, probably -- so the only thing you are allowed to draw on the screen is point() -- you aren't allowed to use line() from Processing.

    Look up functions in the reference -- you can also right-click on words typed into the PDE editor and "Look up in reference":

    Like point:

    The structure should be: setup{} draw{} line drawing{} other own functions{} mousepressed{} keypressed{}

    So look up:

    Okay, now write your code for Task 1 here -- you can see this is the format that @Chrisir and @NoName used. You can also find similar setups in all examples in the Examples sketchbook built in to Processing.

    void setup(){
      // code here
    }
    void draw(){
      // code here
    }
    void lineDrawing(float x1, float y1, float x2, float y2){
      // TASK 1: line drawing with midpoint algorythm it is waiting
      // from the user the coordinates of the two points of the line,
      // if we change the coordinates it draws th same line, if we
      // give the program 2 points which coordinates are the same,
      // it should draw a "point" line.
      // 
      // code here
      // ...somewhere, use point()
    }
    void mousePressed(){
    }
    void keyPressed(){
    }
    

    and to test the code you put in lineDrawing by drawing it to the screen,, but this in draw:

    void draw(){
      // code here
      background(0);
      lineDrawing(10,20,50,100);
    }
    

    I admire you trying to get a 5th degree while working full time. This looks like advanced homework for a complete beginner. However, keep in mind that the forum cannot do your homework for you -- your degrees are supposed to mean that you learned the material.

  • edited May 2017

    Thanks for your help. This course is a correspondent course, because we all have full time job. There were 2 times lessons with the teacher, but the schedule was created so, that the c++ programming course was in the same time with this, so i could not take part. So i didnt have any lessons. The teacher did not share anyting just this tasks, and no material to the tasks. As i m hungarian, i have two difficulties:

    1, i m a completely beginner, i heard first time from processing in februar,

    2, english is not my mother language, and it is hard to understand programming or mathematical algorythms not in your mother language.

    I think the teacher shuold give us material in hungaian , and should not give tasks like these, as we have no base knowledge. He should give us beginners tasks.

    I dont know, what the other univerities are, in Hungary all the schools want to know what you DONT KNOW, give tasks which are impossible to solve, because they forget to teach you. It is a shit country with a shit education. They should teach first, than demand. And they should help, but i wrote the teacher, and he will never help and wont answer any question.

  • edited May 2017 Answer ✓

    @judit740521 -- that sounds very frustrating.

    Focus on Task 1 first. First, describe your understanding of the midpoint algorithm.

    Do you have a textbook, or class notes, or online readings such as the CourseHero page that NoName linked to above?

    Once you have described how the midpoint algorithm works you can try putting your understanding into code, and forum members can help show you how that is done.

  • maybe just skup the tasks for now

    instead play with examples like line above and text box to get an understanding of what it means to program at all.

    then write a sketch with an idea for task 1 and come back with it

  • which you solved is not the task 1 ? i mean this code: String tempText = ""; // while typing

    String textInput1 = ""; // the result String textInput2 = ""; // the result String textInput3 = ""; // the result String textInput4 = ""; // the result

    int state = 0;

    boolean crsIsOn;

    // --------------------------------------------------

    void setup() { size(640, 480);

    rectMode(CORNER); textAlign(LEFT); strokeWeight(1.5); background(#778C85); }

    void draw() {

    if (state>=0 && state<=3) { // input textInput(); } else if (state==4) { // output background(0); fill(255); text (textInput1+"\n"+textInput2 +"\n"+textInput3 +"\n"+textInput4, 200, 200); stroke(255, 2, 2); line (float (textInput1), float (textInput2), float (textInput3), float (textInput4)); }// else if }

    void textInput() { background(#778C85);

    fill(0); rect(29, 10, 200, 30); fill(255);
    text(tempText+cursorSign(), 30, 30);

    String strText=""; if (state==0) strText="x 1"; else if (state==1) strText="y 1"; else if (state==2) strText="x 2"; else if (state==3) strText="y 2";

    text("enter " +strText +", hit return to show result", 240, 10, 200, 88); }

    // --------------------------------------

    void keyPressed() {

    if (key == CODED)
    return;

    // Now the not coded keys

    if (key == BACKSPACE) {
    tempText = tempText.substring(0, max(0, tempText.length()-1)); } else if (key == ENTER | key == RETURN) {

    if (state==0)
      textInput1 = tempText;
    else  if (state==1)
      textInput2 = tempText;
    else if (state==2)
      textInput3 = tempText;
    else if (state==3)
      textInput4 = tempText;
    
    tempText = "";
    state++;
    

    } else if (key == DELETE) {
    tempText = ""; } else if (key >= '0' && key <='9') {
    tempText += key; } }

    // --------------------------------------

    String cursorSign() {

    String buffer="";

    if (frameCount%22 == 0) crsIsOn=!crsIsOn;

    if (crsIsOn) buffer = "|"; else buffer = "";

    return buffer; } //

  • edited May 2017

    No, this is not a solution for your task 1:

    There is no midpoint algorythm in this code

    Also, i am not sure if you are allowed to use the line() command at all

    This code is just a starting point to learn to enter text

  • edited May 2017

    i think i m not able to code mathematical algorythm, as i m a beginner or not a beginner (worse), because i have no base knowledge. i think it is an impossible mission until 17 juni. and i know NOBODY has sent this task to the teacher, because he sent an e-mail yesterday to the participiants of the course, with the note, that we should do the task. i think he enjoys, that all will fail the course. but i know, that it is not the aim of teaching, to show that you (teacher) know and the students not. his task would be to teach us in OUR level, not on HIS LEVEL. I have to pass my other exams, than i will have one week for this, but i think it wont be enough to code algorythm, if i know just line() and no more thing :).

  • you'll manage to do this I am sure

Sign In or Register to comment.