Difference between revisions of "Slope"

From HIVE
Jump to navigation Jump to search
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
To detect the '''slope''' of the [[terrain]] along a certain line, you have to apply the following formula:
 
To detect the '''slope''' of the [[terrain]] along a certain line, you have to apply the following formula:
  
(z1 - z2) / sqrt((x1 - x2)^2 + (y1 -y2)^2)
+
(z1 - z2) / sqrt((x1 - x2)^2 + (y1 -y2)^2)
  
You require the x, y and z coordinates of two points along this line. In this formula, x1, y1 and z1 are the x, y and z coordinates of one point and x2, y2 and z2 are the x, y and z coordinates of another point. An easy way to do it if you're doing it for the movement along the terrain of one [[unit]] is to constantly set one point to be the point the unit is at and another point to the first point. Then, you can constantly calculate slope using the above formula. If you want to do it for terrain, then the "Height at" function can be used to find z; otherwise, "height of" finds the distance of a unit above the terrain.
+
You require the x, y and z coordinates of two points along this line. In this formula, x1, y1 and z1 are the x, y and z coordinates of one point and x2, y2 and z2 are the x, y and z coordinates of another point. An easy way to do it if you're doing it for the movement along the terrain of one [[unit]] is to constantly set one point to be the point the unit is at and another point to the first point. Then, you can constantly calculate slope using the above formula. If you want to do it for terrain, then the "'''Height at'''" function can be used to find z; otherwise, "'''Height of'''" finds the distance of a unit above the terrain.
  
If you want to find slope at a certain point without having a unit move across it, you'd have to decide on an angle, choose the point, use the angle and the points to find two new points offset by a tiny amount from the point you want along that angle, and use the above formula on it. This method is less efficient than the above for finding slope along which a unit is traveling (because of the need to calculate two points) but it's more flexible. Here's a simple diagram, assuming that the original point is G and the angle is 0: P1 -- G -- P2 . Using G and the angle, you can calculate P1 and P2 and use the coordinates of that point to calculate slope.
+
If you want to find slope at a certain point without having a unit move across it, you'd have to decide on an angle, choose the point, use the angle and the points to find two new points offset by a tiny amount from the point you want along that angle, and use the above formula on it. This method is less efficient than the above for finding slope along which a unit is travelling (because of the need to calculate two points) but it's more flexible. Here's a simple diagram, assuming that the original point is G and the angle is 0: P1 -- G -- P2 . Using G and the angle, you can calculate P1 and P2 and use the coordinates of that point to calculate slope.
  
 
[[Category:StarCraft II]]
 
[[Category:StarCraft II]]
 
[[Category:Reference]]
 
[[Category:Reference]]
 +
[[Category:Tutorials]]

Latest revision as of 07:31, 21 November 2010

To detect the slope of the terrain along a certain line, you have to apply the following formula:

(z1 - z2) / sqrt((x1 - x2)^2 + (y1 -y2)^2)

You require the x, y and z coordinates of two points along this line. In this formula, x1, y1 and z1 are the x, y and z coordinates of one point and x2, y2 and z2 are the x, y and z coordinates of another point. An easy way to do it if you're doing it for the movement along the terrain of one unit is to constantly set one point to be the point the unit is at and another point to the first point. Then, you can constantly calculate slope using the above formula. If you want to do it for terrain, then the "Height at" function can be used to find z; otherwise, "Height of" finds the distance of a unit above the terrain.

If you want to find slope at a certain point without having a unit move across it, you'd have to decide on an angle, choose the point, use the angle and the points to find two new points offset by a tiny amount from the point you want along that angle, and use the above formula on it. This method is less efficient than the above for finding slope along which a unit is travelling (because of the need to calculate two points) but it's more flexible. Here's a simple diagram, assuming that the original point is G and the angle is 0: P1 -- G -- P2 . Using G and the angle, you can calculate P1 and P2 and use the coordinates of that point to calculate slope.