How to use the @bentley/geometry-core.Vector3d.createStartEnd function in @bentley/geometry-core

To help you get started, we’ve selected a few @bentley/geometry-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / test-apps / ui-test-app / src / frontend / tools / MeasurePoints.ts View on Github external
public setupAndPromptForNextAction(): void {
    IModelApp.accuSnap.enableSnap(true);

    if (0 === this.points.length) {
      IModelApp.notifications.outputPromptByKey("SampleApp:tools.Measure.ByPoints.Prompts.FirstPoint");
      return;
    }

    IModelApp.notifications.outputPromptByKey("SampleApp:tools.Measure.ByPoints.Prompts.NextPoint");

    const hints = new AccuDrawHintBuilder();
    hints.enableSmartRotation = true;

    if (this.points.length > 1 && !(this.points[this.points.length - 1].isAlmostEqual(this.points[this.points.length - 2])))
      hints.setXAxis(Vector3d.createStartEnd(this.points[this.points.length - 2], this.points[this.points.length - 1])); // Rotate AccuDraw to last segment...

    hints.setOrigin(this.points[this.points.length - 1]);
    hints.sendHints();
  }
github imodeljs / imodeljs / core / frontend / src / render / webgl / glsl / SkySphere.ts View on Github external
shader.addGraphicUniform("u_worldEye", (uniform, params) => {
      const frustum = params.target.planFrustum;
      if (FrustumUniformType.Perspective === params.target.frustumUniforms.type) {
        // compute eye point from frustum.
        const farLowerLeft = frustum.getCorner(Npc.LeftBottomRear);
        const nearLowerLeft = frustum.getCorner(Npc.LeftBottomFront);
        const scale = 1.0 / (1.0 - params.target.planFraction);
        const zVec = Vector3d.createStartEnd(farLowerLeft, nearLowerLeft, scratchVec3);
        const cameraPosition = fromSumOf(farLowerLeft, zVec, scale, scratchPoint3);
        scratch3Floats[0] = cameraPosition.x;
        scratch3Floats[1] = cameraPosition.y;
        scratch3Floats[2] = cameraPosition.z;
        uniform.setUniform3fv(scratch3Floats);
      } else {
        const delta = Vector3d.createStartEnd(frustum.getCorner(Npc.LeftBottomRear), frustum.getCorner(Npc.LeftBottomFront));
        const pseudoCameraHalfAngle = 22.5;
        const diagonal = frustum.getCorner(Npc.LeftBottomRear).distance(frustum.getCorner(Npc.RightTopRear));
        const focalLength = diagonal / (2 * Math.atan(pseudoCameraHalfAngle * Angle.radiansPerDegree));
        let zScale = focalLength / delta.magnitude();
        if (zScale < 1.000001)
          zScale = 1.000001; // prevent worldEye front being on or inside the frustum front plane
        const worldEye = Point3d.createAdd3Scaled(frustum.getCorner(Npc.LeftBottomRear), .5, frustum.getCorner(Npc.RightTopRear), .5, delta, zScale);
        scratch3Floats[0] = worldEye.x;
        scratch3Floats[1] = worldEye.y;
github imodeljs / imodeljs / core / frontend / src / render / webgl / glsl / SkySphere.ts View on Github external
shader.addGraphicUniform("u_worldEye", (uniform, params) => {
      const frustum = params.target.planFrustum;
      if (FrustumUniformType.Perspective === params.target.frustumUniforms.type) {
        // compute eye point from frustum.
        const farLowerLeft = frustum.getCorner(Npc.LeftBottomRear);
        const nearLowerLeft = frustum.getCorner(Npc.LeftBottomFront);
        const scale = 1.0 / (1.0 - params.target.planFraction);
        const zVec = Vector3d.createStartEnd(farLowerLeft, nearLowerLeft, scratchVec3);
        const cameraPosition = fromSumOf(farLowerLeft, zVec, scale, scratchPoint3);
        scratch3Floats[0] = cameraPosition.x;
        scratch3Floats[1] = cameraPosition.y;
        scratch3Floats[2] = cameraPosition.z;
        uniform.setUniform3fv(scratch3Floats);
      } else {
        const delta = Vector3d.createStartEnd(frustum.getCorner(Npc.LeftBottomRear), frustum.getCorner(Npc.LeftBottomFront));
        const pseudoCameraHalfAngle = 22.5;
        const diagonal = frustum.getCorner(Npc.LeftBottomRear).distance(frustum.getCorner(Npc.RightTopRear));
        const focalLength = diagonal / (2 * Math.atan(pseudoCameraHalfAngle * Angle.radiansPerDegree));
        let zScale = focalLength / delta.magnitude();
        if (zScale < 1.000001)
          zScale = 1.000001; // prevent worldEye front being on or inside the frustum front plane
        const worldEye = Point3d.createAdd3Scaled(frustum.getCorner(Npc.LeftBottomRear), .5, frustum.getCorner(Npc.RightTopRear), .5, delta, zScale);
        scratch3Floats[0] = worldEye.x;
        scratch3Floats[1] = worldEye.y;
        scratch3Floats[2] = worldEye.z;
        uniform.setUniform3fv(scratch3Floats);
      }
    });
  });
github imodeljs / imodeljs / core / frontend / src / AccuDraw.ts View on Github external
private intersectLine(snap: SnapDetail, linePt: Point3d, unitVec: Vector3d) {
    const vec = Vector3d.createStartEnd(linePt, snap.getPoint());
    const endPt = linePt.plusScaled(unitVec, vec.dotProduct(unitVec));
    const cpLine = LineSegment3d.create(linePt, endPt);
    this.intersectXYCurve(snap, cpLine, true); // Get point on snapped curve, not AccuDraw axis. Snap point isn't required to be in AccuDraw plane when Z isn't locked.
  }
github imodeljs / imodeljs / example-code / snippets / src / frontend / InteractiveTools.ts View on Github external
public setupAndPromptForNextAction(): void {
    // NOTE: Tool should call IModelApp.notifications.outputPromptByKey or IModelApp.notifications.outputPrompt to tell user what to do.
    IModelApp.accuSnap.enableSnap(true); // Enable AccuSnap so that linestring can be created by snapping to existing geometry

    if (0 === this.points.length)
      return;

    const hints = new AccuDrawHintBuilder();
    hints.enableSmartRotation = true; // Set initial AccuDraw orientation based on snapped geometry (ex. sketch on face of a solid)

    if (this.points.length > 1 && !(this.points[this.points.length - 1].isAlmostEqual(this.points[this.points.length - 2])))
      hints.setXAxis(Vector3d.createStartEnd(this.points[this.points.length - 2], this.points[this.points.length - 1])); // Align AccuDraw with last accepted segment

    hints.setOrigin(this.points[this.points.length - 1]); // Set compass origin to last accepted point.
    hints.sendHints();
  }
github imodeljs / imodeljs / core / frontend / src / tools / ToolAdmin.ts View on Github external
} else if (undefined !== vp.pickNearestVisibleGeometry(target, vp.pixelsFromInches(ToolSettings.viewToolPickRadiusInches), true, newTarget)) {
          vp.worldToNpc(newTarget, newTarget);
          targetNpc.z = newTarget.z;
        } else {
          vp.view.getTargetPoint(newTarget);
          vp.worldToNpc(newTarget, newTarget);
          targetNpc.z = newTarget.z;
        }
        vp.npcToWorld(targetNpc, target);
      }

      const cameraView: ViewState3d = vp.view;
      const transform = Transform.createFixedPointAndMatrix(target, Matrix3d.createScale(zoomRatio, zoomRatio, zoomRatio));
      const oldCameraPos = cameraView.getEyePoint();
      const newCameraPos = transform.multiplyPoint3d(oldCameraPos);
      const offset = Vector3d.createStartEnd(oldCameraPos, newCameraPos);

      // when you're too close to an object, the wheel zoom operation will stop. We set a "bump distance" so you can blast through obstacles.
      if (!isSnapOrPrecision && offset.magnitude() < ToolSettings.wheelZoomBumpDistance) {
        offset.scaleToLength(ToolSettings.wheelZoomBumpDistance / 3.0, offset); // move 1/3 of the bump distance, just to get to the other side.
        lastEventWasValid = false;
        target.addInPlace(offset);
      }

      const viewTarget = cameraView.getTargetPoint().clone();
      viewTarget.addInPlace(offset);
      newCameraPos.setFrom(oldCameraPos.plus(offset));

      if (!lastEventWasValid) {
        const thisEvent = ev.clone();
        thisEvent.point.setFrom(target);
        IModelApp.toolAdmin.currentInputState.lastWheelEvent = thisEvent;
github imodeljs / imodeljs / core / frontend / src / tools / MeasureTool.ts View on Github external
protected async acceptNewSegments(): Promise {
    if (this._locationData.length > 1) {
      for (let i = 0; i <= this._locationData.length - 2; i++) {
        const start = this._locationData[i].point;
        const end = this._locationData[i + 1].point;
        const distance = start.distance(end);
        const xyDist = start.distanceXY(end);
        const zDist = end.z - start.z;
        const slope = (0.0 === xyDist ? Math.PI : Math.atan(zDist / xyDist));
        const delta = Vector3d.createStartEnd(start, end);
        const refAxes = this._locationData[i].refAxes;
        refAxes.multiplyTransposeVectorInPlace(delta);

        const toolTip = await this.getMarkerToolTip(distance, slope, start, end);
        const marker = new MeasureMarker((this._acceptedSegments.length + 1).toString(), toolTip, start.interpolate(0.5, end), Point2d.create(25, 25));

        const segMarkerButtonFunc = (ev: BeButtonEvent) => {
          if (ev.isDown)
            return true;

          let selectedMarker: MeasureMarker | undefined;
          for (const seg of this._acceptedSegments) {
            if (!seg.marker.pick(ev.viewPoint))
              continue;
            selectedMarker = (seg.marker.isSelected ? undefined : seg.marker);
            break;
github imodeljs / imodeljs / core / frontend / src / ViewContext.ts View on Github external
let maxY = Math.ceil(localRange.high.y / refSpacing.y);

      const nRefRepetitionsX = (maxY - minY);
      const nRefRepetitionsY = (maxX - minX);

      minX *= refSpacing.x; maxX *= refSpacing.x;
      minY *= refSpacing.y; maxY *= refSpacing.y;

      let nGridRepetitionsX = nRefRepetitionsX;
      let nGridRepetitionsY = nRefRepetitionsY;

      const dirPoints: Point3d[] = [Point3d.create(minX, minY), Point3d.create(minX, minY + refSpacing.y), Point3d.create(minX + refSpacing.x, minY)];
      transform.multiplyPoint3dArrayInPlace(dirPoints);

      const xDir = Vector3d.createStartEnd(dirPoints[0], dirPoints[1]); xDir.normalizeInPlace();
      const yDir = Vector3d.createStartEnd(dirPoints[0], dirPoints[2]); yDir.normalizeInPlace();
      const dotX = xDir.dotProduct(viewZ);
      const dotY = yDir.dotProduct(viewZ);
      const unambiguousX = Math.abs(dotX) > 0.25;
      const unambiguousY = Math.abs(dotY) > 0.25;
      const reverseX = dotX > 0.0;
      const reverseY = dotY > 0.0;
      const refStepX = reverseY ? -refSpacing.x : refSpacing.x;
      const refStepY = reverseX ? -refSpacing.y : refSpacing.y;
      const fadeRefSteps = 8;
      const fadeRefTransparencyStep = (255 - gridConstants.refTransparency) / (fadeRefSteps + 2);

      let lastDist = 0.0;
      const lastPt = Point3d.createZero();
      const planeX = Plane3dByOriginAndUnitNormal.create(lastPt, Vector3d.unitX())!;
      const planeY = Plane3dByOriginAndUnitNormal.create(lastPt, Vector3d.unitY())!;
      const thisPt = Point3d.create();