Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Apr 03, 2018 at 02:48 PM by gsolra for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by gsolra · Mar 07, 2018 at 11:27 AM · transformvector3infinite

infinite vector 3 generate method for Sierpinski Tetrahedron C#,infinite vector 3 generate method for a Sierpinski tetrahedron?

sierpinski tetrahedron in unity

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Mar 07, 2018 at 12:53 PM 1
Share

Level of coding will only help with implementation. You might want to get the problem worked out on paper first, then start worrying about how to type it.

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Mar 07, 2018 at 01:43 PM

It's a recursive algorithm which of course can be carried out linearly as well. The only thing you have to create is creating 4 tetrahedron out of the bigger one. That's all you need. So you start with a single tetrahedron and apply your "conversion" to every tetrahedron (at the first step there's only 1).


To do this it's actually easier to represent your tetrahedron "logically". For example using the center point and a "size" variable. You would calculate 4 new center positions based on the given center and the size. Just cut the size in half. If you do the same for the new 4 center positions you get again 4 new ones for each old one. So you end up with 16 center points.


You should seperate the "meshing" from the actual subdivision. Just run the algorithm as often as you want and when you reached your desired level run the mesher on the tetrahedron centers + size.


I quickly created a class that can build such a construct:

 public class STetrahedron
 {
     static float s8_9 = Mathf.Sqrt(8f/9f);
     static float s2_9 = Mathf.Sqrt(2f / 9f);
     static float s2_3 = Mathf.Sqrt(2f / 3f);
     static float f1_3 = 1f / 3f;
     public float Size = 1;
     public List<Vector3> centers = new List<Vector3>();
     public STetrahedron Subdivide()
     {
         var result = new STetrahedron();
         float s = result.Size = Size*0.5f;
         if (centers.Count == 0)
             centers.Add(Vector3.zero);
         foreach(var c in centers)
         {
             result.centers.Add(c + new Vector3(0, s, 0));
             result.centers.Add(c + new Vector3(-s2_3*s, -f1_3 * s, -s2_9*s));
             result.centers.Add(c + new Vector3( s2_3*s, -f1_3 * s, -s2_9*s));
             result.centers.Add(c + new Vector3(0, -f1_3 * s, s8_9*s));
         }
         return result;
     }
     public STetrahedron Subdivide(int aCount)
     {
         var res = this;
         for (int i = 0; i < aCount; i++)
             res = res.Subdivide();
         return res;
     }
     public Mesh CreateMesh()
     {
         Vector3[] vertices = new Vector3[centers.Count*12];
         Vector3[] normals = new Vector3[vertices.Length];
         float s = Size;
         int i = 0;
         foreach (var c in centers)
         {
             var v0 = c + new Vector3(0, s, 0);
             var v1 = c + new Vector3(-s2_3 * s, -f1_3 * s, -s2_9 * s);
             var v2 = c + new Vector3(s2_3 * s, -f1_3 * s, -s2_9 * s);
             var v3 = c + new Vector3(0, -f1_3 * s, s8_9 * s);
 
             normals[i] = normals[i + 1] = normals[i + 2] = Vector3.Cross(v2 - v0, v1 - v0).normalized;
             vertices[i++] = v0; vertices[i++] = v2; vertices[i++] = v1;
 
             normals[i] = normals[i + 1] = normals[i + 2] = Vector3.Cross(v1 - v0, v3 - v0).normalized;
             vertices[i++] = v0; vertices[i++] = v1; vertices[i++] = v3;
 
             normals[i] = normals[i + 1] = normals[i + 2] = Vector3.Cross(v3 - v0, v2 - v0).normalized;
             vertices[i++] = v0; vertices[i++] = v3; vertices[i++] = v2;
 
             normals[i] = normals[i + 1] = normals[i + 2] = Vector3.down;
             vertices[i++] = v1; vertices[i++] = v2; vertices[i++] = v3;
         }
         int[] triangles = new int[vertices.Length];
         for (int n = 0; n < triangles.Length; n++)
             triangles[n] = n;
         var m = new Mesh();
         m.vertices = vertices;
         m.normals = normals;
         m.triangles = triangles;
         m.RecalculateBounds();
         return m;
     }
 }

You just create an instance of that class and call subdivide which will return a subdivided version of the given structure. When done call CreateMesh to get a mesh from it. Note that at subdivision level 6 the resulting mesh would already have nearly 50k vertices. The result going from 0 to lvl 6 looks like this:

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer

Need help getting randomly moving particles to head to the nearest of 4 coordinates. 1 Answer

InverseTransformPoint() help 0 Answers

Set variable to position of collided object. 0 Answers

Vector 3 moving to certain place? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges