BLOG.CSHARPHELPER.COM: Draw a simple robot arm with a hand in C#
Draw a simple robot arm with a hand in C#
The example Draw a simple robot arm in C# shows how to use transformations to make it (relatively) easy to draw a robot arm. Each piece of the arm is transformed due to the pieces closer to the arm's base at the shoulder. See that example for the basic explanation.
This example adds a hand that opens and closes. The following code shows how the program draws its arm with the new code highlighted in blue.
// Draw the robot arm. private void DrawRobotArm(Graphics gr) { const int UpperArmLength = 75; const int LowerArmLength = 50; const int WristLength = 20; const int HandWidth = 48; const int FingerLength = 30;
There are only two additions to this code beyond what was used in the previous example. First, the code adds a translation to move to the end of the final arm segment. That positions future drawing at the end of the arm where the hand should be.
The second change is simply the code that draws the hand.
Adding more segments to a robot arm is just as easy. Add a translation and rotation to move to the end of the current segment, and then draw the new section.
Comments