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 CaptainChristian · Apr 14, 2013 at 12:58 PM · arccone

Find Evenly Spaced Samples Over An Aribtrary Arc

I would like to create a fan located at a specific vector and point at another vector. Then a number of samples should scatter evenly spaced and evenly distributed over that arc. How do I find these samples? I know all paramters (length of the cone, angle, source vector and target, and number of samples).

Any help/hint would be greatly appreciated.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Apr 14, 2013 at 06:01 PM

  1. Create two vectors going from the point of the fan to each end of the fan.

  2. Use Vector2.Angle() to figure out the angle between the two vectors.

  3. Calculate the angle of rotation to place each item. If you have n items to place, your delta angle will be total angle divided by n-1.

  4. Figure out the axis of rotation. If the two vectors are arbitrary, you can use Vector3.Cross() to calculate the axis.

  5. Create a rotation representing the delta_angle rotation around using Quaternon.AngleAxis() using the axis from step 4.

  6. To actually place the items, start with the first vector from step 1 and in a loop:

    pos = fan_point + qRot * v3Start;

...where 'fan_point' is the point of the fan, qRot is the rotation calculated in step 5, and v3Start the first vector from step 1,

Comment
Add comment · Show 3 · 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
avatar image CaptainChristian · Apr 15, 2013 at 11:15 AM 0
Share

Accoring to this I will do the following: Find the angle of the fan: For that I use a given vector3. Then I calculate the angle of a 2d vector using the x and z coordinates of that given vector via $$anonymous$$athf.Atan2(vectorDirection.z, vectorDirection.x).

Then I create two new vectors with polar offset using the lenth of the cone (or distance between origin and new point), a highest angle to the left and to the right and fill the remaining samples inbetween according to each individual angle between the two edges.

After that I calculate the axis via cross product, using the two edges translated to 3d via Vector3.Set(vecLeftEdge.x, dunno, vecLeftEdge.z) and Vector3.Set(vecRightEdge.x, dunno, vecRightEdge.z) and then proceed with calculating the rotation in 3d and following through the loop.

Do I miss something or is this correct?

avatar image robertbu · Apr 15, 2013 at 02:23 PM 0
Share

You asked for an arbitrary arc which to me meant any two vectors in 3D space. ATan2() will only work if your objects are aligned with a plane using two axes. I don't know the form of your inputs, but here is a bit of sample code for the above steps:

 using UnityEngine;
 using System.Collections;
 
 public class FanPlacement : $$anonymous$$onoBehaviour {
 
     public Vector3 v3Pivot = new Vector3(0.0f, -.5f, 0.0f);  // World point of pivot
     public Vector3 v3End1  = new Vector3(-2.0f, 2.0f, 0.0f); // World point of left end of fan
     public Vector3 v3End2 = new Vector3(2.0f, 2.0f, 0.0f);  // World point of right end of fan
     
     public int count = 5; // number of items to place
 
     void Start () {
         Vector3 v3A = v3End1 - v3Pivot;  // Step 1
         Vector3 v3B = v3End2 - v3Pivot;
         
         float total_angle = Vector3.Angle (v3A, v3B); // Step 2 
         
         float delta_angle = total_angle / (float)(count - 1); // Step 3
         
         Vector3 axis = Vector3.Cross(v3A, v3B);  // Step 4
         
         Quaternion q = Quaternion.AngleAxis (delta_angle, axis);  // Step 5
         
         for (int i = 0; i < count; i++) {
             GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
             
             go.transform.position = v3Pivot + v3A;  // Step 6
             v3A = q * v3A;
         }
     }
 }

avatar image CaptainChristian · Apr 15, 2013 at 03:54 PM 0
Share

Thank you for the sample code. I will use it to solve this issue.

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

11 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

Related Questions

Moving player in an arc, from startPoint to endPoint 2 Answers

Vector3.Slerp - is there a way to force an arc? 0 Answers

Moving the player in a ballistic trajectory in 3D 0 Answers

how to make a obduction beam in unity? 1 Answer

arc object's position using sin 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