# Normal vector for plane entity

**URL:** <https://community.cesium.com/t/normal-vector-for-plane-entity/18495>\
**Category:** CesiumJS\
**Created:** [May 9, 2022, 12:38am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495 "2022-05-09T00:38:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hiroshi\_Yaginuma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hiroshi_yaginuma/32/10887_2.png) [@Hiroshi\_Yaginuma](https://community.cesium.com/u/Hiroshi_Yaginuma)\
**Post date:** [May 9, 2022, 12:38am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/1 "2022-05-09T00:38:10Z")

</div>

Hi there,

I would like to ask how to get the normal vector correctly that is orthogonal to the line entity at the Z=0.

The normal vector will be given to the the plane entity.

This is what I want to make.

 ![image](https://global.discourse-cdn.com/cesium/original/2X/d/dfe9135a6d2f198f2fed153e768471643d6bb021.jpeg)

The code and result from my own trial,

![image](https://global.discourse-cdn.com/cesium/original/2X/0/014a2ffb578ce2f73a8bf494eaff8c0751b9d3ef.jpeg)

```auto

addPlane(twoPositions) {

        let mid = Cesium.Cartesian3.midpoint(twoPositions[0], twoPositions[1], new Cesium.Cartesian3());

        let p1 = Cesium.Cartesian3.normalize(twoPositions[0], new Cesium.Cartesian3());
        let p2 = Cesium.Cartesian3.normalize(twoPositions[1], new Cesium.Cartesian3());

        let lineVec = Cesium.Cartesian3.subtract(p2, p1, new Cesium.Cartesian3());

        let normal = Cesium.Cartesian3.cross(lineVec, Cesium.Cartesian3.UNIT_Z, new Cesium.Cartesian3());

        normal = Cesium.Cartesian3.normalize(normal.clone(), new Cesium.Cartesian3());

        let entity = new Cesium.Entity();
        entity.position = mid;
        entity.plane = {
            dimensions: new Cesium.Cartesian2(200, 200),
            plane: new Cesium.Plane(normal, 0),
            material: Cesium.Color.WHITE.withAlpha(0.5),
            outlineColor: Cesium.Color.BLACK,
            outlineWidth : 1
        }
        this._viewer.entities.add(entity);

    }

```

I tried to get the orthogonal vector from the vector that is along with the line by using cross product calculation.  
The plane should be parallel with the line as it should be given the orthogonal vector for normal.  
What might be missing here?

Thanks

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [May 10, 2022, 12:30am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/2 "2022-05-10T00:30:45Z")

</div>

A _very_ quick guess: Try adding

```auto
entity.orientation = Cesium.Quaternion.IDENTITY;

```

before passing the entity to the `viewer.entities`.

(Disclaimer: I have not tried it out, and would need to create a Sandcastle with your code first. But there seems to be some confusion about the plane orientation, and the symptoms that you described reminded me of [another question](https://community.cesium.com/t/plane-passing-throw-points/18329/2) about plane orientations…)

---

<div class="post-metadata">

**Author:** ![Hiroshi\_Yaginuma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hiroshi_yaginuma/32/10887_2.png) [@Hiroshi\_Yaginuma](https://community.cesium.com/u/Hiroshi_Yaginuma)\
**Post date:** [May 10, 2022, 2:47am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/3 "2022-05-10T02:47:22Z")

</div>

Thanks for the reply!  
It is deepening my grasp of the reference frame(orientations etc).

Just quick report about testing your suggestion.  
The plane aligned with the line entity, however, the Z axis orientation seems tilting to about 45 degrees from vertical line.

![image](https://global.discourse-cdn.com/cesium/original/2X/e/e4a60d030cb5086486cba4f9ff1a292dcc6d8998.jpeg)

I will be digging it on my end as well but I’d be great if you can give some advices.

---

<div class="post-metadata">

**Author:** ![Hiroshi\_Yaginuma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hiroshi_yaginuma/32/10887_2.png) [@Hiroshi\_Yaginuma](https://community.cesium.com/u/Hiroshi_Yaginuma)\
**Post date:** [May 10, 2022, 6:47am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/4 "2022-05-10T06:47:59Z")

</div>

Hi @Marco13 ,

Just to let you know my updates,  
I have found a way without using plane which is using the wall entity.

RESULT:  
 ![image](https://global.discourse-cdn.com/cesium/original/2X/a/a2e821362e78bd779bb2fb186d310409f864ecc5.jpeg)

```
    const wall= this._viewer.entities.add({
        name: "Cross profile",
        wall: {
            positions: twoPositions,
            material: Cesium.Color.SKYBLUE.withAlpha(0.3),
            outline: false,
            outlineColor: Cesium.Color.WHITE,
            outlineWidth: 1,
            minimumHeights: [hMin, hMin],
            maximumHeights: [hMax, hMax]
        },
    });

```

Thanks for helping me out.  
Nonetheless, I still want to know the solution when using the Plane entity for my further understanding of mathematics in cesium, so if you’d like to please give me the solution you come up with.

---

<div class="post-metadata">

**Author:** ![Hiroshi\_Yaginuma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hiroshi_yaginuma/32/10887_2.png) [@Hiroshi\_Yaginuma](https://community.cesium.com/u/Hiroshi_Yaginuma)\
**Post date:** [May 10, 2022, 11:54am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/5 "2022-05-10T11:54:29Z")

</div>

Hi @Marco13 ,

I actually confront to another issue that I need to get the orthogonal vector.

I hope I can get some advice from you.

The new issue is I need to crop the tileset using clippingPlane.  
I need to pass the normal vector to the clippingPlane

However, the outcome is similar to what I have described above.  
 ![image](https://global.discourse-cdn.com/cesium/original/2X/5/5cc10a96bfbb8974af4441f029a77e1d32aca6dc.png)

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [May 10, 2022, 2:21pm UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/6 "2022-05-10T14:21:35Z")

</div>

Sorry, there are a few things mixed here. I’m not sure whether the question now is about a `Plane` entity and its orientation. Or whether it is about a `Wall` entity a orthogonal (normal?) vector for that. Or whether it is about “clipping planes” (and I assume that this is not related to [the clipping plane example sandcastle](https://sandcastle.cesium.com/index.html?src=3D%20Tiles%20Clipping%20Planes.html) , but … it might be). I’m also not sooo deeply familiar with CesiumJS in particular, but would try to help finding answers to specific technical questions when I understand the intention or goal more clearly.

---

<div class="post-metadata">

**Author:** ![Hiroshi\_Yaginuma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hiroshi_yaginuma/32/10887_2.png) [@Hiroshi\_Yaginuma](https://community.cesium.com/u/Hiroshi_Yaginuma)\
**Post date:** [May 11, 2022, 12:40am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/7 "2022-05-11T00:40:05Z")

</div>

Sorry @Marco13 , I will give you the example code I’m working on.

So I pass four normal vector that has different directions to the ClippingPlaneCollection to clip the tileset.

```
    let lineVec = Cesium.Cartesian3.subtract(this.linePoints[1], this.linePoints[0], new Cesium.Cartesian3());
    let normalVec1 = Cesium.Cartesian3.cross(lineVec, Cesium.Cartesian3.UNIT_Z, new Cesium.Cartesian3());
    let normalVec2 = Cesium.Cartesian3.cross(normalVec1, Cesium.Cartesian3.UNIT_Z, new Cesium.Cartesian3());

    normalVec1 = Cesium.Cartesian3.normalize(normalVec1, new Cesium.Cartesian3());
    normalVec2 = Cesium.Cartesian3.normalize(normalVec2, new Cesium.Cartesian3());
    let centerPosition = Cesium.Cartesian3.midpoint(this.linePoints[0], this.linePoints[1], new Cesium.Cartesian3());

    let clippingPlane = new Cesium.ClippingPlaneCollection({
        planes: [
            new Cesium.ClippingPlane(
                normalVec1,
                5
            ),
            new Cesium.ClippingPlane(
                Cesium.Cartesian3.negate(normalVec1, new Cesium.Cartesian3()),
                5 ),
            new Cesium.ClippingPlane(
                normalVec2,
                5
            ),
            new Cesium.ClippingPlane(
                Cesium.Cartesian3.negate(normalVec2, new Cesium.Cartesian3()),
                5
            )
        ],
        enabled: true,
        unionClippingRegions: true,
        edgeWidth: 1.0,
        edgeColor: Cesium.Color.RED,
        modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(centerPosition)
    });

```

RESULT  
 ![image](https://global.discourse-cdn.com/cesium/original/3X/6/6/66077ffa4f5a7460392460eb9daa2234f435427a.png)

IDEALLY  
 ![image](https://global.discourse-cdn.com/cesium/original/2X/f/f99569109a2e32bdf25c01a71e5b07ce0750f47c.png)

It is somewhat same issue as the first problem which is unsolved,

![image](https://global.discourse-cdn.com/cesium/original/2X/0/014a2ffb578ce2f73a8bf494eaff8c0751b9d3ef.jpeg)

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [May 11, 2022, 9:36pm UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/8 "2022-05-11T21:36:59Z")

</div>

I see a short code snippet and two small images. Can you carve out the actual question and create a Sandcastle for that? Maybe this will make the intention clearer.

If there is a question about clipping planes, then this should probably be a separate question.

(The only thing that these questions seem to have in common is that there is some confusion about the coordinate systems, but it’s hard to make a more specific statement than that…)

I created a sandcastle (based on the ‘Sample Height from 3D Tiles’ Sandcastle) :

> **[Cesium Sandcastle](https://sandcastle.cesium.com/#c=7VnrUxs3EP9XVD6dJ0bcy48DkikB0jDDq+A0TepO57iTsdqzdCPpDE7G/3v1uLfPCaXTmX4AA0bSrvan365290xECRdgidEDYuA1IOgBHCOOswX8Rc9Z051Ij48pESEmiE13+uDrlAAgEGNy5prRJY4R2y8UI4ZCgT5SlsQTI2L1+lOy7h1MSaTN8QgRJK0Zs1AP5eKU4BmwftBDGCXhIp3Q9wjfz8VtlqaUCRT3jOkHTGL6AMMEMWGpCQCmO5M55uCO0QcujxJTxAGh0pZRBY39LigXJ0ieJ0ExnO6oHRS6tcJgIAq5xJGQIA2clOEFFniJOAzjWNuscWXevJOJ0bK+GkwZS0pWzii5QZxmLEJwxujiiEvBs9jy7fFwqPgBYN2bkp7mIacgXCAWQimnfGE2jREXmIQCU7LfQBBKejgOiZfz4bjO0HccaI/88WgUuEO/bxZ2/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MBbM7lZ1RQu9VY99lZbrzqmu+TpAo2rEKUtmhcYhk8yWjTMw/yHb7HX5E8TsmG9kNNHUs5Y6dZlD8ubJUdH6LLBE4TVZvV/om5C4pdbYlR7tv953edyrPP02GdaRPyYaVC2qauUXJv/6jdR9oRtTDiGd3BSrPA/VIPm2tLNsYUjneSuQjDJar9oF8OzTb7I4PwKtXuFdktzw/z2bmeQcDWSyNvV2Q+6rW43CYZnxubR5SPoulZSbqyCG1drRMK9pmOdzmE7NukKwNK/oByczDrU92VcjxfA8oix6xqpZfq6L4uJKrUn4nf215eWpyL+ZNQtVXV81pVJNavm1v+hv+vVEGyiagVZAAYPLxC297DrShq2qK+dUsLFur0s3pSUNwXRuti1govfCEg6Y0WSV4o5YWp+cdx28ACFk0WaWohHlkxvDy6vK0IfiAYzHfB+6W2luvoTmkq0yot4tc5prRFDHZCLQ4jhQxLZo+nZ6fX31sMtVkOEapmL+TYXjxHAhNBC1AT4ak/VQN6gArv5ZeLSbaT7Yb0Wn/3u+I2W1XY9fpEm8aXZcfvrRfL93Es7qJ5xUOLfud4vGvSodMbJ0V9T8rHf+jyrFJ3kuZeCkTL2WiKhOFhaIa7PR3DrlYJehNYfNHvNCf5WcssSDcE0jWBMkJ37vLor+QgBEvC8vhXl31MMZLgOPXHf/MUBg5lyuzLElu8Rc03XlzuCflN1QTqj/svloiloQrJTZ33pybSQjh4Z4cdmsK8yl0a+e/AQ)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

It takes the two points of the polyline, and creates a plane that is aligned with the plane that is created from these points. Comparing that to the first image that you posted, this could be _roughly_ what you want to achieve:

 ![Cesium Plane](https://global.discourse-cdn.com/cesium/original/3X/c/4/c4edb56b36b1a57e0c1c0cef568e3220521a5d16.jpeg)

(Aligning the plane and its size _perfectly_ with the exact polyline is trickier than it looks at the first glance. But maybe the code helps to solve the original question about the “Normal vector for plane entity”, at least…)

---

<div class="post-metadata">

**Author:** ![Hiroshi\_Yaginuma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hiroshi_yaginuma/32/10887_2.png) [@Hiroshi\_Yaginuma](https://community.cesium.com/u/Hiroshi_Yaginuma)\
**Post date:** [May 13, 2022, 12:14am UTC](https://community.cesium.com/t/normal-vector-for-plane-entity/18495/9 "2022-05-13T00:14:48Z")

</div>

Hi @Marco13 and thank you so much for the help.

the plane that is parallel to the line has solved.

However, I faced another issue again.

I have created another topic for this.

> [@Normal vector for clipping plane is not vertical from the ground](https://community.cesium.com/t/normal-vector-for-clipping-plane-is-not-vertical-from-the-ground/18571):
>
> Hi, I have a problem on giving the modelMatrix to the clipping plane. It should be clipped along with the green line but it is tilted as shown below. [image] I have a sandcastle replicated the issue but not completely as I cannot share the dataset. In sandcastle, it does not seem tilted because it is 3d model tileset but when you do it on point cloud tileset, you should the issue. This topic is related to this.
