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?
(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 about plane orientationsā¦)
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.
I will be digging it on my end as well but Iād be great if you can give some advices.
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.
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 , 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.
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
IDEALLY
It is somewhat same issue as the first problem which is unsolved,
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) :
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:
(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ā¦)