Solved

Rotatating line... Linear Algebra question.

Posted on 2004-03-29
3
282 Views
Last Modified: 2013-12-26
Okay so here's a question. I need an algorithm for rotating a point (p2) about an axis (p1). Here's the spaghetti code I have so far.

Radius = SquareRoot((p2.y - p1.y) ^ 2 + (p2.x - p1.x) ^ 2)
Radians = ArcCos((p1.y - p2.y) / radius) ' Angle between Vector(p1,p2) and unit vector (p1, {0, 1}). Rotating counter clockwise.
Radians = Radians + (2 * ((2 * PI) / 360)) 'Add two degrees to current angle of line
p2.y = (Cos(Radians) * Radius) + p1.y
p2.x = (Cos(Radians) * Radius) + p1.x

The code works fine for angles < 180 degrees. But as soon as I get to say 182 the line moves to an angle of 2 degrees counter clockwise from the unit vector... anyone know a better algorithm for this or how to fix this one to be able to run a full rotation? I need to be able to "add" angles to lines.
0
Comment
Question by:CyrexCore2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 10709272
Radians = atan2(p2.y - p1.y,p1.x - p2.x);
0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 10709418
Radians = atan2(p2.y - p1.y,p2.x - p1.x)

 p2.x = (Sin(Radians) * Radius) + p1.x
0
 
LVL 14

Author Comment

by:CyrexCore2k
ID: 10709644
YES! Thank you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question