Skip to content

Commit

Permalink
calculating q value
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Sep 8, 2023
1 parent e81b1a4 commit db63777
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
30 changes: 30 additions & 0 deletions src/calculations/qvalue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Beamstop } from "../utils/types";
import { Ray } from "./ray";
import { Vector2 } from "three";

export const calculateQValue = (distance: number, cameraLength: number, wavelength: number): number | null => {
if (cameraLength === 0 || wavelength == 0) {
return null;
}
if (cameraLength < 0 || distance < 0 || wavelength < 0) {
return null;
}
return 4 * Math.PI * Math.sin(Math.atan(distance / cameraLength) / 2) / wavelength;
};

export const calculateDistanceFromQValue = (qValue: number, cameraLength: number, wavelength: number): number | null => {
if (qValue < 0 || cameraLength < 0 || wavelength < 0) {
return null;
}
const temp = wavelength * qValue / (4 * Math.PI);

if (Math.abs(temp) >= Math.sqrt(2) / 2) {
return null;
}
return Math.tan(2 * Math.asin(temp)) * cameraLength;
};

export const getPointForQ = (qValue: number, angle: number, cameralength: number, wavelength: number, beamstop: Beamstop): Vector2 => {
const ray = new Ray(new Vector2(Math.cos(angle), Math.sin(angle)), new Vector2(beamstop.centre.x ?? 0, beamstop.centre.y ?? 0));
return ray.getPointAtDistance(1.0e3 * (calculateDistanceFromQValue(qValue, cameralength, wavelength) ?? 0));
};
9 changes: 2 additions & 7 deletions src/calculations/ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export class Ray {
this.initial_point = initial_point;
}

/**
* Returns a point in the ray
* @param scalar
* @returns
*/
getPoint(scalar: number): Vector2 {
const result = new Vector2(this.direction.x, this.direction.y);
result.multiplyScalar(scalar);
Expand Down Expand Up @@ -56,8 +51,8 @@ export class Ray {
const b =
2 * coeffOfx2 * this.direction.x * this.initial_point.x +
coeffOfxy *
(this.direction.x * this.initial_point.y +
this.direction.y * this.initial_point.x) +
(this.direction.x * this.initial_point.y +
this.direction.y * this.initial_point.x) +
2 * coeffOfy2 * this.direction.y * this.initial_point.y +
coeffOfx * this.direction.x +
coeffOfy * this.direction.y;
Expand Down
2 changes: 1 addition & 1 deletion src/plot/centrePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function CentrePlot(): JSX.Element {
}
return state.current;
});

const beamstop = useBeamstopStore((state): Beamstop => {
if (plotConfig.plotAxes === PlotAxes.milimeter) {
return {
Expand Down Expand Up @@ -65,7 +66,6 @@ export default function CentrePlot(): JSX.Element {
};
});

//unit miss alignment
const domains = getDomains(detector, cameraTube);

return (
Expand Down

0 comments on commit db63777

Please sign in to comment.