/* get(u,i): returns the ith component of vector u */ func get { para u, i; return u[i]; }; /* add(u,v): returns the vector addition of vectors u and v */ func add { para u, v; return [u[1]+v[1], u[2]+v[2], u[3]+v[3]]; }; /* scale(s,v): returns the vector v multiplied by scalar s */ func scale { para s, v; return [v[1]*s, v[2]*s, v[3]*s]; }; /* unit(v): returns unit vector in direction of v */ func unit { para v; auto len; len = sqrt(float(v[1]*v[1] + v[2]*v[2] + v[3]*v[3])); if (len==0) return [@,@,@]; /* Stop divide by zero */ else return [(v[1]/len), (v[2]/len), (v[3]/len)]; }; /* dot(u,v): returns dot-product of vectors u and v */ func dot { para v; return (v[1]*u[1] + v[2]*u[2] + v[3]*u[3]); }; /* cross(u,v): returns cross-product of vectors u and v */ func cross { para u, v; return [(u[2]*v[3] - u[3]*v[2]), (u[3]*v[1] - u[1]*v[3]), (u[1]*v[2] - u[2]*v[1])]; }; /* JS-EDEN version */ func float { para x; return x; }; /* ## atan2 adapted from JavaScript in style of Matt Cranham - with conversion to degrees func atan2 { return ${{ Math.atan2(arguments[0])*180/Math.PI; }}$; }; */ ## to be consistent with EDEN conventions ... func atan2 { return ${{ Math.atan2(arguments[0], arguments[1]); }}$; }; func sin { return ${{ Math.sin(arguments[0]); }}$; }; func cos { return ${{ Math.cos(arguments[0]); }}$; }; /* Specification of view */ view_cen is [_x_pos,_y_pos,_z_pos]; view_norm is [-_x_dir, -_y_dir, -_z_dir]; view_theta is atan(_y_dir,_x_dir); view_up is [-_z_dir*cos(view_theta), -_z_dir*sin(view_theta), sqrt(_x_dir*_x_dir + _y_dir*_y_dir)]; eye_dist = 200; view_width = 200; view_height = 200; /* Calculate view plane x and z axis */ view_x is unit(cross(view_up,view_norm)); view_z is unit(view_norm); /* Definition of view: [Centre, View axis (x,y,z), Eye distance from plane] */ view is [view_cen, view_x, cross(view_z,view_x), view_z, eye_dist]; /* project(p,v): returns donald point of p projected into viewplane v */ func project { para p, v; auto pers, x, y, z; x = p[1] - v[1][1]; y = p[2] - v[1][2]; z = p[3] - v[1][3]; pers = 1 - (v[4][1]*x + v[4][2]*y + v[4][3]*z)/v[5]; if (pers <= 0) return [@, @]; /* At or behind eye */ else return [(v[2][1]*x + v[2][2]*y + v[2][3]*z)/pers, (v[3][1]*x + v[3][2]*y + v[3][3]*z)/pers]; }; _x_pos = -300; _y_pos = 20; _z_pos = -300; _x_dir = 4; _y_dir = 8; _z_dir = 1; offset = [300,300]; origin is add(offset,project([0,0,0], view)); size = 100; p1 is add(offset,project([size,0,0], view)); p2 is add(offset,project([0,size,0], view)); p3 is add(offset,project([0,0,size], view)); axisx is Line(origin[1], origin[2], p1[1], p1[2], "red"); axisy is Line(origin[1], origin[2], p2[1], p2[2], "green"); axisz is Line(origin[1], origin[2], p3[1], p3[2], "blue"); picture is [axisx, axisy, axisz]; xplane is Polygon([origin[1],origin[2], p2[1], p2[2], p2[1]+p3[1]-origin[1], p2[2]+p3[2]-origin[2], p3[1], p3[2]], "yellow"); picture is [axisx, axisy, axisz, xplane]; yplane is Polygon([origin[1],origin[2], p1[1], p1[2], p1[1]+p3[1]-origin[1], p1[2]+p3[2]-origin[2], p3[1], p3[2]], "pink"); zplane is Polygon([origin[1],origin[2], p1[1], p1[2], p1[1]+p2[1]-origin[1], p1[2]+p2[2]-origin[2], p2[1], p2[2]], "lightblue"); picture is [axisx, axisy, axisz, xplane, yplane, zplane]; _x_dir = 4; _y_dir = 8; _z_dir = 4; _y_dir = 3; _x_dir = -1; _z_dir = 5; picture is [xplane, yplane, zplane, axisx, axisy, axisz]; html("

x_dir|y_dir|z_dir|x_pos|y_pos|z_pos

"); testpt is add(offset,project([size,size,size], view)); testvect is Line(origin[1], origin[2], testpt[1], testpt[2], "black"); picture is [axisx, axisy, axisz, xplane, yplane, zplane, testvect]; ## testplane is Polygon([origin[1],origin[2], p2[1], p2[2], p2[1]+testpt[1]-origin[1], p2[2]+testpt[2]-origin[2], testpt[1], testpt[2]], "orange"); testplane is Polygon([origin[1],origin[2], p2[1], p2[2], testpt[1], testpt[2]], "orange"); ## origin + (v - origin) + (w - origin) = v + w - origin picture is [axisx, axisy, axisz, xplane, yplane, zplane, testvect, testplane]; labO is Text("O", origin[1],origin[2], "black"); labX is Text("X", p1[1],p1[2], "black"); labY is Text("Y", p2[1],p2[2], "black"); labZ is Text("Z", p3[1],p3[2], "black"); picture is [axisx, axisy, axisz, xplane, yplane, zplane, testvect, testplane, labO, labX, labY, labZ]; Spos = 100; mk_eye_dist is Slider("sliderED", 100, 900, 5, 500, "vertical", Spos + 700, 100); mk_x_pos is Slider("sliderXP", 100, 500, 5, 200, "vertical", Spos + 770, 100); mk_y_pos is Slider("sliderYP", 100, 500, 5, 200, "vertical", Spos + 840, 100); mk_z_pos is Slider("sliderZP", 100, 500, 5, 200, "vertical", Spos + 910, 100); mk_x_dir is Slider("sliderXD", 100, 500, 5, 200, "vertical", Spos + 980, 100); mk_y_dir is Slider("sliderYD", 100, 500, 5, 200, "vertical", Spos + 1050, 100); mk_z_dir is Slider("sliderZD", 100, 500, 5, 200, "vertical", Spos + 1120, 100); Sbot = 250; txt_eye_dist is Text("ED", Spos + 700, Sbot); txt_x_pos is Text("XP", Spos + 770, Sbot); txt_y_pos is Text("YP", Spos + 840, Sbot); txt_z_pos is Text("ZP", Spos + 910, Sbot); txt_x_dir is Text("XD", Spos + 980, Sbot); txt_y_dir is Text("YD", Spos + 1050, Sbot); txt_z_dir is Text("ZD", Spos + 1120, Sbot); picture is [xplane, yplane, zplane, axisx, axisy, axisz, testplane, labO, labX, labY, labZ, button1, mk_eye_dist, mk_x_pos, mk_y_pos, mk_z_pos, mk_x_dir, mk_y_dir, mk_z_dir, txt_eye_dist, txt_x_pos, txt_y_pos, txt_z_pos, txt_x_dir, txt_y_dir, txt_z_dir]; eye_dist is sliderED_value; _x_pos is sliderXP_value; _y_pos is sliderYP_value; _z_pos is sliderZP_value; _x_dir is sliderXD_value; _y_dir is sliderYD_value; _z_dir is sliderZD_value; test3 is Line(p1[1]+p3[1]-origin[1], p1[2]+p3[2]-origin[2], testpt[1], testpt[2], "black"); test2 is Line(p1[1]+p2[1]-origin[1], p1[2]+p2[2]-origin[2], testpt[1], testpt[2], "black"); test23 is Line(p2[1]+p3[1]-origin[1], p2[2]+p3[2]-origin[2], testpt[1], testpt[2], "black"); picture is [xplane, yplane, zplane, axisx, axisy, axisz, testplane, labO, labX, labY, labZ, button1, mk_eye_dist, mk_x_pos, mk_y_pos, mk_z_pos, mk_x_dir, mk_y_dir, mk_z_dir, txt_eye_dist, txt_x_pos, txt_y_pos, txt_z_pos, txt_x_dir, txt_y_dir, txt_z_dir, test2, test3, test23]; v is Vector([50,50,100]); ## using Sylvester package vProj is add(offset,project([v.e(1),v.e(2),v.e(3)], view)); ## projecting into a 2d JS-EDEN vector vLine is Line(origin[1], origin[2], vProj[1], vProj[2], "red"); w is Vector([150,50,50]); ## using Sylvester package wProj is add(offset,project([w.e(1),w.e(2),w.e(3)], view)); ## projecting into a 2d JS-EDEN vector wLine is Line(origin[1], origin[2], wProj[1], wProj[2], "green"); u is Vector([100,50,150]); ## using Sylvester package uProj is add(offset,project([u.e(1),u.e(2),u.e(3)], view)); ## projecting into a 2d JS-EDEN vector uLine is Line(origin[1], origin[2], uProj[1], uProj[2], "purple"); picture is [xplane, yplane, zplane, axisx, axisy, axisz, testplane, labO, labX, labY, labZ, button1, mk_eye_dist, mk_x_pos, mk_y_pos, mk_z_pos, mk_x_dir, mk_y_dir, mk_z_dir, txt_eye_dist, txt_x_pos, txt_y_pos, txt_z_pos, txt_x_dir, txt_y_dir, txt_z_dir, test2, test3, test23, vLine, wLine, uLine]; u is v.add(w); ## using Sylvester package