Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Triangle Math <- Easy one?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cbx
Swordmaster

Canada
296 Posts

Posted - Jun 21 2004 :  4:55:21 PM  Show Profile  Visit cbx's Homepage  Send cbx an ICQ Message  Click to see cbx's MSN Messenger address  Send cbx a Yahoo! Message  Reply with Quote
OK I am trying to find the formula to find the length of 2 sides of a 2D triangle.

I already know what each of the 3 inner angles of the triangle are as well as the length of one side. So does anyone know how to calculate the length of the other 2 sides of the triangle? The formula must work on ANY type of triangle weather it be equilateral, isosceles, scalene or right-angled etc.

This is what I have. I have 2 points in 2D space. I know the X/Y location of each point. That is how I know what the distance of one side of the triangle is. Now each point is facing in a direction and because I know what direction each of the 2 points is facing I can calculate what each of the inner anges of the triangle are. Again that is how I know what the distance of one side of the triangle is. What I an trying to find is the formula to determin at what X/Y position the third point in the triangle is locate at. Now I can find this position if I can find the length of the 2nd or 3rd side of the triangle.

See the attached pic for what I am talking about...

Image Insert:



Even if I could find the length of one other side would be helpfull. Thanx.

Created by: X
http://www.createdbyx.com/

Edited by - cbx on Jun 22 2004 03:25:04 AM

masterbooda
Swordmaster

277 Posts

Posted - Jun 21 2004 :  5:03:30 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Are you trying to find the total length for the triangle? Because otherwise, couldn't you use the same formula to calculate every line of the triangle? Just input the points of that side... or is this not what you are asking?

This code will give you the distance between two points which is the same thing as length...

Public Function FindDistance(X1 as Single, Y1 as Single, X2 as Single, Y2 as Single) as Double
     FindDistance = Sqr((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1))  
End Function


DaBooda out...


DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 21 2004 :  5:34:48 PM  Show Profile  Reply with Quote
hehe... Law of Sines (and I thought I'd never have to use it after trig...). Okay, basically givin triangle ABC(excuse the awful ASCII art ):

A
|\
|.\
|..\
B--C

where the side opposite the angles are a,b, and c (respectively):

Sin(A)/a = Sin(B)/b


or in you case:

a = b*Sin(A)/Sin(B)

where the letters can be changed around. That will allow you to find the remaining sides. It looks like it may be a little computationally expensive, so use sparingly...

Edited by - Sr. Guapo on Jun 21 2004 5:37:29 PM
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 21 2004 :  11:02:10 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
Hi

OK ,,, I will assume that you have 4 points ( or 2 points and 2 vectors) I don't exactly know the information you have . anyway the idea would be the same ...



notice that p3 is any point lies on Line1,p4 is any point lies on Line2

  
Ya = m1 * Xa + b1  ' P1 & P3 satisfied (lies on it)  
Yb = m2 * Xb + b2 ' P2 & P4 satisfied (lies on it)  
  
b1 = Ya - m1 * Xa  
use p1 or p3  
b1 = y1 - m1 * x1  
b2 = y2 - m2 * x2  
  
m1 = (y3-y1)/(x3-x1)  , x3 # x1  
m2 = (y4-y2)/(x4-x2)  , x4 # x2  
  
_____________  
  
Ya = m1 * Xa + b1  
Yb = m2 * Xb + b2  
  
to find intersection point we let Ya = Yb = y , Xa = Xb = x  
Ya = Yb  
  
m1 * x + b1 = m2 * x + b2  
m1 * x - m2 * x = b2 - b1  
x (m1 - m2) = b2 - b1  
x = (b2 - b1)/(m1 - m2)  
notice : m1 never = m2 otherwise the are || i.e. never intersect  
  
hence ,  
mx1 = 1 /(x3-x1)  
mx2 = 1 /(x4-x2)  
m1 = (y3-y1) * mx1  
m2 = (y4-y2) * mx2  
b1 = y1 - m1 * x1  
b2 = y2 - m2 * x2  
x = (b2 - b1)/(m1 - m2)  
y = m1 * x + b1    or   y = m2 * x + b2  
  


  
Option Explicit
  
Private Type Vector2D  
X As Single
Y As Single
End Type
  
Private Sub Form_Load()  
Dim P1 As Vector2D, P2 As Vector2D, P3 As Vector2D, P4 As Vector2D  
  
P1 = SetV2(3000, 4000)  
P3 = SetV2(1000, 1000)  
P2 = SetV2(3000, 1000)  
P4 = SetV2(1000, 3000)  
  
Me.AutoRedraw = True
Line (P1.X, P1.Y)-(P3.X, P3.Y)  
Line (P2.X, P2.Y)-(P4.X, P4.Y)  
Me.Circle (P1.X, P1.Y), 100: Print " 1"  
Me.Circle (P2.X, P2.Y), 100: Print " 2"  
Me.Circle (P3.X, P3.Y), 100: Print " 3"  
Me.Circle (P4.X, P4.Y), 100: Print " 4"  
  
Dim IP As Vector2D  
Dim M1 As Single, M2 As Single
Dim Mx1 As Single, Mx2 As Single
Dim B1 As Single, B2 As Single
  
Mx1 = IIf(P3.X = P1.X, 0, 1 / (P3.X - P1.X))  
Mx2 = IIf(P4.X = P2.X, 0, 1 / (P4.X - P2.X))  
M1 = (P3.Y - P1.Y) * Mx1  
M2 = (P4.Y - P2.Y) * Mx2  
B1 = P1.Y - M1 * P1.X  
B2 = P2.Y - M2 * P2.X  
  
IP.X = (B2 - B1) / (M1 - M2)  
IP.Y = M1 * IP.X + B1  
  
Me.ForeColor = RGB(255, 0, 0): Me.DrawWidth = 3  
Circle (IP.X, IP.Y), 100: Print "   IP"  
End Sub
  
Private Function SetV2(X As Single, Y As Single) As Vector2D  
SetV2.X = X  
SetV2.Y = Y  
End Function
  



regards

Edited by - game_maker on Jun 21 2004 11:20:50 PM
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 22 2004 :  6:02:56 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
If you didn't understand what I was doing:

At first, we have 2 unknowns (x & y) this means you have to find 2 equation at least to solve it.

To find the point of intersection first we find 2 lines passing through that point (satisfy x & y) then we equalize them and hence we get x & y

To find an equation of a line we need to find (2 points) lies on it or one point and the slope

If you have a vector or ray and point then:
a = <x1, y1>
p = (x2, y2)
m = y1/x1
b = y2 - m * x2
That's how to find an equation of a line by knowing a point & vector (direction) [we get the slope from the vector , point]

If you know 2 point's then read my prev post

Edited by - game_maker on Jun 22 2004 6:06:22 PM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.2 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.