Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You must not use any of Processings built-in drawing commands such as point(), line(), triangle(), etc. All images must be created pixel by pixel. The
You must not use any of Processings built-in drawing commands such as point(), line(), triangle(), etc. All images must be created pixel by pixel.
The function bresenhamLine() receives integer coordinates (fromX, fromY) for the starting point of a line, and integer coordinates (toX, toY) for its ending point. Complete this function so that it draws a line on the raster with Bresenham's algorithm, using the specified starting and ending points. You can easily go online and find code for this algorithm that is optimized for integer arithmetic. Do not submit that version: it will receive no marks. Instead, implement the algorithm precisely as described in the Unit 3 video. This includes doing exactly what I just said not to do in Question 1 , and accumulating a float value for the error. Your implementation must work for lines in all eight octants. The template has a display mode that draws several lines using your implementation, and draws comparison lines using Processing's line() function, as shown below. The offset between the red and white lines is done on purpose so that both sets of lines can be seen at the same time. Marks: 3 for one case of the algorithm, 5 for extending it to the remaining octants Interlude: concerning triangles. A triangle in 3D space is defined by the locations of its three vertices. Taken on its own, a triangle is a planar figure. It has a normal vector that can be determined by a 3D cross product of its edge vectors, and that normal vector is the same at every point on the triangle. However, triangles can be used to approximate a curved surface like a cylinder. In that case, each vertex is a point on the surface, and is associated with a normal vector to the surface at that point. If the surface is curved, then the normal vectors may be different at each of the three vertices of the triangle. The Triangle class was written with the latter usage in mind. The constructor for this class expects two arrays of vectors: one containing the vertices, and the other containing the corresponding normal vectors. Although Java makes this something of a hassle, you can add a constructor to the Triangle class that only receives an array of vertices, and treats such a triangle as planar. This is convenient but not required. The Triangle class was also written to facilitate the process of creating rotated copies. Note the method updateAll(), which is called at the end of the constructor. If you add more instance variables to the Triangle class - and you should definitely do so-put the code that calculates their values into updateAll() so that all of your variables are updated as the triangle rotates. Some instance variables to consider adding to Triangle: the edge vectors, the center point, a normal vector at the center point, the projected vertices, the projected edge vectorsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started