Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

javascript - 动态计算运动物体前面的点的坐标?(Dynamicaly calculate the coordinates of a point in front of a moving object?)

I am working on a web project where I have a car moving on the canvas, and I need to get the colors of the pixels in front of the car.(我正在一个Web项目中工作,有一辆汽车在画布上移动,我需要获取汽车前部像素的颜色。)

I know how to get their colors, but have problems with their coordinates because my car's angle of moving is changing.(我知道如何获得它们的颜色,但是它们的坐标存在问题,因为我的汽车的移动角度正在变化。) Can I somehow dynamically calculate their coordinates knowing the center point of the car and its angle rotation?(我能否以某种方式知道汽车的中心点及其角度旋转来动态地计算其坐标?) 看起来如何   ask by BlackFlameLord translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes you can use sine and cosine like this:(是的,您可以像这样使用正弦和余弦:)

function xyFromVector(angle, mag){ return { x: Math.cos(angle)*mag, y: Math.sin(angle)*mag, } } const { x: xd, y: yd } = xyFromVector(carAngle, carLength/2); //car x + xd = x position of front of car //car y + yd = y position of front of car angle must be in radians.(角度必须以弧度为单位。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...