Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Make object tetrahedron function

Author
Message
ShadowCentaur 2
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Free Country USA
Posted: 28th Apr 2005 07:57
i was looking to see if anyone could help me with creating a function which makes a tetrahedron as a primitive. it is simple but still 3 dimentional. it only has 4 faces, 1/3 as many as a cube, so thats a small number of polygons for drawing. it would be usefull for small objects that dont need to be detailed. would the best way to go about it be by figureing out where all the vertexes would be in 3d space and making triangles to those vertexes or place/rotate them with sin/cos maths? glue them together or use add limb? i think such a function would be usefull to all.

Truth suffers from too much analysis.
-Ancient Fremen Saying
Kelebrindae
21
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 28th Apr 2005 19:44
I won't be of much help here, but...

I think the best method for this would be to build a memblock containing the vertices' positions and all the other infos (normals, faces, UV mapping) then converting it to a mesh. This should be (quite) easy...

The hard part would be to calculate the vertices' positions. If I had to do it, I would try to extend the function's capability to all platonic solids (dodecahedron, icosahedron, octahedron, and tetrahedron), which share the same properties.

All the necessary maths are here:
[href] http://mathworld.wolfram.com/PlatonicSolid.html [/href]

I only miss the courage to do it...

Ideas: memories of things which did not occur yet...
Kelebrindae
21
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 28th Apr 2005 20:21
Oh, I found the coords of the 4 vertices of a tetrahedron:


(on this page: http://documents.wolfram.com/v5/Add-onsLinks/StandardPackages/Graphics/Polyhedra.html

And here's the faces:


It might help; I'll try to find something more "generic".

Ideas: memories of things which did not occur yet...
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 29th Apr 2005 06:12

Here you go. Just made it.
MakeTetrahedron(Id,Scale#)

Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 29th Apr 2005 06:30
"unrecognised parameter at line 43"
line 43= "make object triangle Id,(Scale#/2),0,(Scale#/2),(Scale#/2),0,0-(Scale#/2),0,Scale#,0,"
delete the last coma, it gives a weird shape

please reply
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 29th Apr 2005 06:33
What?
It worked fine! It ran even with the comma! Oh well. Comma removed. It make a tetrahedron. Or has my geometry gone crazy? Tetrahedron is a triangle based pyramid isn't it?


ShadowCentaur 2
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Free Country USA
Posted: 29th Apr 2005 09:54
yes. a tetrahedron is a triangle based pyramid with all its faces equilateral triangles.

Truth suffers from too much analysis.
-Ancient Fremen Saying
ShadowCentaur 2
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Free Country USA
Posted: 29th Apr 2005 10:15
andrew, i tried your code, and it didnt quite work. firstly, the base appeares to be a square , not a triangle, so right now its a five sided die, not four. and the base also doesnt appear to be attatched to the rest of it at all. and your code wasn't commented so i couldnt quite figure out what was going on or what was going wrong.

Truth suffers from too much analysis.
-Ancient Fremen Saying
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 29th Apr 2005 17:21
Sorry just realised what I did! I'll edit it later.

Kelebrindae
21
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 29th Apr 2005 21:31
Here's a function to create a tetrahedron (or any other platonic solid except for the cube -> octahedron, isocahedron,dodecahedron).
Not very useful, but I've always liked the dodecahedron (yeah, I know, I'm weird ).

Just include "MakePlatonicSolid.dba" at the beginning of your code then use the function like this:
MakePlatonicSolid(Id,type$,size#)
ex: MakePlatonicSolid(1,"dodecahedron",5.0)

The code isn't very beautiful or optimized, but it works (and I miss the math knowledge to do better) .

You'll find the include file and a little prog to test it under the "download" button.

Ideas: memories of things which did not occur yet...

Attachments

Login to view attachments
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 30th Apr 2005 01:07
Well I fixed my code and it is in code snippets but Kelebrindae's answer is probably better so oh well!

Kelebrindae
21
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 30th Apr 2005 01:51 Edited at: 30th Apr 2005 01:55
@Andrew:
No, I don't think so, really.
Your solution is better for the tetrahedron, because the way you create the object is (probably) much faster than mine. Besides, my code is quite big, and not very elegant (I don't calculate the vertices' positions, I've stored them in "data" lines).

I've made it only because I have a nerdy fascination for Platonic Solids, and I wanted something to create them (especially dodecahedrons. Don't know why, but I love'em. Platonically speaking, of course ).

So cheer up, and keep up the good work!

Ideas: memories of things which did not occur yet...
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 30th Apr 2005 04:14
ShadowCentaur 2
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Free Country USA
Posted: 30th Apr 2005 05:13
oh yah! platonic solids rule! personally, the icosahedron is my favorite, twenty perfect triangles. that is still less polys than a sphere in db though i think . thanks for contributing, ill run it and test around with it. if we get it perfected we should put it into the codebase for all to use.

Truth suffers from too much analysis.
-Ancient Fremen Saying
ShadowCentaur 2
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Free Country USA
Posted: 30th Apr 2005 16:45
i would like to thank you again. ill include that in my game definately(and your name in the credits kelebrindae). i havent a clue how all that works but the figures look perfect. sweet function entirely. you really need to put it in codebase. really.

Truth suffers from too much analysis.
-Ancient Fremen Saying
Kelebrindae
21
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 3rd May 2005 23:22
@ShadowCentaur 2
Thanks for the very positive feedback; feels good!

Three small bug fixes:
- fixed a "for i=1 to n: .... :next anythingbutnoti" in UV mapping. Don't know why it worked anyway...
- fixed the case when you give something wrong as the name of the solid you want to create.
ex:MakePlatonicSolid(1,"schmurtzahedron",1.0)
- fixed errors "memblock 255 already exists" and "mesh 65534 already exists".

I've put the corrected code in the Codebase (and under the "download" button) with an enhanced text program.

Ideas: memories of things which did not occur yet...

Attachments

Login to view attachments
ShadowCentaur 2
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Free Country USA
Posted: 11th May 2005 11:26
@kelebrindae

one small thing though, i think its spelled "icosahedron" not "isocahedron"

Truth suffers from too much analysis.
-Ancient Fremen Saying
Kelebrindae
21
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 11th May 2005 21:28
Oops! You're right...

Here's the corrected version ("download" button).

Thanks, ShadowCentaur 2.

Ideas: memories of things which did not occur yet...

Attachments

Login to view attachments

Login to post a reply

Server time is: 2025-05-23 01:58:47
Your offset time is: 2025-05-23 01:58:47