Board index » cppbuilder » Straight Line Algorithm
Cenk
CBuilder Developer |
Cenk
CBuilder Developer |
Straight Line Algorithm2006-01-11 07:04:10 AM cppbuilder60 hi, i wanna know if there is a sample straight line algorithm. in my application, in a specific time interval, there are prices and among those prices i need to get 2 highest low price points and with those points i need to get the coordinates of the straight line but NOT the graph thanks |
Ed Mulroy
CBuilder Developer |
2006-01-11 12:41:14 PM
Re:Straight Line Algorithm
Init the set of two lowest price points to the first two points.
Pass through the array starting from the third one looking for one which is lower than the highest point that you have, replacing that highest value with the one you found. Convert the points you have at the end to coordinates in the window that you have created. A straight line has the formula y = a * x + b Where 'y' is the vertical and 'x' is the horizontal. Assuming that the first low point is [y1, x1] and the second [y2, x2] a = (y2 - y1) / (x2 - x1) b = y2 - a * x2 Windows coordinates are different. The 'y' value at the top is zero and the values increase as you go down. For that reason the formula that I give above will plot upside down so, assuming that the vertical value at the bottom of the graph is Ymax, plot Ymax-y instead of plotting y . Ed QuoteCenk wrote in message |