Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Benjames · May 10, 2015 at 07:33 PM · vector3quaterniondirectionproceduraltree

Setting up point sets for a procedural tree

While creating a set of lines.

                     points=new Vector3[num];
                 points[0]=new Vector3(0,0,0);
                 for(int tt=1; tt<num; tt++)
                 {
                     d_a=Quaternion.AngleAxis(seed*num*tt*13%(39+tt),Vector3.up)*d_a;
                     direction=Quaternion.AngleAxis(seed*num*tt*(tt*13%39)%(15+tt),d_a)*direction;
                     dirs[tt-1]=direction;
                     points[tt]=points[tt-1]+(direction*(num/20f));
                     Debug.DrawLine(points[tt],points[tt-1],Color.blue,91);
                 }

a set of points form a ring around each point on the line set

         for(int tt=0; tt<num; tt++)
         {    
             int it=num-tt;
             it=Mathf.RoundToInt(it/3)*3;
             if(it==0 && tt!=num-1)
             {
                 it=3;
             }
             if(tt==num-1)
             {
                 it=1;
             }
             vert_at_point[tt]=it;
             for(int i=0; i<it; i++)
             {
                 Quaternion q=Quaternion.AngleAxis((360f/(it))*i,dirs[tt]);
                 Vector3 dd=q*Vector3.forward;
                 dd=dd.normalized;
                 int ttt=tt;
                 if(ttt<3)
                 {
                     ttt=3;
                 }
                 dd*=((num-ttt)/(float)num)*(num/10f);
             
                 Vector3 castfrom=points[tt]+dd;//+(dirs[tt]);//Vector3.Normalize(dd));
                 Debug.DrawLine(castfrom,castfrom+(Vector3.up*.1f),Color.red,91);
                 trees[slot].vertices.Add(castfrom);
             }
         } 

the points for the rings are put in a list for vertices points

alt text

OR

alt text

The problem is the more of an angle the ring is the smaller it is, as is the direction vector doesn't == 1 total, I'm not sure how to fix this, any speculative comments appreciated.

scr.png (86.5 kB)
untitled.png (4.8 kB)
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 Benjames · May 10, 2015 at 07:41 PM 0
Share

One thing I noticed is the center of the ring is offset from the point.

I did a test and the direction vectors are all approximately 1 in distance, so the angle is off.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Benjames · May 10, 2015 at 09:19 PM

So I looked up how to find a perpendicular vector http://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html

Then modified my code a little. It took a little over an hour to figure out.

             for(int i=0; i<it; i++)
             {
                 Vector3 qq=Vector3.Cross(dirs[tt],Vector3.up);//dirs[tt]-Vector3.Project(dirs[tt],Vector3.up);//Quaternion.AngleAxis(90,dirs[tt])*dirs[tt];
                 qq=qq.normalized;
                 Quaternion q=Quaternion.AngleAxis((360f/(it))*i,dirs[tt]);
                 Vector3 dd=q*qq;

                 int ttt=tt;
                 if(ttt<3)
                 {
                     ttt=3;
                 }
                 dd*=((num-ttt)/(float)num)*(num/10f);
             
                 Vector3 castfrom=points[tt]+dd;//+(dirs[tt]);//Vector3.Normalize(dd));
                 Debug.DrawLine(castfrom,castfrom+(Vector3.up*.1f),Color.red,91);
                 trees[slot].vertices.Add(castfrom);
             }


alt text

Also if anyone cares here is what I was trying to accomplish.

alt text

alt text


tree.png (180.8 kB)
scr.png (70.9 kB)
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Snap a direction vector 1 Answer

Quaternion amount/value of rotation? 2 Answers

How to calculate order of directions relative to world forward around point? 1 Answer

3D nested Turret Prefab Rotation 1 Answer

Rotate vector3 relative to another vector3 1 Answer


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