3d-representations-guide / src /lib /point-sensor.mjs
suvadityamuk's picture
suvadityamuk HF Staff
Rename article to 3D Ecosystem and refine text, sensor and storage visualizations
d5c8235 verified
Raw History Blame Contribute Delete
917 Bytes
import {camera,add,mul} from './math.mjs';
// One pose drives visibility, the world-space camera, and the top-view locator.
export const sensorPose=angle=>camera(angle??35,12,5.2);
export function sensorEdges(angle){
const {eye,forward,right,up}=sensorPose(angle);
const point=(x,y,z)=>add(eye,add(mul(right,x),add(mul(up,y),mul(forward,z))));
const ring=(w,h,z)=>[[-w,-h],[w,-h],[w,h],[-w,h]].map(([x,y])=>point(x,y,z));
const back=ring(.17,.12,-.25),front=ring(.17,.12,-.04),lens=ring(.08,.06,.03),view=ring(.28,.21,.55),edges=[];
for(const r of [back,front,lens,view])for(let i=0;i<4;i++)edges.push([r[i],r[(i+1)%4]]);
for(let i=0;i<4;i++){edges.push([back[i],front[i]],[front[i],lens[i]],[lens[i],view[i]]);}
return edges;
}
export function sensorLocator(angle){
const {eye}=sensorPose(angle),scale=32/5.2;
return {x:50+eye[0]*scale,y:48+eye[2]*scale,rotation:Math.atan2(eye[0],-eye[2])*180/Math.PI};
}