int main(void) { int intersect=0; double tmin=0, tmax=1000, t; Lgm_Vector *vec1, *vec2, *vec3; EllipsoidType ellipsoid; RayType ray; // make a sphere at the origin vec1 = Lgm_CreateVector(0,0,0); ellipsoid.Origin = *vec1; ellipsoid.Radius_a = 2.0; ellipsoid.Radius_b = 2.0; ellipsoid.Radius2_a = ellipsoid.Radius_a*ellipsoid.Radius_a; ellipsoid.Radius2_b = ellipsoid.Radius_b*ellipsoid.Radius_b; // make a ray pointing at the origin vec2 = Lgm_CreateVector(10,0,0); vec3 = Lgm_CreateVector(-1,0,0); ray.Origin = *vec2; ray.Direction = *vec3; // print out some info on the geometry printf("Ray origin: %lf %lf %lf\n", ray.Origin.x, ray.Origin.y, ray.Origin.z); printf("Ray direction: %lf %lf %lf\n", ray.Direction.x, ray.Direction.y, ray.Direction.z); intersect = Lgm_EllipsoidIntersect( &ellipsoid, &ray, &tmin, &tmax, &t ); if (intersect) { printf("The ray did intersect the ellipsoid, %lf from the ray origin\n", t); printf("Closest intersection point, %lf %lf %lf\n", ray.Origin.x+ray.Direction.x*t, ray.Origin.y+ray.Direction.y*t, ray.Origin.z+ray.Direction.z*t); } else printf("The ray did not intersect the ellipsoid, %lf\n",t); Lgm_FreeVector(vec1); Lgm_FreeVector(vec2); Lgm_FreeVector(vec3); return(0); }
int main(void) { Lgm_Vector *v, *v2; double Lat, Lon, r, ang; double Arr[3]; printf("Make a Vector:\n"); v = Lgm_CreateVector(1,2,3); Lgm_PrintVector(v); printf("Normalize it:\n"); Lgm_NormalizeVector(v); Lgm_PrintVector(v); printf("Force it to have a magnitude:\n"); Lgm_ForceMagnitude(v, 2); Lgm_PrintVector(v); printf("Set its value:\n"); Lgm_SetVecVal(v, 3); Lgm_PrintVector(v); printf("Set its elements:\n"); Lgm_SetVecElements(v, 1,2,3); Lgm_PrintVector(v); printf("Change it to spherical:\n"); Lgm_CartToSphCoords(v, &Lat, &Lon, &r); printf("Lat:%lf Lon:%lf r:%lf\n", Lat, Lon, r); printf("And back to Cart:\n"); Lgm_SphToCartCoords(Lat, Lon, r, v ); Lgm_PrintVector(v); printf("Make it an array:\n"); Lgm_VecToArr(v, Arr); printf("Arr[0]:%lf Arr[1]:%lf Arr[2]:%lf\n", Arr[0], Arr[1], Arr[2]); printf("Edit the array and make it a vector:\n"); Arr[0] = -1; Lgm_ArrToVec(Arr, v); Lgm_PrintVector(v); printf("Divide it by a scalar:\n"); Lgm_VecDivideScalar(v, 2); Lgm_PrintVector(v); printf("Multiply by a scalar:\n"); Lgm_VecMultiplyScalar(v, 2); Lgm_PrintVector(v); printf("Make a new vector and get the angle between them:\n"); v2 = Lgm_CreateVector(1,0,0); Lgm_SetVecElements(v, 0, 1, 0); ang = Lgm_VectorAngle(v, v2); printf("Angle:%lf\n", ang); printf("Make a new vector and get the angle between them:\n"); Lgm_SetVecElements(v, 0, 1, 0); Lgm_SetVecElements(v2, 0, 1, 0); ang = Lgm_VectorAngle(v, v2); printf("Angle:%lf\n", ang); Lgm_FreeVector(v); Lgm_FreeVector(v2); return(0); }