Skip to content Skip to sidebar Skip to footer

Distance Between Center To Any Point On Edge Of Rectangle In Javascript

As you can see in above picture, suppose that there is a ray emitted from center and collides at edge of rectangle. so I want to calculate at which point it collides, so that I co

Solution 1:

Let's center is (0, 0) and ray angle is phi. Pseudocode:

c = Cos(phi)
s = Sin(phi)
if Width * Abs(s) < Height * Abs(c) then
   x = Sign(c) * Width / 2
   y = Tan(phi) * x
else
   y = Sign(s) * Height / 2
   x = CoTan(phi) * y

Post a Comment for "Distance Between Center To Any Point On Edge Of Rectangle In Javascript"