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 boysenberry · May 11, 2015 at 05:50 PM · ellipse

Unity best practices for determining if something is inside or outside the circumference of an ellipse

Hello,

I am try to setup an asset that needs to identify regions for biome selection. I would like to do this using ellipses so I can make an island of sorts using procedural code. Basically I need a function that will determine if a 2D point is inside our outside the circumference of an ellipses given 2 sets of x/y coordinates. The first set would determine the dimensions of the ellipse. The second set would be used to determine if the point was either inside or outside the ellipse returning Boolean. I am pretty new to using geometry in a video game setting and am researching the math. I figured there were tons of situations where the same formulas/algorithms would be useful, e.g. target ranges, etc. I am guessing if there is not already an established way to do this easily, there are supportive libraries I am just not familiar with that might help with some of the heavier math.

Here are some of the articles I've been going from to try to get a handle on what I need to do so far: http://en.wikipedia.org/wiki/Ellipse#Circumference

http://en.wikipedia.org/wiki/Elliptic_integral#Complete_elliptic_integral_of_the_second_kind

http://en.wikipedia.org/wiki/Circumference

http://www.mathopenref.com/coordparamellipse.html

http://www.mathopenref.com/coordgeneralellipse.html

http://www.mathopenref.com/coordcirclealgorithm.html

And just because I thought these would be interesting to do the same with:

http://en.wikipedia.org/wiki/Hypotrochoid

http://en.wikipedia.org/wiki/Epitrochoid

It would seem to me, plotting points along the edge of an ellipse and filling the area of an ellipse are easier (or maybe just done more often) than determining the circumference of an ellipse. Am I mistaken?

Can anyone help with how I can determine inside vs the outside of an ellipse. And as a bonus maybe explain how I can even expand on that to include procedurally generated shapes like an epitrochoid? (That would make for much more realistic shorelines, ranges, etc...)

Thank you in advance, Boysenberry Payne

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 Dblfstr · May 12, 2015 at 06:27 PM 0
Share

Have you looked at Physics.OverLapSphere or Physcis.CapsuleCast

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Owen-Reynolds · May 12, 2015 at 04:05 PM

"Best practices" in Unity is not to use an ellipse. There's no built-in collider for it, the math is harder, and it's just a game. We'd use a capsule collider or something. A big part of making a game is identifying places where you can tweak/downgrade the specification just a little, in return for 80% less work.

So that's why you don't see much about odd shapes here.

If you really need an ellipse (sounds like you do): you could just do the math `(ax^2+by^2

Comment
Add comment · Show 1 · 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 boysenberry · May 12, 2015 at 06:19 PM 0
Share

I started down that path last night. I have a tendency to make things a little hard than need be, thus the question.

I don't $$anonymous$$d going the collider route at all, I am just not sure how to implement it. I was thinking maybe raycasting on a sprite similar to collusion detection in 2D games.

The issue for me is I am getting a coordinate for a voxel in world space and I need to be able to know what biome the coordinate belongs to. I thought the most straight forward approach would be using concentric oblong rings to deter$$anonymous$$e each of the main biomes, e.g. beach leading to mountains then to the valley within.

How would I do this with colliders, make them invisible in world space then hit testing using raycasting (or something else) to deter$$anonymous$$e the boundaries of each biome/collider?

PS for the math portion (ax^2+by^2) a and b are the coordinates to deter$$anonymous$$e whether a point is inside or outside, and x and y are for deter$$anonymous$$ing the size of the ellipse, right?

avatar image
0

Answer by boysenberry · May 18, 2015 at 02:08 PM

So, the answer for me came in the form of a splatmap. Basically I make a ellipse the dimensions I want in Photoshop or GIMP (or what ever image app you use) import it into Unity and then check the sprite out using Texture2D and its methods, i.e. ellipse.GetPixel(x,y).r (using a white ellipse here). If the value is greater than 0 than I know I am in the ellipse.

The colliders weren't doing it for me because none of this is happening in the scene, but is to effect what happens in the scene.

Also the ax^2+by^2 formula works only for plotting or placing things along the edge of a ellipse, but isn't really helpful when it comes to telling whether something is on one side or the other of that edge.

I hope this makes it easier for someone after me. I couldn't find an answer for it in the forums...

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 Owen-Reynolds · May 18, 2015 at 03:06 PM 1
Share

?? I think the problem is you're thinking of this as a Unity issue, when it's really just math. If you focused on the trig, you'd be able to look up how ax^2+bx^2=c is exactly used to check in/out (plug in x/y from the center, and check the result is less than / greater than c.) Likewise, a 2D array of bools would probably work better than a splatmap/texture (which uses 4 ints for each yes/no.)

avatar image boysenberry · May 18, 2015 at 06:48 PM 0
Share

You're absolutely right. I missed the =c part on your initial post and wasn't sure if it meant that. If I use the x/y from 0 of the ellipse, then feed a/b for the x/y I am testing with what value of c will be in vs out of the circumference. That's the part I am not sure of.

As for the 2D array of bools, that will probably be what I end of working with, but outside of using an image to generate those values I am not sure how to derive them.

Unfortunately, and the reason for asking the question, my trig is rather weak. I know how to look it up, but translating the math notation in to what I know syntactically, well lets just say up to now I haven't needed it much.

avatar image Owen-Reynolds · May 18, 2015 at 08:21 PM 1
Share

HT$$anonymous$$L did eat the last pat of my answer (I think there was a less-than sign. Odd, since it was there in the preview.)

To repeat myself, you can usually make slight changes in the rules, and most people play to their strengths. If you aren't so great at trig and such, and decide to go with a trig-heavy approach, you just volunteered yourself to google a bunch of High School trig.

You wrote that you "would like to" do it using ellipses. So, I assume it's not a firm biome rule. If what you have works and is fast enough, you're done. If not, maybe a good time to rethink the approach, not that you've explored using ellipses.

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

21 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

Related Questions

Move Object allong an ellipsoid path 1 Answer

Calculate a spline with start- and endpos 0 Answers

Drawing a moving objects trajectory 4 Answers

Constant speed on elliptical path 0 Answers

Ho do I move an object on an elliptical path? 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