Example: http://www.zhaojz.com.cn/demo/draw10.html
//draw a vertical line outsidefunctionDrawverticalline (point, line) {//Draw Auxiliary Line-start varcolor = ' darkred ';//the color of the vertical line varColor2 = "#ccc";//Color of other auxiliary linesDrawpoint ({pw:2,ph:2,color: ' darkred ', point:line[0] }); Drawpoint ({pw:2,ph:2,color: ' darkred ', point:line[1] }); DrawLine (Point, line[0], {color:color2}); DrawLine (Point, line[1], {color:color2}); //Draw Auxiliary Line-endDrawpoint ({pw:2,ph:2,color: ' darkred ', point:point}); varV_1_0 = line[1][1]-line[0][1]; varH_1_0 = line[1][0]-line[0][0]; varC_square = Math.pow (v_1_0,2) + Math.pow (h_1_0,2); varc = math.sqrt (C_square);//calculates the distance between two points on a line varA_b_slope = 0; varHasslope =true; if(V_1_0 = = 0) {Hasslope=false; } a_b_slope= V_1_0/H_1_0; The slope of the linevarPoint_pos = 1;//define the position relationship of a point to a line //when the slope of the line is greater than 0 o'clock, if the point is above the line, Point_pos = 1, if the point is below the line, Point_pos = 3 //when the slope of the line is less than 0 o'clock, if the point is above the line, Point_pos = 2, if the point is below the line, Point_pos = 4 if(hasslope) {varA_b_intercept = line[1][1]-a_b_slope*line[1][0]; varP_intercept = point[1]-a_b_slope*point[0]; if(A_b_slope >= 0){ if(P_intercept >a_b_intercept) {Point_pos= 3; }Else{Point_pos= 1; } }Else{ if(P_intercept <a_b_intercept) {Point_pos= 2; }Else{Point_pos= 4; } } } //A is the angle between the line and the horizon (acute angle) varSinA = Math.Abs (V_1_0)/C; SinAvarCosA = Math.Abs (H_1_0)/C; CosA//c is the angle between the vertical line and the horizontal line in the clockwise direction. varSinC = 0; varCosC = 0; //d is the angle between the parallel lines of point and line and the horizontal line varSinD = 0; varCOSD = 0; Switch(point_pos) { Case1: SinC=CosA; CosC= -SinA; SinD= -CosC; Cosd=SinC; Break; Case2: SinC=CosA; CosC=SinA; SinD=CosC; Cosd= -SinC; Break; Case3: SinC= -CosA; CosC=SinA; SinD=CosC; Cosd= -SinC; Break; Case4: SinC= -CosA; CosC= -SinA; SinD= -CosC; Cosd=SinC; Break; default: } //Cross point to draw line linesDrawLine (Point, [Point[0]+c*cosd, Point[1]+c*sind], {color: ' Red '}); DrawLine (Point, [point[0]+c* (-COSD), point[1]+c* (-sind)], {color: ' Red '}); varPoint_v_1 = point[1]-line[1][1]; varpoint_h_1 = point[0]-line[1][0]; varpoint_dist_1 = Math.sqrt (Math.pow (point_v_1,2) +math.pow (point_h_1,2));//point to line up a little distance varPoint_v_0 = point[1]-line[0][1]; varPoint_h_0 = point[0]-line[0][0]; varPoint_dist_0 = Math.sqrt (Math.pow (point_v_0,2) +math.pow (point_h_0,2));//point to Line on the other distance vars = (C+POINT_DIST_1+POINT_DIST_0)/2;varArea = Math.sqrt (s* (s-c) * (S-POINT_DIST_0) * (s-point_dist_1));//the area of a triangle with points, line[0], and line[1] as vertices varh = 2*area/c; The height of the trianglevarVpoint = [Point[0]+h*cosc, point[1]+h*sinc];//Dip PointDrawLine (Point, Vpoint);//Draw Perpendicular}
JS drawing geometry of the six "over a straight line outside a point as perpendicular"