comparison Framework/Toolbox/GeometryToolbox.cpp @ 140:2115530d3703 wasm

OrientedBoundingBox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Jan 2018 14:42:33 +0100
parents e2fe9352f240
children 62670cc2bb50
comparison
equal deleted inserted replaced
139:22628d37ef5c 140:2115530d3703
257 // This is Skala algorithm for rectangles, "A new approach to line 257 // This is Skala algorithm for rectangles, "A new approach to line
258 // and line segment clipping in homogeneous coordinates" 258 // and line segment clipping in homogeneous coordinates"
259 // (2005). This is a direct, non-optimized translation of Algorithm 259 // (2005). This is a direct, non-optimized translation of Algorithm
260 // 2 in the paper. 260 // 2 in the paper.
261 261
262 static uint8_t tab1[16] = { 255 /* none */, 262 static const uint8_t tab1[16] = { 255 /* none */,
263 0, 263 0,
264 0, 264 0,
265 1, 265 1,
266 1, 266 1,
267 255 /* na */, 267 255 /* na */,
268 0, 268 0,
269 2, 269 2,
270 2, 270 2,
271 0, 271 0,
272 255 /* na */, 272 255 /* na */,
273 1, 273 1,
274 1, 274 1,
275 0, 275 0,
276 0, 276 0,
277 255 /* none */ }; 277 255 /* none */ };
278 278
279 279
280 static uint8_t tab2[16] = { 255 /* none */, 280 static const uint8_t tab2[16] = { 255 /* none */,
281 3, 281 3,
282 1, 282 1,
283 3, 283 3,
284 2, 284 2,
285 255 /* na */, 285 255 /* na */,
286 2, 286 2,
287 3, 287 3,
288 3, 288 3,
289 2, 289 2,
290 255 /* na */, 290 255 /* na */,
291 2, 291 2,
292 3, 292 3,
293 1, 293 1,
294 3, 294 3,
295 255 /* none */ }; 295 255 /* none */ };
296 296
297 // Create the coordinates of the rectangle 297 // Create the coordinates of the rectangle
298 Vector x[4]; 298 Vector x[4];
299 AssignVector(x[0], xmin, ymin, 1.0); 299 AssignVector(x[0], xmin, ymin, 1.0);
300 AssignVector(x[1], xmax, ymin, 1.0); 300 AssignVector(x[1], xmax, ymin, 1.0);
376 // default value in such a case 376 // default value in such a case
377 spacingX = 1; 377 spacingX = 1;
378 spacingY = 1; 378 spacingY = 1;
379 } 379 }
380 } 380 }
381
382
383 Matrix CreateRotationMatrixAlongX(double a)
384 {
385 // Rotate along X axis (R_x)
386 // https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
387 Matrix r(3, 3);
388 r(0,0) = 1;
389 r(0,1) = 0;
390 r(0,2) = 0;
391 r(1,0) = 0;
392 r(1,1) = cos(a);
393 r(1,2) = -sin(a);
394 r(2,0) = 0;
395 r(2,1) = sin(a);
396 r(2,2) = cos(a);
397 return r;
398 }
399
400
401 Matrix CreateRotationMatrixAlongY(double a)
402 {
403 // Rotate along Y axis (R_y)
404 // https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
405 Matrix r(3, 3);
406 r(0,0) = cos(a);
407 r(0,1) = 0;
408 r(0,2) = sin(a);
409 r(1,0) = 0;
410 r(1,1) = 1;
411 r(1,2) = 0;
412 r(2,0) = -sin(a);
413 r(2,1) = 0;
414 r(2,2) = cos(a);
415 return r;
416 }
417
418
419 Matrix CreateRotationMatrixAlongZ(double a)
420 {
421 // Rotate along Z axis (R_z)
422 // https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
423 Matrix r(3, 3);
424 r(0,0) = cos(a);
425 r(0,1) = -sin(a);
426 r(0,2) = 0;
427 r(1,0) = sin(a);
428 r(1,1) = cos(a);
429 r(1,2) = 0;
430 r(2,0) = 0;
431 r(2,1) = 0;
432 r(2,2) = 1;
433 return r;
434 }
381 } 435 }
382 } 436 }