• 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 Bobfan · Nov 10, 2013 at 06:10 PM · mathpointcircleradius

Find distance around a circle, from center point and another point

I am having trouble creating a circle in 3d space, and fining a point along it. So if I have a circle with center point C, and a point on the circle R, would it be possible to find a point a specific distance along the circle from R? I don't necessarily need the code to do it, but just assistance on the math.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by robertbu · Nov 10, 2013 at 06:26 PM

There are an infinite number of circles that have a center and a point in common, so you need to specify one specific circle. The code below uses the axis (normal) to the circle. The polarity of the axis will determine which direction to move along the circle. It solves your problem by creating a vector between the center and the point. It then calculates the angle by using the fraction of the circumference the distance travels. An AngleAxis() rotation generates the point. The code is untested:

 function  FindPoint(center : Vector3, r : Vector3, dist : float, axis : Vector3) : Vector3 {
     var v3 = r - center;
     var circumference = 2.0 * Mathf.PI * v3.magnitude;
     var angle = dist / circumference * 360.0;
     v3 = Quaternion.AngleAxis(angle, axis) * v3;
     return v3 + center;
 }
Comment
Add comment · Show 2 · 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 Bobfan · Nov 10, 2013 at 10:49 PM 0
Share

I'll try it out, and fix it if it doesn't work. Thanks.

avatar image Mythran · Feb 27, 2017 at 10:27 PM 0
Share

Awsome!! Thank you very much!

avatar image
0

Answer by shieldgenerator7 · Dec 06, 2020 at 10:08 AM

Here's a modified version of @robertbu 's answer:

 public static Vector2 travelAlongCircle(this Vector2 pos, Vector2 center, float distance)
 {
     Vector3 axis = Vector3.back;
     Vector2 dir = pos - center;
     float circumference = 2.0f * Mathf.PI * dir.magnitude;
     float angle = distance / circumference * 360.0f;
     dir = Quaternion.AngleAxis(angle, axis) * dir;
     return dir + center;
 }

You can call it like this:

 Vector2 position = transform.position;
 Vector2 center = Vector2.zero;
 float distance = 10;
 transform.position = position.travelAlongCircle(center, distance);

This version is handy because it is an extension method of the Vector2 class.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Maths: Given a point on a circle and a fixed length line. Find the next closest point on the circle. 2 Answers

Programmatically specifying a random point in an arc in front of the player 1 Answer

Circular motion via the mathematical circle equation? 4 Answers

How to use Handles.DrawSolidArc() in execute mode 0 Answers

GUI Coordinate System 0 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