| | 4344 | %%%% plans affines %%%% |
|---|
| | 4345 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| | 4346 | |
|---|
| | 4347 | %%%%% ### planaffine ### |
|---|
| | 4348 | %% plan : origine, base, range, ngrid |
|---|
| | 4349 | %% [0 0 0 [1 0 0 0 1 0] [-3 3 -2 2] [1. 1.] ] |
|---|
| | 4350 | |
|---|
| | 4351 | /explan [0 0 0 [1 0 0 0 1 0 0 0 1] [-3 3 -2 2] [1. 1.] ] def |
|---|
| | 4352 | |
|---|
| | 4353 | %% syntaxe : any isplan --> bool |
|---|
| | 4354 | /isplan { |
|---|
| | 4355 | 1 dict begin |
|---|
| | 4356 | /candidat exch def |
|---|
| | 4357 | candidat isarray { |
|---|
| | 4358 | candidat length 6 eq { |
|---|
| | 4359 | candidat 3 get isarray { |
|---|
| | 4360 | candidat 4 get isarray { |
|---|
| | 4361 | candidat 5 get isarray |
|---|
| | 4362 | } { |
|---|
| | 4363 | false |
|---|
| | 4364 | } ifelse |
|---|
| | 4365 | } { |
|---|
| | 4366 | false |
|---|
| | 4367 | } ifelse |
|---|
| | 4368 | } { |
|---|
| | 4369 | false |
|---|
| | 4370 | } ifelse |
|---|
| | 4371 | } { |
|---|
| | 4372 | false |
|---|
| | 4373 | } ifelse |
|---|
| | 4374 | end |
|---|
| | 4375 | } def |
|---|
| | 4376 | |
|---|
| | 4377 | /newplanaffine { |
|---|
| | 4378 | [0 0 0 [1 0 0 0 1 0] [-3 3 -2 2] [1 1]] |
|---|
| | 4379 | } def |
|---|
| | 4380 | |
|---|
| | 4381 | %% syntaxe : plantype getorigine --> x y z |
|---|
| | 4382 | /plangetorigine { |
|---|
| | 4383 | 1 dict begin |
|---|
| | 4384 | /plan exch def |
|---|
| | 4385 | plan isplan not { |
|---|
| | 4386 | (Erreur : mauvais type d argument dans plangetorigine) == |
|---|
| | 4387 | Error |
|---|
| | 4388 | } if |
|---|
| | 4389 | plan 0 get |
|---|
| | 4390 | plan 1 get |
|---|
| | 4391 | plan 2 get |
|---|
| | 4392 | end |
|---|
| | 4393 | } def |
|---|
| | 4394 | |
|---|
| | 4395 | %% syntaxe : plantype getbase --> [u v w] |
|---|
| | 4396 | %% ou u, v et w vecteurs de R^3 |
|---|
| | 4397 | /plangetbase { |
|---|
| | 4398 | 1 dict begin |
|---|
| | 4399 | /plan exch def |
|---|
| | 4400 | plan isplan not { |
|---|
| | 4401 | (Erreur : mauvais type d argument dans plangetbase) == |
|---|
| | 4402 | Error |
|---|
| | 4403 | } if |
|---|
| | 4404 | plan 3 get |
|---|
| | 4405 | end |
|---|
| | 4406 | } def |
|---|
| | 4407 | |
|---|
| | 4408 | %% syntaxe : plantype getrange --> array |
|---|
| | 4409 | %% ou array = [xmin xmax ymin ymax] |
|---|
| | 4410 | /plangetrange { |
|---|
| | 4411 | 1 dict begin |
|---|
| | 4412 | /plan exch def |
|---|
| | 4413 | plan isplan not { |
|---|
| | 4414 | (Erreur : mauvais type d argument dans plangetrange) == |
|---|
| | 4415 | Error |
|---|
| | 4416 | } if |
|---|
| | 4417 | plan 4 get |
|---|
| | 4418 | end |
|---|
| | 4419 | } def |
|---|
| | 4420 | |
|---|
| | 4421 | %% syntaxe : plantype getngrid --> array |
|---|
| | 4422 | %% ou array = [n1 n2] |
|---|
| | 4423 | /plangetngrid { |
|---|
| | 4424 | 1 dict begin |
|---|
| | 4425 | /plan exch def |
|---|
| | 4426 | plan isplan not { |
|---|
| | 4427 | (Erreur : mauvais type d argument dans plangetngrid) == |
|---|
| | 4428 | Error |
|---|
| | 4429 | } if |
|---|
| | 4430 | plan 5 get |
|---|
| | 4431 | end |
|---|
| | 4432 | } def |
|---|
| | 4433 | |
|---|
| | 4434 | %% =================== |
|---|
| | 4435 | |
|---|
| | 4436 | %% syntaxe : plantype x y z putorigine --> - |
|---|
| | 4437 | /planputorigine { |
|---|
| | 4438 | 4 dict begin |
|---|
| | 4439 | /z exch def |
|---|
| | 4440 | /y exch def |
|---|
| | 4441 | /x exch def |
|---|
| | 4442 | /plan exch def |
|---|
| | 4443 | plan isplan not { |
|---|
| | 4444 | (Erreur : mauvais type d argument dans planputorigine) == |
|---|
| | 4445 | Error |
|---|
| | 4446 | } if |
|---|
| | 4447 | plan 0 x put |
|---|
| | 4448 | plan 1 y put |
|---|
| | 4449 | plan 2 z put |
|---|
| | 4450 | end |
|---|
| | 4451 | } def |
|---|
| | 4452 | |
|---|
| | 4453 | %% syntaxe : plantype [u v w] putbase --> - |
|---|
| | 4454 | %% ou u, v et w vecteurs de R^3 |
|---|
| | 4455 | /planputbase { |
|---|
| | 4456 | 2 dict begin |
|---|
| | 4457 | /base exch def |
|---|
| | 4458 | /plan exch def |
|---|
| | 4459 | plan isplan not { |
|---|
| | 4460 | (Erreur : mauvais type d argument dans planputbase) == |
|---|
| | 4461 | Error |
|---|
| | 4462 | } if |
|---|
| | 4463 | plan 3 base put |
|---|
| | 4464 | end |
|---|
| | 4465 | } def |
|---|
| | 4466 | |
|---|
| | 4467 | %% syntaxe : plantype array putrange --> - |
|---|
| | 4468 | %% ou array = [xmin xmax ymin ymax] |
|---|
| | 4469 | /planputrange { |
|---|
| | 4470 | 2 dict begin |
|---|
| | 4471 | /table exch def |
|---|
| | 4472 | /plan exch def |
|---|
| | 4473 | plan isplan not { |
|---|
| | 4474 | (Erreur : mauvais type d argument dans planputrange) == |
|---|
| | 4475 | Error |
|---|
| | 4476 | } if |
|---|
| | 4477 | plan 4 table put |
|---|
| | 4478 | end |
|---|
| | 4479 | } def |
|---|
| | 4480 | |
|---|
| | 4481 | %% syntaxe : plantype array putngrid --> - |
|---|
| | 4482 | %% ou array = [n1 n2] |
|---|
| | 4483 | /planputngrid { |
|---|
| | 4484 | 2 dict begin |
|---|
| | 4485 | /table exch def |
|---|
| | 4486 | /plan exch def |
|---|
| | 4487 | plan isplan not { |
|---|
| | 4488 | (Erreur : mauvais type d argument dans planputngrid) == |
|---|
| | 4489 | quit |
|---|
| | 4490 | } if |
|---|
| | 4491 | plan 5 table put |
|---|
| | 4492 | end |
|---|
| | 4493 | } def |
|---|
| | 4494 | |
|---|
| | 4495 | %% -3 3 -2 2 1. 1. newgrille |
|---|
| | 4496 | %% drawsolid |
|---|
| | 4497 | |
|---|
| | 4498 | %orange |
|---|
| | 4499 | |
|---|
| | 4500 | %% plan : origine, base, range, ngrid |
|---|
| | 4501 | |
|---|
| | 4502 | %% syntaxe : plantype drawplanaffine --> - |
|---|
| | 4503 | /drawplanaffine { |
|---|
| | 4504 | 5 dict begin |
|---|
| | 4505 | /plan exch def |
|---|
| | 4506 | plan plangetbase |
|---|
| | 4507 | aload pop |
|---|
| | 4508 | /imK defpoint3d |
|---|
| | 4509 | /imJ defpoint3d |
|---|
| | 4510 | /imI defpoint3d |
|---|
| | 4511 | newpath |
|---|
| | 4512 | plan plangetrange plan plangetngrid aload pop quadrillagexOy_ |
|---|
| | 4513 | plan plangetorigine [imI imK] false planprojpath |
|---|
| | 4514 | stroke |
|---|
| | 4515 | end |
|---|
| | 4516 | } def |
|---|
| | 4517 | |
|---|
| | 4518 | |
|---|
| | 4519 | %% %% syntaxe : [a b c d] (x0 y0 z0) alpha defeqplanaffine --> plantype |
|---|
| | 4520 | %% %% plan defini par l equation ax+by+cz+d=0, |
|---|
| | 4521 | %% %% rotation de alpha autour de la normale (alpha est optionnel) |
|---|
| | 4522 | %% %% origine (x0, y0, z0). l origine est optionnelle |
|---|
| | 4523 | %% /defeqplanaffine { |
|---|
| | 4524 | %% 5 dict begin |
|---|
| | 4525 | %% dup isarray { |
|---|
| | 4526 | %% /alpha 0 def |
|---|
| | 4527 | %% } { |
|---|
| | 4528 | %% dup isstring { |
|---|
| | 4529 | %% /alpha 0 def |
|---|
| | 4530 | %% } { |
|---|
| | 4531 | %% /alpha exch def |
|---|
| | 4532 | %% } ifelse |
|---|
| | 4533 | %% } ifelse |
|---|
| | 4534 | %% dup isstring { |
|---|
| | 4535 | %% cvx /origine exch def |
|---|
| | 4536 | %% } if |
|---|
| | 4537 | %% /table exch def |
|---|
| | 4538 | %% table length 4 ne { |
|---|
| | 4539 | %% (Erreur : mauvais type d argument dans defeqplanaffine) == |
|---|
| | 4540 | %% Error |
|---|
| | 4541 | %% } if |
|---|
| | 4542 | %% table 0 get /a exch def |
|---|
| | 4543 | %% table 1 get /b exch def |
|---|
| | 4544 | %% table 2 get /c exch def |
|---|
| | 4545 | %% table 3 get /d exch def |
|---|
| | 4546 | %% /resultat newplanaffine def |
|---|
| | 4547 | %% [a b c alpha] normalvect_to_orthobase |
|---|
| | 4548 | %% /imK defpoint3d |
|---|
| | 4549 | %% /imJ defpoint3d |
|---|
| | 4550 | %% /imI defpoint3d |
|---|
| | 4551 | %% resultat [imI imJ imK] planputbase |
|---|
| | 4552 | %% currentdict /origine known { |
|---|
| | 4553 | %% origine /z exch def /y exch def /x exch def |
|---|
| | 4554 | %% a x mul b y mul add c z mul add d add 0 ne { |
|---|
| | 4555 | %% (Erreur : mauvaise origine dans defeqplanaffine) == |
|---|
| | 4556 | %% Error |
|---|
| | 4557 | %% } if |
|---|
| | 4558 | %% resultat origine planputorigine |
|---|
| | 4559 | %% } { |
|---|
| | 4560 | %% c 0 ne { |
|---|
| | 4561 | %% resultat 0 0 d neg c div planputorigine |
|---|
| | 4562 | %% } { |
|---|
| | 4563 | %% a 0 ne { |
|---|
| | 4564 | %% resultat d neg a div 0 0 planputorigine |
|---|
| | 4565 | %% } { |
|---|
| | 4566 | %% resultat 0 d neg b div 0 planputorigine |
|---|
| | 4567 | %% } ifelse |
|---|
| | 4568 | %% } ifelse |
|---|
| | 4569 | %% } ifelse |
|---|
| | 4570 | %% resultat |
|---|
| | 4571 | %% end |
|---|
| | 4572 | %% } def |
|---|
| | 4573 | |
|---|
| | 4574 | %% /explan [0 0 0 [1 0 0 0 1 0 0 0 1] [-3 3 -2 2] [1 1] ] def |
|---|
| | 4575 | %% explan drawplanaffine |
|---|
| | 4576 | %% noir |
|---|
| | 4577 | %% /explan [0 0 2 [1 0 0 0 1 0 0 0 1] [-3 3 -2 2] [1 .5] ] def |
|---|
| | 4578 | %% explan drawplanaffine |
|---|
| | 4579 | |
|---|
| | 4580 | %% orange |
|---|
| | 4581 | %% [0 0 1 -2] defeqplanaffine |
|---|
| | 4582 | %% drawplanaffine |
|---|
| | 4583 | %% noir |
|---|
| | 4584 | %% [0 0 1 0] defeqplanaffine |
|---|
| | 4585 | %% drawplanaffine |
|---|
| | 4586 | %% bleu |
|---|
| | 4587 | %% [1 1 1 0] (1 -1 0) defeqplanaffine |
|---|
| | 4588 | %% drawplanaffine |
|---|
| | 4589 | %% |
|---|
| | 4590 | |
|---|
| | 4591 | /dessinebase { |
|---|
| | 4592 | 4 dict begin |
|---|
| | 4593 | gsave |
|---|
| | 4594 | /V3 defpoint3d |
|---|
| | 4595 | /V2 defpoint3d |
|---|
| | 4596 | /V1 defpoint3d |
|---|
| | 4597 | /M0 defpoint3d |
|---|
| | 4598 | rouge |
|---|
| | 4599 | V3 newvecteur |
|---|
| | 4600 | {M0 translatepoint3d} solidtransform |
|---|
| | 4601 | drawsolid** |
|---|
| | 4602 | bleu |
|---|
| | 4603 | V2 newvecteur |
|---|
| | 4604 | {M0 translatepoint3d} solidtransform |
|---|
| | 4605 | drawsolid** |
|---|
| | 4606 | orange |
|---|
| | 4607 | V1 newvecteur |
|---|
| | 4608 | {M0 translatepoint3d} solidtransform |
|---|
| | 4609 | drawsolid** |
|---|
| | 4610 | grestore |
|---|
| | 4611 | end |
|---|
| | 4612 | } def |
|---|
| | 4613 | |
|---|
| | 4614 | %% syntaxe : solid i solidface2eqplan --> [a b c d] |
|---|
| | 4615 | %% equation cartesienne de la face d'indice i du solide solid |
|---|
| | 4616 | /solidface2eqplan { |
|---|
| | 4617 | 8 dict begin |
|---|
| | 4618 | /i exch def |
|---|
| | 4619 | /solid exch def |
|---|
| | 4620 | solid i solidnormaleface |
|---|
| | 4621 | /c exch def |
|---|
| | 4622 | /b exch def |
|---|
| | 4623 | /a exch def |
|---|
| | 4624 | solid 0 i solidgetsommetface |
|---|
| | 4625 | /z exch def |
|---|
| | 4626 | /y exch def |
|---|
| | 4627 | /x exch def |
|---|
| | 4628 | [a b c a x mul b y mul add c z mul add neg] |
|---|
| | 4629 | end |
|---|
| | 4630 | } def |
|---|
| | 4631 | |
|---|
| | 4632 | |
|---|
| | 4633 | %% syntaxe : plantype newplan --> solid |
|---|
| | 4634 | /newplan { |
|---|
| | 4635 | 5 dict begin |
|---|
| | 4636 | /lepl@n exch def |
|---|
| | 4637 | lepl@n plangetbase /@base exch def |
|---|
| | 4638 | @base 0 getp3d /@U defpoint3d |
|---|
| | 4639 | @base 1 getp3d /@V defpoint3d |
|---|
| | 4640 | lepl@n plangetorigine /@M defpoint3d |
|---|
| | 4641 | lepl@n plangetrange /@range exch def |
|---|
| | 4642 | lepl@n plangetngrid /@ngrid exch def |
|---|
| | 4643 | /@F { |
|---|
| | 4644 | 2 dict begin |
|---|
| | 4645 | /@y exch def |
|---|
| | 4646 | /@x exch def |
|---|
| | 4647 | @U @x mulv3d |
|---|
| | 4648 | @V @y mulv3d |
|---|
| | 4649 | addv3d |
|---|
| | 4650 | @M addv3d |
|---|
| | 4651 | end |
|---|
| | 4652 | } def |
|---|
| | 4653 | @range aload pop @ngrid {@F} newsurfaceparametree |
|---|
| | 4654 | end |
|---|
| | 4655 | } def |
|---|
| | 4656 | |
|---|
| | 4657 | %% syntaxe : M eqplan --> real |
|---|
| | 4658 | %% image de M par la fonction definie par l equation eqplan |
|---|
| | 4659 | /pointeqplan { |
|---|
| | 4660 | 8 dict begin |
|---|
| | 4661 | /eqplan exch def |
|---|
| | 4662 | /@z exch def |
|---|
| | 4663 | /@y exch def |
|---|
| | 4664 | /@x exch def |
|---|
| | 4665 | /@a eqplan 0 get def |
|---|
| | 4666 | /@b eqplan 1 get def |
|---|
| | 4667 | /@c eqplan 2 get def |
|---|
| | 4668 | /@d eqplan 3 get def |
|---|
| | 4669 | @a @x mul @b @y mul add @c @z mul add @d add |
|---|
| | 4670 | end |
|---|
| | 4671 | } def |
|---|
| | 4672 | |
|---|
| | 4673 | %% syntaxe : [a b c d] (x0 y0 z0) alpha defeqplanaffine --> plantype |
|---|
| | 4674 | %% plan defini par l equation ax+by+cz+d=0, |
|---|
| | 4675 | %% rotation de alpha autour de la normale (alpha est optionnel) |
|---|
| | 4676 | %% origine (x0, y0, z0). l origine est optionnelle |
|---|
| | 4677 | /eq2plan { |
|---|
| | 4678 | 5 dict begin |
|---|
| | 4679 | dup isarray { |
|---|
| | 4680 | /alpha 0 def |
|---|
| | 4681 | } { |
|---|
| | 4682 | dup isstring { |
|---|
| | 4683 | /alpha 0 def |
|---|
| | 4684 | } { |
|---|
| | 4685 | /alpha exch def |
|---|
| | 4686 | } ifelse |
|---|
| | 4687 | } ifelse |
|---|
| | 4688 | dup isstring { |
|---|
| | 4689 | cvx /origine exch def |
|---|
| | 4690 | } if |
|---|
| | 4691 | /table exch def |
|---|
| | 4692 | table length 4 ne { |
|---|
| | 4693 | (Erreur : mauvais type d argument dans eq2plan) == |
|---|
| | 4694 | quit |
|---|
| | 4695 | } if |
|---|
| | 4696 | table 0 get /a exch def |
|---|
| | 4697 | table 1 get /b exch def |
|---|
| | 4698 | table 2 get /c exch def |
|---|
| | 4699 | table 3 get /d exch def |
|---|
| | 4700 | /resultat newplanaffine def |
|---|
| | 4701 | [a b c alpha] normalvect_to_orthobase |
|---|
| | 4702 | /imK defpoint3d |
|---|
| | 4703 | /imJ defpoint3d |
|---|
| | 4704 | /imI defpoint3d |
|---|
| | 4705 | resultat [imI imJ imK] planputbase |
|---|
| | 4706 | currentdict /origine known { |
|---|
| | 4707 | origine /z exch def /y exch def /x exch def |
|---|
| | 4708 | a x mul b y mul add c z mul add d add 0 ne { |
|---|
| | 4709 | (Erreur : mauvaise origine dans eq2plan) == |
|---|
| | 4710 | quit |
|---|
| | 4711 | } if |
|---|
| | 4712 | resultat origine planputorigine |
|---|
| | 4713 | } { |
|---|
| | 4714 | c 0 ne { |
|---|
| | 4715 | resultat 0 0 d neg c div planputorigine |
|---|
| | 4716 | } { |
|---|
| | 4717 | a 0 ne { |
|---|
| | 4718 | resultat d neg a div 0 0 planputorigine |
|---|
| | 4719 | } { |
|---|
| | 4720 | b 0 ne { |
|---|
| | 4721 | resultat 0 d neg b div 0 planputorigine |
|---|
| | 4722 | } { |
|---|
| | 4723 | (Error dans eq2plan : (a,b,c) = (0,0,0)) == |
|---|
| | 4724 | } ifelse |
|---|
| | 4725 | } ifelse |
|---|
| | 4726 | } ifelse |
|---|
| | 4727 | } ifelse |
|---|
| | 4728 | resultat |
|---|
| | 4729 | end |
|---|
| | 4730 | } def |
|---|
| | 4731 | |
|---|
| | 4732 | /points2eqplan { |
|---|
| | 4733 | 10 dict begin |
|---|
| | 4734 | /C defpoint3d |
|---|
| | 4735 | /B defpoint3d |
|---|
| | 4736 | /A defpoint3d |
|---|
| | 4737 | A B vecteur3d |
|---|
| | 4738 | A C vecteur3d |
|---|
| | 4739 | vectprod3d |
|---|
| | 4740 | normalize3d |
|---|
| | 4741 | /c exch def |
|---|
| | 4742 | /b exch def |
|---|
| | 4743 | /a exch def |
|---|
| | 4744 | A |
|---|
| | 4745 | /zA exch def |
|---|
| | 4746 | /yA exch def |
|---|
| | 4747 | /xA exch def |
|---|
| | 4748 | [a b c a xA mul b yA mul add c zA mul add neg] |
|---|
| | 4749 | end |
|---|
| | 4750 | } def |
|---|
| | 4751 | |
|---|
| | 4752 | %% /monplan |
|---|
| | 4753 | %% %[0 0 -2 [1 0 0 0 1 0 0 0 1] [-3 3 -2 2] [1. 1.]] |
|---|
| | 4754 | %% [0 0 1 1] 30 eq2plan |
|---|
| | 4755 | %% def |
|---|
| | 4756 | %% |
|---|
| | 4757 | %% [0 0 1 -2] eq2plan newplan |
|---|
| | 4758 | %% dup (blanc) outputcolors |
|---|
| | 4759 | %% monplan newplan |
|---|
| | 4760 | %% dup (blanc) outputcolors |
|---|
| | 4761 | %% solidfuz |
|---|
| | 4762 | %% drawsolid** |
|---|
| | 4763 | %% monplan plangetorigine |
|---|
| | 4764 | %% monplan plangetbase aload pop dessinebase |
|---|
| | 4765 | |
|---|
| | 4766 | %% syntaxe : x0 y0 z0 [normalvect] norm2plan |
|---|
| | 4767 | /norm2plan { |
|---|
| | 4768 | 9 dict begin |
|---|
| | 4769 | normalvect_to_orthobase |
|---|
| | 4770 | /imK defpoint3d |
|---|
| | 4771 | /imJ defpoint3d |
|---|
| | 4772 | /imI defpoint3d |
|---|
| | 4773 | imK |
|---|
| | 4774 | /c exch def |
|---|
| | 4775 | /b exch def |
|---|
| | 4776 | /a exch def |
|---|
| | 4777 | /z0 exch def |
|---|
| | 4778 | /y0 exch def |
|---|
| | 4779 | /x0 exch def |
|---|
| | 4780 | [a b c a x0 mul b y0 mul add c z0 mul add neg] eq2plan |
|---|
| | 4781 | dup x0 y0 z0 planputorigine |
|---|
| | 4782 | dup [imI imJ] planputbase |
|---|
| | 4783 | end |
|---|
| | 4784 | } def |
|---|
| | 4785 | |
|---|
| | 4786 | %% syntaxe : plantype planxmarks |
|---|
| | 4787 | /planxmarks { |
|---|
| | 4788 | 5 dict begin |
|---|
| | 4789 | /leplan exch def |
|---|
| | 4790 | leplan plangetrange aload pop |
|---|
| | 4791 | /ymax exch def |
|---|
| | 4792 | /ymin exch def |
|---|
| | 4793 | /xmax exch def |
|---|
| | 4794 | /xmin exch def |
|---|
| | 4795 | xmin truncate cvi xmkstep xmax truncate cvi { |
|---|
| | 4796 | dup 0 ne { |
|---|
| | 4797 | dup chaine cvs exch 0 leplan dctextp3d |
|---|
| | 4798 | } { |
|---|
| | 4799 | pop |
|---|
| | 4800 | } ifelse |
|---|
| | 4801 | } for |
|---|
| | 4802 | end |
|---|
| | 4803 | } def |
|---|
| | 4804 | |
|---|
| | 4805 | %% syntaxe : plantype planymarks |
|---|
| | 4806 | /planymarks { |
|---|
| | 4807 | 5 dict begin |
|---|
| | 4808 | /leplan exch def |
|---|
| | 4809 | leplan plangetrange aload pop |
|---|
| | 4810 | /ymax exch def |
|---|
| | 4811 | /ymin exch def |
|---|
| | 4812 | /xmax exch def |
|---|
| | 4813 | /xmin exch def |
|---|
| | 4814 | ymin truncate cvi ymkstep ymax truncate cvi { |
|---|
| | 4815 | dup 0 ne { |
|---|
| | 4816 | dup chaine cvs exch 0 exch leplan cltextp3d |
|---|
| | 4817 | } { |
|---|
| | 4818 | pop |
|---|
| | 4819 | } ifelse |
|---|
| | 4820 | } for |
|---|
| | 4821 | end |
|---|
| | 4822 | } def |
|---|
| | 4823 | |
|---|
| | 4824 | %% syntaxe : plantype planmarks |
|---|
| | 4825 | /planmarks { |
|---|
| | 4826 | dup planxmarks planymarks |
|---|
| | 4827 | } def |
|---|
| | 4828 | |
|---|
| | 4829 | %% bleu |
|---|
| | 4830 | %% [-3 3 -2 2] quadrillagexOy_ |
|---|
| | 4831 | %% stroke |
|---|
| | 4832 | %% noir |
|---|
| | 4833 | |
|---|
| | 4834 | %% syntaxe : [xmin xmax ymin ymax] dx dy quadrillagexOy_ |
|---|
| | 4835 | /quadrillagexOy_ { |
|---|
| | 4836 | 4 dict begin |
|---|
| | 4837 | dup isarray { |
|---|
| | 4838 | /dx 1 def |
|---|
| | 4839 | /dy 1 def |
|---|
| | 4840 | } { |
|---|
| | 4841 | /dy exch def |
|---|
| | 4842 | dup isarray { |
|---|
| | 4843 | /dx dy def |
|---|
| | 4844 | } { |
|---|
| | 4845 | /dx exch def |
|---|
| | 4846 | } ifelse |
|---|
| | 4847 | } ifelse |
|---|
| | 4848 | /table exch def |
|---|
| | 4849 | table 0 get /xmin exch def |
|---|
| | 4850 | table 1 get /xmax exch def |
|---|
| | 4851 | table 2 get /ymin exch def |
|---|
| | 4852 | table 3 get /ymax exch def |
|---|
| | 4853 | ymin dy ymax { |
|---|
| | 4854 | /y exch def |
|---|
| | 4855 | xmin y smoveto |
|---|
| | 4856 | xmax y slineto |
|---|
| | 4857 | } for |
|---|
| | 4858 | xmin dx xmax { |
|---|
| | 4859 | /x exch def |
|---|
| | 4860 | x ymin smoveto |
|---|
| | 4861 | x ymax slineto |
|---|
| | 4862 | } for |
|---|
| | 4863 | end |
|---|
| | 4864 | } def |
|---|
| | 4865 | |
|---|
| | 4866 | %%%%% ### fin insertion ### |
|---|
| | 4867 | |
|---|
| | 4868 | |
|---|
| | 4869 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| | 4872 | |
|---|
| | 4873 | %%%%% ### solidplansection ### |
|---|
| | 4874 | %% syntaxe : M eqplan --> real |
|---|
| | 4875 | %% image de M par la fonction definie par l equation eqplan |
|---|
| | 4876 | /pointeqplan { |
|---|
| | 4877 | 8 dict begin |
|---|
| | 4878 | /@qplan exch def |
|---|
| | 4879 | /@z exch def |
|---|
| | 4880 | /@y exch def |
|---|
| | 4881 | /@x exch def |
|---|
| | 4882 | /@a @qplan 0 get def |
|---|
| | 4883 | /@b @qplan 1 get def |
|---|
| | 4884 | /@c @qplan 2 get def |
|---|
| | 4885 | /@d @qplan 3 get def |
|---|
| | 4886 | @a @x mul @b @y mul add @c @z mul add @d add |
|---|
| | 4887 | end |
|---|
| | 4888 | } def |
|---|
| | 4889 | |
|---|
| | 4890 | %% syntaxe : A B eqplan segment_inter_plan --> array true ou false |
|---|
| | 4891 | %% array contient 1 point M si [AB] inter plan = {M} |
|---|
| | 4892 | %% array contient les 2 points A et B si [AB] inter plan = [AB] |
|---|
| | 4893 | /segment_inter_plan { |
|---|
| | 4894 | 4 dict begin |
|---|
| | 4895 | /plan exch def |
|---|
| | 4896 | plan aload pop |
|---|
| | 4897 | /d exch def |
|---|
| | 4898 | /c exch def |
|---|
| | 4899 | /b exch def |
|---|
| | 4900 | /a exch def |
|---|
| | 4901 | /B defpoint3d |
|---|
| | 4902 | /A defpoint3d |
|---|
| | 4903 | A |
|---|
| | 4904 | /zA exch def |
|---|
| | 4905 | /yA exch def |
|---|
| | 4906 | /xA exch def |
|---|
| | 4907 | B |
|---|
| | 4908 | /zB exch def |
|---|
| | 4909 | /yB exch def |
|---|
| | 4910 | /xB exch def |
|---|
| | 4911 | /imA a xA mul b yA mul add c zA mul add d add def |
|---|
| | 4912 | /imB a xB mul b yB mul add c zB mul add d add def |
|---|
| | 4913 | imA imB mul dup 0 gt { |
|---|
| | 4914 | %% pas d intersection |
|---|
| | 4915 | pop |
|---|
| | 4916 | false |
|---|
| | 4917 | } { |
|---|
| | 4918 | 0 eq { |
|---|
| | 4919 | %% intersection en A ou en B |
|---|
| | 4920 | [ |
|---|
| | 4921 | imA 0 eq {A} if |
|---|
| | 4922 | imB 0 eq {B} if |
|---|
| | 4923 | ] true |
|---|
| | 4924 | } { |
|---|
| | 4925 | %% intersection entre A et B |
|---|
| | 4926 | /k |
|---|
| | 4927 | imA neg |
|---|
| | 4928 | xB xA sub a mul |
|---|
| | 4929 | yB yA sub b mul add |
|---|
| | 4930 | zB zA sub c mul add |
|---|
| | 4931 | dup 0 eq { |
|---|
| | 4932 | (Error dans segment_inter_plan) == |
|---|
| | 4933 | quit |
|---|
| | 4934 | } if |
|---|
| | 4935 | div |
|---|
| | 4936 | def |
|---|
| | 4937 | [ |
|---|
| | 4938 | A B vecteur3d |
|---|
| | 4939 | k mulv3d |
|---|
| | 4940 | A addv3d |
|---|
| | 4941 | ] true |
|---|
| | 4942 | } ifelse |
|---|
| | 4943 | } ifelse |
|---|
| | 4944 | end |
|---|
| | 4945 | } def |
|---|
| | 4946 | |
|---|
| | 4947 | %% syntaxe : solid i solidface2eqplan --> [a b c d] |
|---|
| | 4948 | %% equation cartesienne de la face d'indice i du solide solid |
|---|
| | 4949 | /solidface2eqplan { |
|---|
| | 4950 | 8 dict begin |
|---|
| | 4951 | /i exch def |
|---|
| | 4952 | /solid exch def |
|---|
| | 4953 | solid i solidnormaleface |
|---|
| | 4954 | /c exch def |
|---|
| | 4955 | /b exch def |
|---|
| | 4956 | /a exch def |
|---|
| | 4957 | solid 0 i solidgetsommetface |
|---|
| | 4958 | /z exch def |
|---|
| | 4959 | /y exch def |
|---|
| | 4960 | /x exch def |
|---|
| | 4961 | [a b c a x mul b y mul add c z mul add neg] |
|---|
| | 4962 | end |
|---|
| | 4963 | } def |
|---|
| | 4964 | |
|---|
| | 4965 | %% syntaxe : solid eqplan solidplansection --> solid2 |
|---|
| | 4966 | /solidplansection { |
|---|
| | 4967 | 10 dict begin |
|---|
| | 4968 | /eqplan exch def |
|---|
| | 4969 | dupsolid /result exch def |
|---|
| | 4970 | /solid exch def |
|---|
| | 4971 | /aenlever [] def |
|---|
| | 4972 | %(nombre faces) == |
|---|
| | 4973 | %solid solidnombrefaces == |
|---|
| | 4974 | 0 1 solid solidnombrefaces 1 sub { |
|---|
| | 4975 | /i exch def |
|---|
| | 4976 | /lacouleur solid i solidgetfcolor def |
|---|
| | 4977 | %(NOUVELLE FACE) == i == |
|---|
| | 4978 | /F solid i solidgetface def %% table des indices |
|---|
| | 4979 | /n F length def %% nb d'aretes |
|---|
| | 4980 | /k1 -1 def |
|---|
| | 4981 | /k2 -1 def |
|---|
| | 4982 | /k3 -1 def |
|---|
| | 4983 | /k4 -1 def |
|---|
| | 4984 | /k3a -3 def |
|---|
| | 4985 | /k4a -3 def |
|---|
| | 4986 | %% pour chaque arete [AB] |
|---|
| | 4987 | 0 1 n 1 sub { |
|---|
| | 4988 | /j exch def |
|---|
| | 4989 | %(nvell arete) == j == |
|---|
| | 4990 | solid j i solidgetsommetface /A defpoint3d |
|---|
| | 4991 | solid j 1 add n mod i solidgetsommetface /B defpoint3d |
|---|
| | 4992 | %% y a-t-il intersection |
|---|
| | 4993 | A B eqplan segment_inter_plan { |
|---|
| | 4994 | %(inter) == |
|---|
| | 4995 | dup length 6 eq { |
|---|
| | 4996 | /k1 -1 def |
|---|
| | 4997 | /k2 -1 def |
|---|
| | 4998 | /k3 -1 def |
|---|
| | 4999 | /k4 -1 def |
|---|
| | 5000 | /k3a -1 def |
|---|
| | 5001 | /k4a -1 def |
|---|
| | 5002 | exit %% c est deja scinde |
|---|
| | 5003 | } if |
|---|
| | 5004 | k1 0 lt { |
|---|
| | 5005 | %% 1ere intersection de la face |
|---|
| | 5006 | /k1 j def |
|---|
| | 5007 | result exch aload pop solidaddsommet |
|---|
| | 5008 | /k1a exch def |
|---|
| | 5009 | } { |
|---|
| | 5010 | k2 0 lt { |
|---|
| | 5011 | %% 2eme intersection de la face |
|---|
| | 5012 | /k2 j def |
|---|
| | 5013 | result exch aload pop solidaddsommet |
|---|
| | 5014 | /k2a exch def |
|---|
| | 5015 | } { |
|---|
| | 5016 | k3 0 lt { |
|---|
| | 5017 | %% 3eme intersection de la face |
|---|
| | 5018 | /k3 j def |
|---|
| | 5019 | result exch aload pop solidaddsommet |
|---|
| | 5020 | /k3a exch def |
|---|
| | 5021 | } { |
|---|
| | 5022 | %% 4eme intersection de la face |
|---|
| | 5023 | /k4 j def |
|---|
| | 5024 | result exch aload pop solidaddsommet |
|---|
| | 5025 | /k4a exch def |
|---|
| | 5026 | } ifelse |
|---|
| | 5027 | } ifelse |
|---|
| | 5028 | } ifelse |
|---|
| | 5029 | } if |
|---|
| | 5030 | } for |
|---|
| | 5031 | %% y a-t-il une coupe ? |
|---|
| | 5032 | k1 0 ge { |
|---|
| | 5033 | %% (coupe) == |
|---|
| | 5034 | %% (n) == n == |
|---|
| | 5035 | %% k1 == k2 == k3 == k4 == |
|---|
| | 5036 | %% (a) == |
|---|
| | 5037 | %% k1a == k2a == k3a == k4a == |
|---|
| | 5038 | k1a k2a eq k3 0 lt and { |
|---|
| | 5039 | } { |
|---|
| | 5040 | k1a k2a eq k3 0 ge and { |
|---|
| | 5041 | /k2a k3a def |
|---|
| | 5042 | /k2 k3 def |
|---|
| | 5043 | } if |
|---|
| | 5044 | k1a k3a eq k4 0 ge and { |
|---|
| | 5045 | /k2a k4a def |
|---|
| | 5046 | /k2 k4 def |
|---|
| | 5047 | } if |
|---|
| | 5048 | [ |
|---|
| | 5049 | k1a F k1 1 add n mod get ne { |
|---|
| | 5050 | k1a |
|---|
| | 5051 | } if |
|---|
| | 5052 | k1 1 add n mod 1 k2 {F exch get} for |
|---|
| | 5053 | k2a F k2 get ne { |
|---|
| | 5054 | k2a |
|---|
| | 5055 | } if |
|---|
| | 5056 | ] |
|---|
| | 5057 | result exch lacouleur solidaddface |
|---|
| | 5058 | [ |
|---|
| | 5059 | k2a F k2 1 add n mod get ne { |
|---|
| | 5060 | k2a |
|---|
| | 5061 | } if |
|---|
| | 5062 | k2 1 add n ne { |
|---|
| | 5063 | k2 1 add n mod 1 n 1 sub {F exch get} for |
|---|
| | 5064 | } if |
|---|
| | 5065 | 0 1 k1 {F exch get} for |
|---|
| | 5066 | k1a F k1 get ne { |
|---|
| | 5067 | k1a |
|---|
| | 5068 | } if |
|---|
| | 5069 | ] |
|---|
| | 5070 | result exch lacouleur solidaddface |
|---|
| | 5071 | /aenlever [aenlever aload pop i] store |
|---|
| | 5072 | } ifelse |
|---|
| | 5073 | } if |
|---|
| | 5074 | } for |
|---|
| | 5075 | result aenlever solidrmfaces |
|---|
| | 5076 | result |
|---|
| | 5077 | end |
|---|
| | 5078 | } def |
|---|
| | 5079 | |
|---|
| | 5080 | %% syntaxe : solid eqplan solideqplansepare --> solid1 solid2 |
|---|
| | 5081 | /solideqplansepare { |
|---|
| | 5082 | 10 dict begin |
|---|
| | 5083 | /eqplan exch def |
|---|
| | 5084 | eqplan solidplansection |
|---|
| | 5085 | /solid exch def |
|---|
| | 5086 | /n solid solidnombrefaces def |
|---|
| | 5087 | /lesneg [] def |
|---|
| | 5088 | /lespos [] def |
|---|
| | 5089 | 0 1 n 1 sub { |
|---|
| | 5090 | /i exch def |
|---|
| | 5091 | solid i solidcentreface /G defpoint3d |
|---|
| | 5092 | G eqplan pointeqplan dup 0 gt { |
|---|
| | 5093 | pop |
|---|
| | 5094 | /lespos [lespos aload pop i] store |
|---|
| | 5095 | } { |
|---|
| | 5096 | 0 lt { |
|---|
| | 5097 | /lesneg [lesneg aload pop i] store |
|---|
| | 5098 | } { |
|---|
| | 5099 | /lesneg [lesneg aload pop i] store |
|---|
| | 5100 | /lespos [lespos aload pop i] store |
|---|
| | 5101 | } ifelse |
|---|
| | 5102 | } ifelse |
|---|
| | 5103 | } for |
|---|
| | 5104 | solid |
|---|
| | 5105 | dupsolid dup lesneg solidrmfaces |
|---|
| | 5106 | /result1 exch def |
|---|
| | 5107 | dupsolid dup lespos solidrmfaces |
|---|
| | 5108 | /result2 exch def |
|---|
| | 5109 | pop |
|---|
| | 5110 | /sommetspos [] def |
|---|
| | 5111 | /sommetsneg [] def |
|---|
| | 5112 | %% pour chaque face du cote negatif |
|---|
| | 5113 | 0 1 lesneg length 1 sub { |
|---|
| | 5114 | lesneg exch get /i exch def |
|---|
| | 5115 | /F solid i solidgetface def |
|---|
| | 5116 | %% pour chaque sommet de cette face |
|---|
| | 5117 | 0 1 F length 1 sub { |
|---|
| | 5118 | /j exch def |
|---|
| | 5119 | /sommet F j get def |
|---|
| | 5120 | %% si le sommet n'est pas encore note |
|---|
| | 5121 | sommet sommetsneg in not { |
|---|
| | 5122 | %% et s'il est isole, on peut l'enlever |
|---|
| | 5123 | result1 sommet solidsommetsadjsommet length 0 eq { |
|---|
| | 5124 | /sommetsneg [sommetsneg aload pop sommet] store |
|---|
| | 5125 | } if |
|---|
| | 5126 | } { |
|---|
| | 5127 | pop |
|---|
| | 5128 | } ifelse |
|---|
| | 5129 | } for |
|---|
| | 5130 | } for |
|---|
| | 5131 | sommetsneg bubblesort reverse {result1 exch solidrmsommet} apply |
|---|
| | 5132 | |
|---|
| | 5133 | %% pour chaque face du cote positif |
|---|
| | 5134 | 0 1 lespos length 1 sub { |
|---|
| | 5135 | lespos exch get /i exch def |
|---|
| | 5136 | /F solid i solidgetface def |
|---|
| | 5137 | %% pour chaque sommet de cette face |
|---|
| | 5138 | 0 1 F length 1 sub { |
|---|
| | 5139 | /j exch def |
|---|
| | 5140 | /sommet F j get def |
|---|
| | 5141 | %% si le sommet n'est pas encore note |
|---|
| | 5142 | sommet sommetspos in not { |
|---|
| | 5143 | %% et s'il est isole, on peut l'enlever |
|---|
| | 5144 | result2 sommet solidsommetsadjsommet length 0 eq { |
|---|
| | 5145 | /sommetspos [sommetspos aload pop sommet] store |
|---|
| | 5146 | } if |
|---|
| | 5147 | } { |
|---|
| | 5148 | pop |
|---|
| | 5149 | } ifelse |
|---|
| | 5150 | } for |
|---|
| | 5151 | } for |
|---|
| | 5152 | sommetspos bubblesort reverse {result2 exch solidrmsommet} apply |
|---|
| | 5153 | |
|---|
| | 5154 | result1 result2 |
|---|
| | 5155 | end |
|---|
| | 5156 | } def |
|---|