# HP Forums

Full Version: Attempt at a 3D parametric grapher
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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. 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!
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
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?
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.
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;
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. Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :