This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-05-20 22:04:40

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Some complex math help

I'm trying to determine the distance to the edge of an ellipse with a given direction.

I have variables for both radii of the ellipse on the x and y scales, what I want to do is find the x and y on the ellipse when I have a given direction from the center so that I can calculate the distance at that given direction/point.

How would I do this?


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#2 2011-05-20 22:07:53

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Some complex math help

I think that can be achieved through simple sine and cosine trigonometry.

X= sin(direction)*xradius
Y=cos(direction)*yradius

EDIT:  This for portal sensing?  I know what you're up to  wink

Last edited by Kileymeister (2011-05-20 22:16:15)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#3 2011-05-20 22:15:08

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Some complex math help

Kileymeister wrote:

I think that can be achieved through simple sine and cosine trigonometry.

X= sin(direction)*xradius
Y=cos(direction)*yradius

Note:  This is using Scratch direction, not math direction.  For math direction, use "-1(direction-90)". (This note was actually kind of unnecessary, but whatever)

EDIT:  This for portal sensing?  I know what you're up to  wink

Yeah, I figured that out before you posted, but no, I'm not.  I'm actually working on a radial gradient effect.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#4 2011-05-20 23:10:27

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Some complex math help

hmm...my overall equation isn't working though.  Here's the design it produces, though it's different cuz I changed it so it's easier to see what happens:
http://i56.tinypic.com/oubpu0.jpg

My equation for the radial distance is the one messing up, I'm sure:

x=radius1*sin(atan(x-centerx/y-centery))
y=radius2*cos(atan(x-centerx/y-centery))

Then it uses the distance formula, distance=sqrt(x^2+y^2)

I've tried several variations of this, but they haven't worked.  Anyone got any ideas why it's not doing it right?


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#5 2011-05-21 09:31:49

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Some complex math help

Bump.  Anyone?

If you need more information to figure this out:

the color= color1-((color2-color1)*(distance/radial distance)

So basically, when the ratio of distances is small, it's more color1, but if it's higher, it's more color2.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#6 2011-05-21 10:59:40

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Some complex math help

Ok, so I think I figured out what it's doing, but I don't understand why.  It's drawing 2 circles around the focii of the ellipse.  So if I make the focii equal (i.e. circle) it's fine, but if the radii are different (and thus, the focii are different), it doesn't work.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

Board footer