Post Reply 
Attempt at a 3D parametric grapher
03-05-2019, 02:12 AM
Post: #1
Attempt at a 3D parametric grapher
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:
Code:
#cas
PPLOT(a,c,t0,tn,dt):=
BEGIN
  local n:=1,l;
  r(t):=[a*cos(t),a*sin(t),c*t];
  ptdef:=MAKELIST(r(X),X,t0,tn,dt);
  n:=size(ptdef)-1;
  ldef:=MAKELIST({X,X+1},X,1,n);
  l:=LINE_P(ptdef,ldef,
    {
      [[1,0,0,0],[0,1,0,0],[0,0,1,15]], 
      "N",
      {-160,-120,16*15},
      {-a,a,-a,a,c*t0,c*tn} 
    });
  freeze;
  return 0;
END;
#end

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.
Thanks!

Cemetech | YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
03-05-2019, 06:20 AM
Post: #2
RE: Attempt at a 3D parametric grapher
hello,

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...

cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
03-05-2019, 11:44 PM
Post: #3
RE: Attempt at a 3D parametric grapher
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?

Cemetech | YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
03-06-2019, 04:36 AM
Post: #4
RE: Attempt at a 3D parametric grapher
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

http://www.hpmuseum.org/forum/thread-5122.html

for a brief overview.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-06-2019, 07:02 AM
Post: #5
RE: Attempt at a 3D parametric grapher
Hello,

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....

Cyrille

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

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

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

export pa(a)
begin
return a mod 10;
end;

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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
03-07-2019, 04:28 AM
Post: #6
RE: Attempt at a 3D parametric grapher
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

Cemetech | YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)