Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i am a mechanical engineering student.(so i don't know too much about programming)
I wanna make a program that draws curves with rational Bezier (I should write the code myself and not using formGraphics.DrawBezier). I've recently started learning c# and i am so new to it. I've searched alot and just got very confused.

How can i make a field that with each click of the mouse (within it) returns a set of (x , y) and puts a dot there. After choosing a bunch of points (starting with 3) it completes the curve (by using the provided rational bezier code).

The problem looks like to me as :
1. A gridded field is required. (with high resolution)
2. The field returns the position (x , y).
3. The field should get some inputs and draws them.
4. The program should look like the sketching part of the CAD softwares (just in case of working environment not the abilities) :D

I would appreciate if you tell me what should i learn to the above. :)
consider that I almost don't know anything about GUI.

thank you.

What I have tried:

searching the internet and getting confused !! :D
Posted
Updated 10-May-16 4:20am
Comments
Sergey Alexandrovich Kryukov 10-May-16 9:43am    
What do you mean "how"? By doing appropriate software development work. I'm afraid, if you "don't know too much", you first need to learn much. Very much. The project doesn't look simple; it doesn't even look too small; even for the most experienced developer it means considerable effort. And you didn't even indicate the application type and UI framework/library you want to use (under the C# category, there are too many different possibilities), so you are probably unaware of them. No wonder you got confused. If you want to learn programming, you should better do much simpler projects and learn a lot.
—SA
farhad baghyari 10-May-16 14:40pm    
thank you for your reply. as you said I still need to learn, and actually i asked about what to learn and didn't ask for codes.I didn't know that this project would be that much hard, by the way i have to do it because it's a course project. in case of UI framework and library that you asked for i should say that i haven't done anything yet :D and i am just planning for what i should do, so i would know what to learn :)
thanks for you comment :)
Sergey Alexandrovich Kryukov 10-May-16 15:41pm    
I understand. It's just too much to make sense for a Quick Answer. It's not very hard, in my opinion, it just involves a lot. Solution 1... hm... this is not what is needed for designer's scratch pad. I can give you a solution of few lines in WPF, where you simply use one available control. But why? Drawing ink won't save you...
—SA
farhad baghyari 11-May-16 0:22am    
thank you for following the question, but actually i couldn't completely understand what you mean? since English is not my first language and also i don't know what is WPF?
Sergey Alexandrovich Kryukov 11-May-16 0:41am    
Farhad,

You see, this is exactly the reason why I did not advise you to get into such problems — not just yet. Minimally experienced engineer would find what is that (Windows Workflow Foundation, something which each and every .NET developer knows, at least a bit; this is no less that one of the major kinds of .NET projects and quite a big part of .NET) in no time...

I hope your English will allow you to understand what I mean; if not, I'll gladly try to qualify.

—SA

1 solution

That's pretty simple to start with: the mouse capture stuff is trivial.
Add a Panel to a form - call it "myDrawing" - and handle two events for the Panel: Paint, and MouseClick.
Add a list to your form class:
C#
private List<Point> points = new List<Point>();

Now, in the MouseClick handler, add the location to the list and invalidate the panel:
C#
private void myDrawing_MouseClick(object sender, MouseEventArgs e)
    {
    points.Add(e.Location);
    myDrawing.Invalidate();
    }

In the Paint handler, draw the points:
C#
private void myDrawing_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    foreach (Point p in points)
        {
        g.FillEllipse(Brushes.Red, new Rectangle(p.X - 2, p.Y - 2, 4, 4));
        }
    }
Gridding the field isn't difficult (it's just a case of "rounding up" the location before you save it and drawing faint lines in the Paint event if you need them)
That should give you a start - to draw the Bezier is the complicated bit, but Wiki should help: Bézier curve - Wikipedia, the free encyclopedia[^]
Don't expect this to work first time, and don't expect it to be easy - implementing Bezier is not a trivial exercise!
Have a look at the Graphics class[^] and you see it has a DrawPath method whihc may be of use to you in drawing the actual curve.
Good luck!
 
Share this answer
 
Comments
farhad baghyari 10-May-16 14:50pm    
really thank you for your solution, that would greatly help me to start, however there are alot that i should learn and now I've got a starting point.
I think the bezier curve itself wouldn't be a big trouble (since the course is about curves and CAD softwares so bezier, B-spline and NURBS are covered) but the problem is that i am not a programmer and i want to and have to learn and do it.
thank you again for your answer :)
OriginalGriff 10-May-16 15:03pm    
You're welcome!
If you get stuck on something specific, feel free to ask another question.
farhad baghyari 11-May-16 0:15am    
sure, thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900