Showing posts with label 3D. Show all posts
Showing posts with label 3D. Show all posts

Saturday, April 27, 2019

HP Prime: Drawing 3D Lines and Boxes

HP Prime:  Drawing 3D Lines and Boxes

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

EXPORT ROTMATRIX(a,b,c)
BEGIN
// rotate x axis
// rotate y axis
// rotate z axis
LOCAL x,y,z,r; 

x:=[[1,0,0],[0,COS(a),−SIN(a)],
[0,SIN(a),COS(a)]];
y:=[[COS(b),0,−SIN(b)],[0,1,0],
[SIN(b),0,COS(b)]];
z:=[[COS(c),−SIN(c),0],
[SIN(c),COS(c),0],[0,0,1]];
r:=x*y*z;

RETURN r;

END;

Drawing the Boxes

HP Prime Program:  DRAWBOX



The program DRAWBOX draws a simple box. 

EXPORT DRAWBOX()
BEGIN
// 3D line demo
// draw still box demo 
// 2019-04-23 EWS

// black background
RECT(0);

// colors - do this first
LOCAL c1:=#FFFF00h; // yellow
LOCAL c2:=#39FF14h; // neon green
LOCAL c3:=#FFFFFFh; // white


// points of the cube
LOCAL p:={{−3,0,0,c1},{0,−2,2,c1},
{3,0,0,c1},{0,2,−2,c2},
{−3,6,0,c1},{0,4,2,c1},
{3,6,0,c1},{0,8,−2,c2}};


// line definitions
// bottom
LOCAL d1:={{1,2},{2,3},
{3,4},{4,1}};
// top
LOCAL d2:={{5,6},{6,7},
{7,8},{8,5}};
// sides, override with white
LOCAL d3:={{1,5,c3},{2,6,c3},
{4,8,c3},{3,7,c3}};

// rotation matrix
LOCAL r:=[[1,0,0],[0,1,0],
[0,0,1]];

LINE(p,d1,r);
LINE(p,d2,r);
LINE(p,d3,r);

WAIT(0);

END;


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.

EXPORT DRAWBOX2(a,b,c)
BEGIN
// 3D line demo
// draw 3D box
// 2019-04-23 EWS
// rotate the cube

// set degrees mode
HAngle:=1;

// rotation calculation
// rotate x axis
// rotate y axis
// rotate z axis
LOCAL x,y,z,r; 

x:=[[1,0,0],[0,COS(a),−SIN(a)],
[0,SIN(a),COS(a)]];
y:=[[COS(b),0,−SIN(b)],[0,1,0],
[SIN(b),0,COS(b)]];
z:=[[COS(c),−SIN(c),0],
[SIN(c),COS(c),0],[0,0,1]];
r:=x*y*z;

// black background
RECT(0);

// colors - do this first
LOCAL c1:=#FFFF00h; // yellow
LOCAL c2:=#39FF14h; // neon green
LOCAL c3:=#FFFFFFh; // white


// points of the cube
LOCAL p:={{−3,0,0,c1},{0,−2,2,c1},
{3,0,0,c1},{0,2,−2,c2},
{−3,6,0,c1},{0,4,2,c1},
{3,6,0,c1},{0,8,−2,c2}};


// line definitions
// bottom
LOCAL d1:={{1,2},{2,3},
{3,4},{4,1}};
// top
LOCAL d2:={{5,6},{6,7},
{7,8},{8,5}};
// sides, override with white
LOCAL d3:={{1,5,c3},{2,6,c3},
{4,8,c3},{3,7,c3}};

// rotation matrix is already
// defined

LINE(p,d1,r);
LINE(p,d2,r);
LINE(p,d3,r);

WAIT(0);

END;

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:

EXPORT TEST6241()
BEGIN
// test 3D triangle
RECT_P();

//TRIANGLE({0,0,#0h,0},
//{2,2,#0000FFh,39},
//{1,5,#FF0000h,−2});

LOCAL c:=#400080h;
LOCAL p:={{0,0,0},{−10,−8,2},
{−6,4,3},{0,0,0}};
LOCAL d:={{1,2,3,c},{1,2,4,c},
{1,3,4,c},{2,3,4,c}};
local rotmat= [[1, .5, 0], [.5, 1, .5], [0, .5, 1]];   // Initial rotation matrix. No rotation but translate to middle of screen 
TRIANGLE(p,d,rotmat);

WAIT(0);
END;

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!

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Thursday, May 21, 2015

Review: QuickGraph+ for iOS


App Information:
App: QuickGraph+
Platform: iOS
Created by KZLabs
Programmers: Alex Restrepo, Alejandro Montoya
Testing: José Betancur
Graphics: Giovanni Mojica
Twitter: @quickgraph

Cost: $1.99 (I purchased it on 2015-05-18). There is a free version, which has a limited function set, but I am going to review the paid app.

Version in Review: 2.5.4

Key Features:

* Graph functions, inequalities, polar, spherical, cylindrical, and implicit statements in 2D and 3D.

* You can save graphs to the Camera roll, as well as use them in emails or tweets.

* Including the variable n in the expression will allow a dynamic graph. You can set he limits to n and the amount of steps between the limits.

* 2D functions, in the form of y=f(x), can be traced (tap the function and hold). When two or more functions are graphed, and one of them is traced, QuickGraph+ displays roots and intersections where appropriate. This is automatic.

What I Like the Most:

* Pressing the nine-square icon will bring up the table. This is available for the 2D graphs only.

* Derivative of functions can be graphed and symbolic analyzed. We can take the following derivatives d/dx, d/dy, and d/dz. To see the symbolic analyzation, press the blue circular icon with the ellipsis (...). On the iPod Touch/iPhone version, a step by step analysis is shown.

* Speaking of analysis, you can enter numerical expressions and they will be automatically analyzed. Just press the [ + ] button and enter the expression. In this sense, this is a scientific calculator.

* You can store functions and graph statements in the app's built in library. The library is stocked with several graph statements when you download QuickGraph+ for the first time. The library is accessed by pressing the book icon. Graphs that are active are listed on top, and those not already stored can be by pressing the small book icon next to them.

* The modulus function (mod), can work with any real number, not just positive integers.

Being Nit Picky?

* Not being able to trace polar functions like regular functions.

* Not being able to trace functions that contain n or be analyzed.

Wish List:

* The ability to plot parametric functions, both in 2D and 3D.

Verdict:

This is a fun app and you can graphically explore functions, patterns, and inequalities. Sharing graphs is a plus. Not a bad way to spend $1.99!


Eddie

This blog is property of Edward Shore. 2015



RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...