Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 saporter · Mar 28, 2015 at 01:54 AM · tangent

Calculating an angle to rotate some tangent around an axis

I don't even know how to Google my question to find an answer so I drew a picture, below. I have a weapon who's Field of Fire I'm trying to rotate so a target comes into view.

I've previously been calculating Theta (below) from my weapon's exit aperture and rotating my parent GameObject by that angle, Theta.
alt text

After drawing it out, I now understand that's not enough since my exit aperture is on the outside radius of (what is effectively) a circle and I always end up with some "error" Theta' (prime).

I would love a math wiz to help me calculate the angle my circle needs to rotate in order for a target to come into my field of view. My domain is 2D - everything is on the same y-plane. The center of the circle, target (x,y), radius, exit aperture (x,y) and min/max directions are all known.

tangent-around-axis.jpg (152.7 kB)
Comment
Add comment · Show 11
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 Glurth · Mar 28, 2015 at 01:42 PM 0
Share

ok you have the exitAperture, which I'll assume is your starting angle/vector. And you have your target vector. To find the angle between these two vectors you can use the Vector2.Angle function (https://docs.unity3d.com/ScriptReference/Vector2.Angle.html)

angleBetweenApetureAndTarget = Vector2.Angle(exitApertureVector, targetVector)

Is this what you were looking for?

avatar image saporter · Mar 28, 2015 at 02:41 PM 0
Share

Not quite. I'm using that now which gives me angle Theta in the drawing. And that would work if I were pivoting at the exitAperture. But I'm pivoting at some other point r (radius) units away, leaving me the problem illustrated above.

avatar image Glurth · Mar 28, 2015 at 02:52 PM 0
Share

Ah- I was assu$$anonymous$$g center was (0,0,0) So, it sounds like you want to know the angle between:

(exitApertureVector - center) (vector from center to exit aperture)

and

(targetVector - center) (vector from center to target)

Note, when center IS (0,0,0), we have the same results I assumed earlier.

OR, are you are looking for the angle between: the vector from aperture to target: targetVector - exitApertureVector and the vector from center to aperture: exitApertureVector - center (from your drawing it looks like this one is what you want, but I don't see why. I don't think this is the right angle to rotate the circle to make the aperture point at the target.)

avatar image lordlycastle · Mar 28, 2015 at 02:55 PM 0
Share

I’m kinda lost, no clue what’s happening in the image above, but from the sound of it you are trying to find the $$anonymous$$imum angle a object (weapon) should rotate so that a point, previously out of it’s FOV, is visible. Am I correct?

avatar image saporter · Mar 28, 2015 at 03:22 PM 0
Share

Lordlycastle you are exactly correct.

Glurth, your first scenario is close (exitA - center to target - center), except I want the $$anonymous$$imum angle I need to rotate, as lordly points out.

Show more comments

1 Reply

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

Answer by Glurth · Mar 29, 2015 at 08:06 PM

Ah, that clears things up a bit!

alt text

consider the grey triangle: if we can solve for that bottom angle we can simply use angle addition/subtraction to get how far to rotate.

For the grey triangle we have:

the leftmost side has length of (target-center).magnitude

the lower right side has length of the (gunsposition-center).magnitude

we also have one angle for the triangle, a constant variation on the FOF angle: 180-(FOF/2)

With this information we should be able to solve the triangle completely. http://www.mathsisfun.com/algebra/trig-solving-ssa-triangles.html

You should only need the first step though, using the law of sines: I got...

 TopAngle = ArcSin(  Sin(180-FOF/2)*(gun-center).magnitude/(target-center).magnitude  )
 BottomAngle = 180-(TopAngle+(180-FoF/2));  //angles add up to 180 for triangles



question-diag.png (30.6 kB)
Comment
Add comment · Show 5 · 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 saporter · Mar 30, 2015 at 02:42 PM 1
Share

Thanks again! Your picture didn't come through on this post...

avatar image Glurth · Mar 30, 2015 at 03:34 PM 0
Share

Hmm, I see the picture, in the answer, looks ok- anyone else having trouble seeing it?

avatar image nikich0601 · Apr 01, 2015 at 12:34 PM 0
Share

I don't see this picture too

avatar image Glurth · Apr 03, 2015 at 10:57 PM 0
Share

I have just re-uploaded it, hope it's showing up ok now.

avatar image saporter · Apr 03, 2015 at 11:59 PM 0
Share

Yup I see it

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I set the tangents of Keyframes in an AnimationCurve through scripting? 1 Answer

Weird Animation clip curves tangents 1 Answer

How can I set all of my animation keyframes tangents to become right angles? 2 Answers

Normal mapping mirrored UVs? 2 Answers

"Shader wants tangents, but the mesh doesn't have them" 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