equilateral triangle
Hi,
It''s a long time since I''ve had to do geometry so need to ask a quick question...
I have an equilateral triangle, ABC
Two of the angles POSITIONS (say A and B) are known in terms of x and y co-ordinates.
How do I determine the co-ordinates of the third position (C in this case)?
I''m working in VB.net so please give suggestions in code or formula...
THANX!
Lindsay Miles
Lindsay Miles
I don''t think this will help too much with code, but I was playing around with the problem on paper and thought this up. Keep in mind, I haven''t finished geometry yet, so there''s probably a lot I still haven''t learned. Let''s look at it this way:
You have an equilateral triangle, and two of its points are at (4,2) and (8,2). The x coordinate of the third would be the midpoint of the two others, in this case 6. Then to get the height, I did this:
If you divide the triangle in two vertically, you have a triangle with a base of 2, and the angle on the left is 60 degrees. (''Cause it came from the equilateral triangle)
Then you can use tangent to get the height:
tan60 = height/2, or 2(tan60) = height.
Therefore, the height is approximately 3.464... That''s the height of the triangle, however, not the height of the point. In this example, you''d have to add another two.
I''ve tested it with the Pythagorean Theorem, and it works. 2^2 + 3.464^2 equals four, so the distance between all three points is equal...
Darn these high-school educations, huh? They don''t teach you how to do anything important! Well, I don''t know how to cahange that into code that wouldn''t be incredibly slow. I figure, however, that maybe you know a few more laws or something that I don''t, and maybe you can translate that into code. Hope so.
-Arek the Absolute
You have an equilateral triangle, and two of its points are at (4,2) and (8,2). The x coordinate of the third would be the midpoint of the two others, in this case 6. Then to get the height, I did this:
If you divide the triangle in two vertically, you have a triangle with a base of 2, and the angle on the left is 60 degrees. (''Cause it came from the equilateral triangle)
Then you can use tangent to get the height:
tan60 = height/2, or 2(tan60) = height.
Therefore, the height is approximately 3.464... That''s the height of the triangle, however, not the height of the point. In this example, you''d have to add another two.
I''ve tested it with the Pythagorean Theorem, and it works. 2^2 + 3.464^2 equals four, so the distance between all three points is equal...
Darn these high-school educations, huh? They don''t teach you how to do anything important! Well, I don''t know how to cahange that into code that wouldn''t be incredibly slow. I figure, however, that maybe you know a few more laws or something that I don''t, and maybe you can translate that into code. Hope so.
-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Arek, thanx for your reply...
If there is anyone else out there who can contribute to this, I''d appreciate it!
I need a formula into which I can pass any two points and have a third returned which would complete all 3 points on the equilateral triangle.
Remember, for any two given points (say A & B) there is only one line, AB. There could be two returnable points, depending on which side of the line AB we choose to place the third to make up the triangle.
Maybe we pass in an additional flag (say 0 or 1) to specify which third point we want...
I still need that formula though, to determine the third point so further help will be useful!
Thanx again!
Lindsay Miles
If there is anyone else out there who can contribute to this, I''d appreciate it!
I need a formula into which I can pass any two points and have a third returned which would complete all 3 points on the equilateral triangle.
Remember, for any two given points (say A & B) there is only one line, AB. There could be two returnable points, depending on which side of the line AB we choose to place the third to make up the triangle.
Maybe we pass in an additional flag (say 0 or 1) to specify which third point we want...
I still need that formula though, to determine the third point so further help will be useful!
Thanx again!
Lindsay Miles
Lindsay Miles
Hi, Im not sure how you would implement this in VB, as I haven;t used it for a couple of years but here is the basic idea:
Given two points, P1(4,2) and P2(8,2) and you need P3(?,?)...
* <- P3
/ / P1->*----*<-P2
(Sorry if that comes out wierd in the post...)
Right, with an equilateral triangle, you know that all the angles are 60 degrees. Now, to rotate a point by any given angle you use the following formula:
x' = x*cos(theta) - y*sin(theta)
y' = x*sin(theta) + y*cos(theta)
So, first you need to make the coordinates into local coordinates. Easy enough, lets use P1 as the origin. so our new coordinates are: P1(0,0) and P2(4,0). Now we stick 60 degrees into the place of theta in the above formula, and replace x + y with 4 + 0 respectively to get the local coordinates for P3. Then to make it back into world coordinates you just add the (x,y) values of P1 to it:
x' = 4*cos(60) - y*sin(60) = 2.
y' = 4*sin(60) + y*cos(60) = 3.464101 (to 6 decimal places)
Now add the (x,y) values of P1:
2 + 4 = 6. = final X coord.
3.464101 + 2 = 5.464101. = final Y coord.
So P3 = (6, 5.464101).
Now, that should be easy enough to implement, as long as VB has sin and cos functions anyway. If you want to know how the coordinate rotation theory works, there is an article here on GameDev about it, should be easy to find.
Later, Mosh.
[EDIT] DAMN, stupid picture came out wierd! [/EDIT]
Hey man, I don't wanna sound like a queer or nothin' but i think unicorns kick ass! -> Orgasmo.
[edited by - Mosh on June 2, 2002 7:41:54 PM]
Given two points, P1(4,2) and P2(8,2) and you need P3(?,?)...
* <- P3
/ / P1->*----*<-P2
(Sorry if that comes out wierd in the post...)
Right, with an equilateral triangle, you know that all the angles are 60 degrees. Now, to rotate a point by any given angle you use the following formula:
x' = x*cos(theta) - y*sin(theta)
y' = x*sin(theta) + y*cos(theta)
So, first you need to make the coordinates into local coordinates. Easy enough, lets use P1 as the origin. so our new coordinates are: P1(0,0) and P2(4,0). Now we stick 60 degrees into the place of theta in the above formula, and replace x + y with 4 + 0 respectively to get the local coordinates for P3. Then to make it back into world coordinates you just add the (x,y) values of P1 to it:
x' = 4*cos(60) - y*sin(60) = 2.
y' = 4*sin(60) + y*cos(60) = 3.464101 (to 6 decimal places)
Now add the (x,y) values of P1:
2 + 4 = 6. = final X coord.
3.464101 + 2 = 5.464101. = final Y coord.
So P3 = (6, 5.464101).
Now, that should be easy enough to implement, as long as VB has sin and cos functions anyway. If you want to know how the coordinate rotation theory works, there is an article here on GameDev about it, should be easy to find.
Later, Mosh.
[EDIT] DAMN, stupid picture came out wierd! [/EDIT]
Hey man, I don't wanna sound like a queer or nothin' but i think unicorns kick ass! -> Orgasmo.
[edited by - Mosh on June 2, 2002 7:41:54 PM]
Life is all about expression, so express yourself.
How about this? I''m assuming you know the length of the sides of the triangle, because you say you know two of the points. If that''s the case, could you just take one point, and rotate it 60 degrees around the other? If you wanna find out how to do that, look up some of the simple 3D tutorials on this site. They''d explain it better than I can. If the triangle''s equilateral, that should work.
-Arek the Absolute
-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Darn. You beat me to my second idea, Mosh! No fair!
-Arek the Absolute
-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Well, the x value of the third point of the triangle (C) is the x value of the point between A and B (in the middle). To calculate the height of the triangle, wich should be the y value of C, you use the formula to calculate the triangle height in a equilater triangle. The formula is:
triangle height = (side * 3^(1/2)) / 2
That's it. I have some problem with english so I couldnt write this better.
[edited by - Ragadast on June 2, 2002 8:09:49 PM]
triangle height = (side * 3^(1/2)) / 2
That's it. I have some problem with english so I couldnt write this better.
[edited by - Ragadast on June 2, 2002 8:09:49 PM]
// calc length of line AB
len_x = B_x - A_x;
len_y = B_y - A_y;
// find midpoint of line AB
mid_x = A_x + (len_x / 2.0);
mid_y = A_y + (len_y / 2.0);
// if A, B, C are in clockwise order
C_x = mid_x + (len_y * 0.8660254);
C_y = mid_y - (len_x * 0.8660254);
// else if A, B, C are in counter-clockwise order
C_x = mid_x - (len_y * 0.8660254);
C_y = mid_y + (len_x * 0.8660254);
[edited by - don on June 2, 2002 12:08:08 AM]
len_x = B_x - A_x;
len_y = B_y - A_y;
// find midpoint of line AB
mid_x = A_x + (len_x / 2.0);
mid_y = A_y + (len_y / 2.0);
// if A, B, C are in clockwise order
C_x = mid_x + (len_y * 0.8660254);
C_y = mid_y - (len_x * 0.8660254);
// else if A, B, C are in counter-clockwise order
C_x = mid_x - (len_y * 0.8660254);
C_y = mid_y + (len_x * 0.8660254);
[edited by - don on June 2, 2002 12:08:08 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement