Drawing slope lines in a confined space

This isn't a game development question per se, but here goes...

I have a 50x50 pixel space in which I need to draw five lines: X and Y axes, and one line for each of a steepest, average, and flattest slope.

I'm working with (Java) code that was handed down to me with no documentation or commentary and I've never worked with drawing on a canvas before. Here's the code for a box that measured 175x75 px. This needs to be adapted for a 50x50 area as described above.

    DrawingArea canvas = new DrawingArea(175, 75);
Rectangle rectangle = new Rectangle(0, 0, 174, 75);
Line slopeMainLineX = new Line(5, 70, 170, 70);
slopeMainLineX.setStrokeOpacity(0.5);
Line slopeMainLineY = new Line(40, 70, 40, 0);
slopeMainLineY.setStrokeOpacity(0.5);
steepestLine = new Line(40, 70, 0, 0);
steepestLine.setStrokeWidth(3);
avgSlopeLine = new Line(40, 70, 0, 0);
avgSlopeLine.setStrokeWidth(2);
flattestLine = new Line(40, 70, 0, 0);
flattestLine.setStrokeWidth(1);

int steepestAngle = Math.round(site.getSlope().getMax());
int averageAngle = Math.round(site.getSlope().getAvg());
int flatestAngle = Math.round(site.getSlope().getMin());

double xPointSteepestAngle = 40 + 120 * Math.cos(steepestAngle*0.0174532925);
double yPointSteepestAngle = 70 + 120 * Math.sin(steepestAngle*0.0174532925);
double xPointAverageAngle = 40 + 120 * Math.cos(averageAngle*0.0174532925);
double yPointAverageAngle = 70 + 120 * Math.sin(averageAngle*0.0174532925);
double xPointFlatestAngle = 40 + 120 * Math.cos(flatestAngle*0.0174532925);
double yPointFlatestAngle = 70 + 120 * Math.sin(flatestAngle*0.0174532925);

steepestLine.setX2((int) xPointSteepestAngle);
steepestLine.setY2(70 - ((int) yPointSteepestAngle - 70));

avgSlopeLine.setX2((int) xPointAverageAngle);
avgSlopeLine.setY2(70 - ((int) yPointAverageAngle - 70));

flatestLine.setX2((int) xPointFlatestAngle);
flatestLine.setY2(70 - ((int) yPointFlatestAngle - 70));


I'm completely lost here, so any help would be greatly appreciated.

-
too...many...magic..numbers..... head explodes – pek Aug 25 '11 at 15:31
Off-topic and too localized. Did you try stackoverflow? – bummzack Aug 25 '11 at 21:31

Replace some constants, it might help understanding what happens:

0.0174532925 => Math.PI / 180.0
175 => MyCanvas.width
75 => MyCanvas.height
174 => MyCanvas.width - 1
74 => MyCanvas.height - 1
120 => MyCanvas.slopeLineLength /* About 40 */


Alternatively, to make the horizontal line centered, replace the following value:

40 => MyCanvas.height / 2 /* 37.5 in original, not 40.0 */


Finally, you can calculate the slope line length instead of setting it (to about 50 if you don't want the lines to be too long):

120 => Math.sqrt(

EDIT: Scratch the last part, obvious brain fart on my side. You should just pick a value between (MyCanvas.height - 2 * MyCanvas.padding) / 2 and (MyCanvas.width - 2 * MyCanvas.padding) for MyCanvas.slopeLineLength.