• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Draw me a Hyperbola

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can draw an ellipse with Ellipse2D, a parabola with QuadCurve2D
but to make my conic section collection complete I'm trying to draw a hyperbola.

I've googled it to death, java docs have an aversion to using geometric nomenclature--in QuadCurve2D not one word about parabola !!!
Some applets bring up the curve but don't betray how they got it.

Shall I write my own code???

Just a class name would make my holidays.
 
Dave Elwood
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh what the heck.
I've found that about six inches of hyperbola can be effectively created with an array of 50 Line2D objects.
Really wasn't hard at all.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the API docs for QuadCurve makes me think of having to fill in a 47-page contract just to get a train ticket. So how did you use that to draw a parabola?
 
Dave Elwood
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doing the parabola was the easiest of the three.

You need three points on the canvas p1, p2 and ptcontrol to depict it with QuadCurve2D.
a line from p1 to ptcontrol and a line from p2 to ptcontrol are two opposing tangents on the parabola. It makes an isoscles triangle.

And it turns out that if the focus is at (0,0)
and p1 is at, just for fun, (-3, +4) then I put the p2 point at (-3, -4).
This will put the p1 point at a distance of 5 from the focus ( a [3, 4, 5] right triangle.)

Now the real fun starts :

if you make a line from the focus to p1 and then make a line depicting the tangent, then let the angle between the two lines be "F". A line from p1 to ptcontrol also (!) makes the angle F with the x axis. This is because the distance from the focus to the ptcontrol is also 5 !!! Same as the distance from p1 to the focus. So there is another isoscles triangle.

And the best of all is that this angle F is half of the angle formed with the x axis by the [3, 4, 5] triangle. Arctan 3/5 = 2F.

Further points along the parabola can be predicted because the distance from the focus to the vertex (tip of the curve) is = d = (5 - 3)/2 and also the distance from the vertex to the directerix line. And the distance from the directerix to the ptcontrol is 3 (from the 3, 4, 5 triangle). So if p1 is (-3, 4) and p2 is (-3, -4) then ptcontrol is (-3 + 2d + 2*3, 0) = (5, 0).

From this I have the formula for the parabola x = -(y**2)/4d + d;
It is symetrical along the x axis and opens to the left.

If you differentiate the formula for the parabola then you have dy/dx and there is the slope of the tangent.

It all hangs together.

And thereby one can also determine if a "tilted" parabola is being depicted, and determine the angle of tilt.

I have this in an app where the satellite is at point p1, the gravity source is at the focus and the velocity vector is of course, the tangent. I start with the distance to the gravity source known (here 5), the angle between the satellite to gravity source line and the velocity vector is also known (here F).

And the rest falls into place nicely.

With a hyperbola it's kinkier. With a hyperbola you always have twins. So which one is the curve? I'm almost there.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Looking at the API docs for QuadCurve makes me think of having to fill in a 47-page contract just to get a train ticket. So how did you use that to draw a parabola?



Dave Elwood wrote:[Everything you always wanted to know about drawing a parabola but were afraid to ask].





On a more serious note, Dave: and thank you for sharing your specialized knowledge. Not many members here would have taken the time to explain in detail.
 
Dave Elwood
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Darryl.

I'm a 61 year old English teacher in Germany. Have you ever met a teacher who wasn't ready to 'show you the way?'
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Elwood wrote:Thanks Darryl.

I'm a 61 year old English teacher in Germany. Have you ever met a teacher who wasn't ready to 'show you the way?'


I'm a year younger than you, a retired Electrical engineer in India, and in the habit of posting hints that are as brief as possible
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic