HP Forums
Attempt at a 3D parametric grapher - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Attempt at a 3D parametric grapher (/thread-12561.html)

Attempt at a 3D parametric grapher - TheLastMillennial - 03-05-2019 02:12 AM

For some reason the absence of this app has really bugged me, in fact so much I've decided to try to make one. However, I've never really dealt with making anything in 3D, I don't understand how the equations actually work, and I certainly have never made a grapher before. Sounds like a typical ambitious project a newbie would attempt doesn't it? Yeah, that's kinda my shtick. Tongue

Anyways, I've done some research (wikipedia) and I think I understand the concept of 2D rotation. However, 3D rotation still breaks my brain, especially when I try of how this could work with more than just a simple cube example. I also looked around here and found this topic that contains this code:

(11-20-2014 07:59 AM)Han Wrote:  Here's some code you can modify:
  local n:=1,l;
  return 0;

The matrix in the code is a 3x4 matrix used for perspective projection. The first three columns correspond to the 3x3 matrix resulting form the product of the three rotation matrices (about each axis). The last column is simply the eyepoint vector <0,0,d>. You'll need to adjust the 15 so that the distance d is larger than the distance from the center of the viewing box to the corner farthest from the center of the viewing box (similarly for the 16*15 value).

Edit: If you need help writing your own program, just post on the forums here and I'm sure someone will help. I've been thinking about creating a 3D parametric plot app but am already buried deep in other projects (also 3D related).
Unfortunately, there are no comments within the code and I can't figure out how this all works. Definitely the part I'm most confused on is what do the variables represent? (The a,c,t0,tn,dt)

I'd really appreciate it if someone could clarify the code I've posted, or provide a resource that I can learn how to program (or just graph) 3D parametric equations.

RE: Attempt at a 3D parametric grapher - cyrille de brébisson - 03-05-2019 06:20 AM


if you look at the on calc help for triangle, there is a program there (in the example). it rotate a thetrahedron. but it would work with lines also...

you can use it as a base...
or Han excelent 3d grapher...


RE: Attempt at a 3D parametric grapher - TheLastMillennial - 03-05-2019 11:44 PM

Ok, so I think I understand how the rotation would work but how do I make the points? Do I have to choose certain x,y, and z value and just plug them in and solve for each x=,y=, and z= separately or is there a better way?

RE: Attempt at a 3D parametric grapher - Han - 03-06-2019 04:36 AM

That snippet of code was supposed to draw a 3D path defined by r(t) -- basically a helix. The a represents the radius of the helix, c its height, and t0 and tn are the starting/ending angles of the helix.

If you want to create a 3D parametric grapher, you will need to generate your points, and use the TRIANGLE or TRIANGLE_P command. Read


for a brief overview.

RE: Attempt at a 3D parametric grapher - cyrille de brébisson - 03-06-2019 07:02 AM


In your case, you will need to generate points doing somehting like:

points:= MAKELIST({fx(pa(I),pb(I)),fy(pa(I),pb(I)),fz(pa(I),pb(I))},I,0,99);

This just generates a list of points with x, y and z values being the result of user defined fx, fy, fz functions.
I use a single variable here for facility purpose, but you could use a double for loop (probaby better actually, but I was trying to show off) and use pa and pb to transform a value from 0 to 99 into 2 values varying from 0 to 9....

Then you need to make your triangle or line list. This one is actually much harder to make :-). In this list, you need to put doublets (or triplets) of point indices to specify your lists...

The beauty of the LINE_P and TRIANGLE_P functions is that they will do the rotations and other operations for you....


I have defined fx, fy, fz, pa and pb like so:
export fx(a,b)
return a+b;

export fy(a,b)
return a-b;

export fz(a,b)
return a*b;

export pa(a)
return a mod 10;

export pb(a)
return ip(a/10);

RE: Attempt at a 3D parametric grapher - TheLastMillennial - 03-07-2019 04:28 AM

Oh boy, that's a lot to take in. Thank you Han and cyrille, I really appreciate your replies! I'll get to work on this soon™! In all seriousness, I will work on this during my sparse free time and focus on it once a few real life projects are finished. Smile