randRangeNonZero(-10, 10) randRangeNonZero(-10, 10) randRangeNonZero(-10, 10) randRangeNonZero(-10, 10) abs(X1 - X2)/2 abs(Y1 - Y2)/2 max(X1, X2) + X_MARGIN min(X1, X2) - X_MARGIN max(Y1, Y2) + Y_MARGIN min(Y1, Y2) - Y_MARGIN Y1 - Y2 X1 - X2 SLOPE_NUMERATOR / SLOPE_DENOMINATOR Y1 - (X1 * M)

Poniższa prosta przechodzi przez punkt (X1, Y1):

y = fractionReduce( SLOPE_NUMERATOR, SLOPE_DENOMINATOR ) x + b

Jaka jest wartość wyrazu wolnego b b (ze wzoru y = ax + b?

(Y1 * SLOPE_DENOMINATOR - X1 * SLOPE_NUMERATOR) / SLOPE_DENOMINATOR

Należy podstawić (X1, Y1) pod równanie prostej:

Y1 = fractionReduce( SLOPE_NUMERATOR, SLOPE_DENOMINATOR ) \cdot X1 + b

Y1 = fractionReduce( X1*SLOPE_NUMERATOR , SLOPE_DENOMINATOR ) + b

b = Y1 - fractionReduce( X1*SLOPE_NUMERATOR , SLOPE_DENOMINATOR )

b = fractionReduce( Y1 * SLOPE_DENOMINATOR - X1 * SLOPE_NUMERATOR, SLOPE_DENOMINATOR )

Podstawiając fractionReduce( Y1 * SLOPE_DENOMINATOR - X1 * SLOPE_NUMERATOR, SLOPE_DENOMINATOR ) pod b otrzymamy y = fractionReduce( SLOPE_NUMERATOR, SLOPE_DENOMINATOR ) x + fractionReduce(Y1*SLOPE_DENOMINATOR-X1*SLOPE_NUMERATOR,SLOPE_DENOMINATOR).

graphInit({ range: max( abs(B) + 4 , 11 ), scale: 20, tickStep: 1, labelStep: 1, unityLabels: false, labelFormat: function( s ) { return "\\small{" + s + "}"; }, axisArrows: "<->" }); plot(function( x ) { return M * x + B; }, [min( ( -abs(B) -5 ), -12) , max( ( abs(B)+5 ), 12 )], { stroke: "#28ae7b" }); circle( [X1, Y1], 3/20, { stroke: "none", fill: "black" } ); label( [X1, Y1], "(" + X1 + ", " + Y1 + ")", p1Position( X1, Y1, X2, Y2 ) );