# Stick model to other objects

**URL:** <https://forum.babylonjs.com/t/stick-model-to-other-objects/34334>\
**Category:** Questions\
**Created:** [September 29, 2022, 7:05am UTC](https://forum.babylonjs.com/t/stick-model-to-other-objects/34334 "2022-09-29T07:05:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zerq98](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zerq98/32/26228_2.png) [@zerq98](https://forum.babylonjs.com/u/zerq98)\
**Post date:** [September 29, 2022, 7:05am UTC](https://forum.babylonjs.com/t/stick-model-to-other-objects/34334/1 "2022-09-29T07:05:10Z")

</div>

Hi  
Is there any possible way to stick model to other objects in AR? What i mean? I have desk and when i place this desk near to wall, there is a gap beetwen desk and wall. I want that desk to be as close as in you can place desk in real life. 😃

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [September 29, 2022, 8:27am UTC](https://forum.babylonjs.com/t/stick-model-to-other-objects/34334/2 "2022-09-29T08:27:34Z")

</div>

> [@Mathematical Way/Tools I Used](https://forum.babylonjs.com/t/mathematical-way-tools-i-used/12032/21):
>
> hey @samevision sorry for late here is code for detect close point an the wall ( inside is allowed ) [https://www.babylonjs-playground.com/#Z2TXI0#2](https://www.babylonjs-playground.com/#Z2TXI0#2) ( inside and outside is allowed ) performance test : 400 check wall in same time you can detect a wall direction too [https://www.babylonjs-playground.com/#Z2TXI0#5](https://www.babylonjs-playground.com/#Z2TXI0#5) ( inside and outside is allowed ) under constriction [[BABYLONjs + Geometry Builder Setup Wall Profil] ](https://www.youtube.com/watch?v=_lZsOLrrwCY)

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#Z2TXI0%233)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

this code calculate touched position of wall live time without raycast

```auto
 var Edge = function (p1, p2, fun ,ref) {

    this.p1 = { x: p1.x, y: p1.y, z: p1.z ,h:p1.h};
    this.p2 = { x: p2.x, y: p2.y, z: p2.z ,h:p2.h};
    this.helper = [];
    this.ref = ref;
    if (fun) fun(this);

};
 Edge.prototype = {
    p1: {},
    p2: {},
    ref: {},
    helper: [],
    cross2D: function (p, inside, func,ref) {
        var th = this;
        var a = pow(pow(this.p1.x - p.x) + pow(this.p1.z - p.z), 0.5);
        var b = pow(pow(this.p2.x - p.x) + pow(this.p2.z - p.z), 0.5);
        var c = pow(pow(this.p2.x - this.p1.x) + pow(this.p2.z - this.p1.z), 0.5);

        var beta = acos((pow(a) + pow(c) - pow(b)) / ((2 * a * c) + 0.000001));

        var len = a * cos(beta);

        var pn = norm({ x: this.p2.x - this.p1.x, y: 0., z: this.p2.z - this.p1.z });
        pn.x *= len;
        pn.z *= len;

        var pn1 = { x: this.p1.x + pn.x, y: 0, z: this.p1.z + pn.z };

        if (inside) {
            var nrm1 = norm({ x: this.p1.x - pn1.x, y: 0., z: this.p1.z - pn1.z });
            var nrm2 = norm({ x: this.p2.x - pn1.x, y: 0., z: this.p2.z - pn1.z });

            var di = function (n) {
                return floor(n * 1.2 / (abs(n) + 0.0001));
            }

            if (di(nrm1.x) == di(nrm2.x) && di(nrm1.z) == di(nrm2.z)) {
                if (func) func(th); return null;
            }
        }

        var len1 = pow(pow(pn1.x - p.x) + pow(pn1.z - p.z), 0.5);
        if (func) func(th, pn1, len1,ref);

        return { point: pn1, length: len1 };
    }
};

    var WallDetails = function () { this.edgs = []; };
    WallDetails.prototype = {
        edgs: [],
        addEdge: function (p1, p2, fun, ref) {

            this.edgs.push(new Edge(p1, p2, fun, ref));
        }
    };

```
