Drawing 3D Lines and Boxes - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: Drawing 3D Lines and Boxes (/thread-12877.html) |
Drawing 3D Lines and Boxes - Eddie W. Shore - 04-27-2019 09:48 PM Link to blog post: https://edspi31415.blogspot.com/2019/04/hp-prime-drawing-3d-lines-and-boxes.html Introduction I was sent an email from Carissa. One of the questions was to explain the 3D features of LINE and TRIANGLE commands. Confession: I have never used to the 3D features of LINE and TRIANGLE before, time to learn something new. Here is what I learned. The Command LINE In 3D drawing, you can connect as many points as you want. In the most simple form, LINE takes three arguments: * Point Definition * Line Definition * Rotation Matrix Point Definition You define points of three dimensions (x, y, z) and if you want, a color. The color attached to the point dominates any portion of the line that is nearest to the point. The point definition is a nested list. Syntax: { {x, y, z, [color]}, {x, y, z, [color]}, {x, y, z, [color]}, ... } Pay attention to the order you set your points. Each point will be tied to an index. For example, the first point in this list will have index 1, the second point in the list will have index 2, and so on. Knowing the index number will be needed for the Line Definition. Line Definition This is where you assign which lines connect to which points. Syntax: { {index start, index end, [color], [alpha]}, {index start, index end, [color], [alpha]}, {index start, index end, [color], [alpha]}, ... } Like the Point Definition, the Line Definition is a nested list. You can make as many points as you want. Color and alpha in the List Definition overrides any color defined in the Point Definition list. Rotation Matrix This tells you the command how you want to rotate the matrix with the respect to the x, y, and z axis, respectively. The acceptable size for the matrix is 2 x 2 (for x and y only), 3 x 3 (x, y, and z axis) and 3 x 4 (I'm not sure what the fourth column is for). For this blog entry and in practice, I use the 3 x 3 rotation matrix. In general: Rx = [ [1, 0, 0],[0 cos a, -sin a],[0, sin a, cos a] ], rotation about the x axis at angle a Ry = [ [cos b, 0, -sin b], [0, 1, 0], [sin b, 0, cos b ] ], rotation about the y axis at angle b Rz = [ [cos c, -sin c, 0], [sin c, cos c, 0], [0, 0, 1] ], rotation about the z axis at angle c Full Rotation matrix: r = Rx * Ry * Rz You can create a program to calculate rotation matrix or copy the syntax to use in your drawing program, as shown here: HP Program ROTMATRIX Code: EXPORT ROTMATRIX(a,b,c) Drawing the Boxes HP Prime Program: DRAWBOX The program DRAWBOX draws a simple box. Code: EXPORT DRAWBOX() HP Prime Program: DRAWBOX2 DRAWBOX2 takes three arguments, rotation of the x axis, rotation of the y axis, and rotation of the z axis. The arguments are entered in degrees, as the calculator is set to Degrees mode in the program. Code: EXPORT DRAWBOX2(a,b,c) 3D Triangles The format for TRIANGLE is similar except the definition list has three points to make up the triangle instead of two. Format: {x, y, z, [ c ]} Code: Code: EXPORT TEST6241() Hope this helps and all of our drawing capabilities on the HP Prime are expanded. Carissa, thank you for your email, much appreciated and I learned a great new skill. All the best! RE: Drawing 3D Lines and Boxes - Han - 04-28-2019 03:15 AM Quote:and 3 x 4 (I'm not sure what the fourth column is for). It designates the distance of the the "viewing screen" from the origin: https://hpmuseum.org/forum/thread-5122.html This final column is what gives 3D perspective. RE: Drawing 3D Lines and Boxes - Eddie W. Shore - 04-28-2019 06:18 AM Thank you Han! Eddie |