Draw a line at a specific angle in Java

霸气de小男生 提交于 2019-11-28 05:49:18

Is this what you're looking for?

startX = x;
startY = y;
endX   = x + 40 * Math.sin(angle);
endY   = y + 40 * Math.cos(angle);

And draw a line from (startX, startY) to (endX, endY) in whatever API you're using.

Also note that angle is in radians. If you had it in degrees, you need to convert it first:

angle = angle * Math.PI / 180;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!