2

I am working on a project in javascript and p5.js and am stuck at this point. I have to rotate a line from one of its ends with a certain angle in Radians/Degrees. Here's what I want to get-the image

Sorry for my bad drawing. So I want a formula to get C(x,y) to use in my code.

What should be the values of x and y in terms of t-ratios and x1,y1,x2,y2

Sorry,flip the positions of A and B.

3 Answers3

1

A \theta counterclockwise rotation matrix about the origin takes an (x,y) input and gives an output $(x cos \theta - y sin \theta, x sin \theta + y cos \theta) $. So you can shift your angle vertex to the origin, perform the rotation, and then shift back; if A is the vertex with coordinates (x1,y1) then subtract that from B, transform, and then add A back on to get C(x,y).

RobertTheTutor
  • 7,415
  • 2
  • 10
  • 34
1

Starting with your corrected sketch:

enter image description here

HINT: Let point $D$ be a point on $\overline{AB}$ such that angle $\angle{ADC}$ is a right angle. Using trig functions, we can then calculate the side lengths of $\triangle ADC$. Do you see how those side lengths would be enough to find $(x,y)$?

enter image description here

David Diaz
  • 2,218
  • Okay,let BC be perpendicular to AB. In that case,what should be the values of x and y?? – Raj jaiswal Feb 05 '21 at 14:08
  • 1
    Assuming $x_1 = x_2$, then $x$ is equal to $x_1$ plus the length of $\overline{DC}$, which you can find by applying a trig function to angle $\theta$. $y$ is $y_1 + \overline{AD}$. If $x_1 \not = x_2$, the problem is a bit harder. – David Diaz Feb 05 '21 at 14:25
  • Okay,that's good. In my case,X1=X2=0. – Raj jaiswal Feb 05 '21 at 14:42
0

Using complex numbers, translate both points to bring the rotation center to the origin, rotate by multiplying by $e^{i\theta}$ and translate back to the original center.

$$q'=(q-p)e^{i\theta}+p.$$

You can rewrite this formula using real numbers only.

  • I am not a profession in maths so I didn't really understand your answer.also,to make question easy,let BC perpendicular to AB.then,what is the value of x and y – Raj jaiswal Feb 05 '21 at 14:09