homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam

The Geek Culture Forums


Post New Topic  New Poll  Post A Reply
my profile | directory login | | search | faq | forum home
  next oldest topic   next newest topic
» The Geek Culture Forums   » Other Geeky Stuff   » Ask a Geek!   » Trigonometry help: line corners

 - UBBFriend: Email this page to someone!    
Author Topic: Trigonometry help: line corners
maximile

SuperFan!
Member # 3446

Member Rated:
5
Icon 1 posted July 05, 2006 09:40      Profile for maximile   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
I've been messing around with OpenGL programming, and I came across a problem with its drawing of lines.

(I'm using a lot of pics here, so I guess lots of you won't see this. But I can't describe it properly with text.)

Say I fed it the following three points:

 -

If I ask it to render it as a line with a thickness, it'll do it as two rectangles, meaning that you get an ugly overlap. Reading around, it seems that this is a problem with OpenGL, and I can't find any help on the topic.

So I'm going to have to use triangles, and split the line like this:

 -

The problem I'm having is finding the two points I've marked with an arrow. The other points are easy enough - although I've had to use trig functions, and I get the feeling that there's a better way perhaps using just the gradient. Here's how I did it:

 -

To find the point marked 'a', I used thefollowing equation:

 -

The others can be found just as easily by swapping some signs and so on. So I'm only struggling with the two in the middle.

Can any of you trig gurus help me? I've tried and failed, and I couldn't even find anything on Google (although I didn't really know what to search for).

Here's another diagram, at a more acute angle. (Oops... I reused the letter a. Well, it's a different one this time.)

 -

So points a and b are the ones to find. I obviously need to find where the outside lines meet (for point a) and where the inside lines meet (for point b). But I can't work out how to express this in terms of the three points from the first diagram.

Any help would be appreciated, as ever. Feel free to tell me I'm stupid, or that I've missed something obvious, or that the question doesn't make sense.

Posts: 1085 | From: London, UK (Powys, UK in hols) | Registered: Feb 2005  |  IP: Logged
TheMoMan
BlabberMouth, a Blabber Odyssey
Member # 1659

Member Rated:
4
Icon 1 posted July 05, 2006 10:43      Profile for TheMoMan         Edit/Delete Post   Reply With Quote 
maximile________________________I used to think I was a geometry wizz untill your problem, now I am going huh. Are you looking for the third line from three ordered points? a(x,y) b(x,y) c(x,y) if so there should be help on the web, as to programing to find the line I would be lost.

--------------------
Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety.


Benjamin Franklin,

Posts: 5836 | From: Just South of the Huron National Forest, in the water shed of the Rifle River | Registered: Sep 2002  |  IP: Logged
Metasquares
Highlie
Member # 4441

Member Rated:
5
Icon 1 posted July 05, 2006 11:38      Profile for Metasquares   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
I understand what you're trying to do, but I'm having a hard time interpreting the diagrams.

Theta's the angle between something and the X-axis, but what? It looks like it's a point midway between (x,y) and (x1,y1).

Also, the images you're drawing look 3D - it makes it confusing, since it looks like there's a Z axis. Since you're just dealing with a 2D triangle, it may help to draw the diagrams in 2D.

Posts: 664 | From: Morganville, NJ | Registered: Oct 2005  |  IP: Logged
canadiangeek
Geek
Member # 4946

Member Rated:
3
Icon 1 posted July 05, 2006 18:28      Profile for canadiangeek     Send New Private Message       Edit/Delete Post   Reply With Quote 
Max,
I think I understand what you're trying to do... but am currently doing a lab write-up. While, under normal circumstances, I'd happily use this as an excuse to procrastinate, I just don't have time (I think this'd be a page or so of algebra).

If someone else hasn't solved it when I get back from my lectures tomorrow, I'll try and solve it for you.

--------------------
-whenever you build something that's idiotproof, someone comes out with a better idiot-

Posts: 161 | From: Nova Scotia | Registered: Mar 2006  |  IP: Logged
Ivan
Alpha Geek
Member # 2622

Member Rated:
3
Icon 1 posted July 05, 2006 23:30      Profile for Ivan   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
This shoudl work, but it's early in the morning and i could be dead wrong.

find equation of line connecting (x1,y1) and a. find equation of perpindicular line at a. (Call this equation x)

find equation of line connecting (x2,y2) and (x2+t, y2+t) (assuming they're vertically collinear, which it looks like they are). then find the equation of the line perpindicular to that at point (x2+t, y2+t). (call this equation y)

set x=y to find their intersecting coordinates.

do the same to find the inside corner, but use the other points in finding your equations.

lengthy and roundabout, but it should work.

Posts: 269 | From: North Carolina | Registered: Mar 2004  |  IP: Logged
maximile

SuperFan!
Member # 3446

Member Rated:
5
Icon 1 posted July 06, 2006 03:39      Profile for maximile   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
Thanks for the interest, everyone.

Are you looking for the third line from three ordered points? a(x,y) b(x,y) c(x,y) if so there should be help on the web, as to programing to find the line I would be lost.

No, I'm just looking for an equation that will get the marked points for given values of x, y, x1 etc. Programming shouldn't come into it; I'm happy to convert an equation into code myself.

Theta's the angle between something and the X-axis, but what? It looks like it's a point midway between (x,y) and (x1,y1).

Theta is the angle between the x-axis and the line (x1,y1) to (x,y). It doesn't matter whether it's midway or not. I work out theta just using an inverse tangens (modified to work properly in four quadrants).

Also, the images you're drawing look 3D - it makes it confusing, since it looks like there's a Z axis. Since you're just dealing with a 2D triangle, it may help to draw the diagrams in 2D.

True... here's a (hopefully) clearer version.

 -

find equation of line connecting (x2,y2) and (x2+t, y2+t) (assuming they're vertically collinear, which it looks like they are). then find the equation of the line perpindicular to that at point (x2+t, y2+t). (call this equation y)

Thanks for the help. However, the solution needs to work with any three points, not just the current ones. Also, I don't know how to find the equation of a line.

What I really need is something like I have for finding point a - an equation in which the x and y values are isolated, and expressed in terms of the x and y values of the other three points. Or theta, or any angle between any of the points, because those are easy to work out.

Feel free to ask for more information if any of you are still interested but confused, and thanks again for the help so far.

Posts: 1085 | From: London, UK (Powys, UK in hols) | Registered: Feb 2005  |  IP: Logged
Metasquares
Highlie
Member # 4441

Member Rated:
5
Icon 1 posted July 06, 2006 05:52      Profile for Metasquares   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
I think I may have figured it out.

Let's assume for a moment that theta is 0. If this is the case, you'll just get a rectangle with a width of t.

Point (x,y) will be located at the midpoint between unknown points a and b. Since the length of this side is t, that means the vertical distance between a or b and y is t / 2. In this case, they also lie on the same x-coordinate.

So a will have the coordinates (x, y - t / 2) and b will have the coordinates (x, y + t / 2) before rotation.

Now we stop assuming the value of theta and apply a rotation transformation. The formula for this is x' = x cos(theta) + y sin(theta), y' = -x sin(theta) + y cos(theta).

So for point a, we should get (x cos(theta) + (y - t/2) sin(theta), -x sin(theta) + (y - t / 2) cos(theta)).

Point b is the same save for flipped signs before the t / 2 terms.

Posts: 664 | From: Morganville, NJ | Registered: Oct 2005  |  IP: Logged
Ivan
Alpha Geek
Member # 2622

Member Rated:
3
Icon 1 posted July 06, 2006 09:31      Profile for Ivan   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
quote:
Thanks for the help. However, the solution needs to work with any three points, not just the current ones. Also, I don't know how to find the equation of a line.
y= (y2-y1)/(x2-x1)

but uh, other than that i choose not to help you, because that requires a little more thought than i feel like investing in this. sorry.

Posts: 269 | From: North Carolina | Registered: Mar 2004  |  IP: Logged
Metasquares
Highlie
Member # 4441

Member Rated:
5
Icon 1 posted July 06, 2006 09:54      Profile for Metasquares   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
quote:
Originally posted by Ivan:
y= (y2-y1)/(x2-x1)

You mean m=(y2-y1)/(x2-x1). You still need to find the y-intercept to get the equation of the line.
Posts: 664 | From: Morganville, NJ | Registered: Oct 2005  |  IP: Logged
maximile

SuperFan!
Member # 3446

Member Rated:
5
Icon 1 posted July 06, 2006 12:06      Profile for maximile   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
Thanks everyone - I'll try this tonight, and if I'm successful I'll let you know.
Posts: 1085 | From: London, UK (Powys, UK in hols) | Registered: Feb 2005  |  IP: Logged
Ivan
Alpha Geek
Member # 2622

Member Rated:
3
Icon 1 posted July 06, 2006 12:20      Profile for Ivan   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
quote:
Originally posted by Metasquares:
quote:
Originally posted by Ivan:
y= (y2-y1)/(x2-x1)

You mean m=(y2-y1)/(x2-x1). You still need to find the y-intercept to get the equation of the line.
You're absolutely right. that's what I get for posting withing a minute of waking up. [Razz]
Posts: 269 | From: North Carolina | Registered: Mar 2004  |  IP: Logged
maybe.logic
Alpha Geek
Member # 5014

Member Rated:
3
Icon 1 posted July 08, 2006 02:21      Profile for maybe.logic     Send New Private Message       Edit/Delete Post   Reply With Quote 
quote:
Originally posted by Ivan:
quote:
Originally posted by Metasquares:
quote:
Originally posted by Ivan:
y= (y2-y1)/(x2-x1)

You mean m=(y2-y1)/(x2-x1). You still need to find the y-intercept to get the equation of the line.
You're absolutely right. that's what I get for posting withing a minute of waking up. [Razz]
[rant]
everytime sombody makes an error with maths/physics it is always an exuse along simillar lines...

Oh I jst woke up, Oh it was really late, Oh i was so pissed... and it goes on.

[/rant]

I'm sure I have done it from time to time as well, i just think its funny.

Posts: 345 | Registered: Mar 2006  |  IP: Logged


All times are Eastern Time  
Post New Topic  New Poll  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:

Contact Us | Geek Culture Home Page

2015 Geek Culture

Powered by Infopop Corporation
UBB.classicTM 6.4.0



homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam