[brlcad-commits] SF.net SVN: brlcad:[58659] brlcad/trunk/src/libbn/chull.c From: - 2013-11-25 19:31:30 ```Revision: 58659 http://sourceforge.net/p/brlcad/code/58659 Author: starseeker Date: 2013-11-25 19:31:27 +0000 (Mon, 25 Nov 2013) Log Message: ----------- Untested (and almost certainly incorrect) but start working out the actual vector math needed to make these functions function. Modified Paths: -------------- brlcad/trunk/src/libbn/chull.c Modified: brlcad/trunk/src/libbn/chull.c =================================================================== --- brlcad/trunk/src/libbn/chull.c 2013-11-25 19:25:20 UTC (rev 58658) +++ brlcad/trunk/src/libbn/chull.c 2013-11-25 19:31:27 UTC (rev 58659) @@ -98,17 +98,23 @@ * @param n the number of points in the input set * @return 0 if successful */ - -#if 0 int bn_coplanar_3d_to_2d(point2d_t **points_2d, const point_t *origin_pnt, const vect_t *u_axis, const vect_t *v_axis, - const ponit_t *points_3d, int n) + const point_t *points_3d, int n) { - /* Step 1 - for each 3D point, construct the 3D vector from the origin_pt to that point */ - /* Step 2 - for each 3D point, project its vector onto the u and v axis vectors. The - * relative lengths of the two projects should be the UV coordinates */ + int i = 0; + for (i = 0; i < n; i++) { + vect_t temp, c, d; + fastf_t u, v; + VSUB2(temp, points_3d[i], *origin_pnt); + VPROJECT(temp, *u_axis, c, d); + u = (VDOT(c, *u_axis) > 0) ? (MAGNITUDE(c)) : (-1 * MAGNITUDE(c)); + v = (VDOT(d, *v_axis) > 0) ? (MAGNITUDE(d)) : (-1 * MAGNITUDE(d)); + V2SET((*points_2d)[i], u, v); + } + return 0; } @@ -127,15 +133,45 @@ int bn_coplanar_2d_to_3d(point_t **points_3d, const point_t *origin_pnt, const vect_t *u_axis, const vect_t *v_axis, - const ponit2d_t *points_2d, int n) + const point2d_t *points_2d, int n) { +int i; + vect_t u_x_component, u_y_component, u_z_component; + vect_t v_x_component, v_y_component, v_z_component; + vect_t x_axis, y_axis, z_axis; + vect_t temp; + fastf_t mag_u_x, mag_u_y, mag_u_z; + fastf_t mag_v_x, mag_v_y, mag_v_z; + VSET(x_axis, 1, 0, 0); + VSET(y_axis, 0, 1, 0); + VSET(z_axis, 0, 0, 1); /* Step 1 - find the 3d X, Y and Z components of u_axis and v_axis */ + VPROJECT(*u_axis, x_axis, u_x_component, temp); + VPROJECT(temp, y_axis, u_y_component, u_z_component); + VPROJECT(*v_axis, x_axis, v_x_component, temp); + VPROJECT(temp, y_axis, v_y_component, v_z_component); + mag_u_x = (VDOT(u_x_component, x_axis) > 0) ? (MAGNITUDE(u_x_component)) : (-1 * MAGNITUDE(u_x_component)); + mag_u_y = (VDOT(u_y_component, y_axis) > 0) ? (MAGNITUDE(u_y_component)) : (-1 * MAGNITUDE(u_y_component)); + mag_u_z = (VDOT(u_z_component, z_axis) > 0) ? (MAGNITUDE(u_z_component)) : (-1 * MAGNITUDE(u_z_component)); + mag_v_x = (VDOT(v_x_component, x_axis) > 0) ? (MAGNITUDE(v_x_component)) : (-1 * MAGNITUDE(v_x_component)); + mag_v_y = (VDOT(v_y_component, y_axis) > 0) ? (MAGNITUDE(v_y_component)) : (-1 * MAGNITUDE(v_y_component)); + mag_v_z = (VDOT(v_z_component, z_axis) > 0) ? (MAGNITUDE(v_z_component)) : (-1 * MAGNITUDE(v_z_component)); + /* Step 2 - for each 2D point, calculate the (x,y,z) coordinates as follows: * (http://math.stackexchange.com/questions/525829/how-to-find-the-3d-coordinate-of-a-2d-point-on-a-known-plane) */ + for (i = 0; i < n; i++) { + vect_t temp_2d; + VSET(temp_2d, points_2d[i][0]*mag_u_x + (points_2d)[i][1]*mag_v_x, + (points_2d)[i][0]*mag_u_y + (points_2d)[i][1]*mag_v_y, + (points_2d)[i][0]*mag_u_z + (points_2d)[i][1]*mag_v_z); + VADD2((*points_3d)[i], (*origin_pnt), temp_2d); + } + + return 0; } -#endif + /* isLeft(): test if a point is Left|On|Right of an infinite line. * Input: three points L0, L1, and p * Return: >0 for p left of the line through L0 and L1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```