Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

General Trigonomic Algorithm question...

Posted on 2004-03-28
3
Medium Priority
?
358 Views
Last Modified: 2010-04-17
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 4

Accepted Solution

by:
mikkelp earned 500 total points
ID: 10702241
Hi

given a point A = (a1,a2) relative to the point 0 = (0,0) in the plane and a counter clockwise rotation of R degrees, your rotation is given by

A' = (a1 x cos R - a2 x sin R, a1 x cos R + a2 sin R)  // counterclockwise
A'' = (a1 x cosR + a2 x sin R, a1 x cos R - a2 sin R)  // clockwise

so to rotate any one point Q about the point P, find the vector D = (Q-P), rotate D R degrees and Add P.

p2' = p1 + ((p2-p1) rotated R degrees)

check this link
http://www.mapleapps.com/categories/maple_tools/animations/html/clock1.html
0
 
LVL 14

Author Comment

by:CyrexCore2k
ID: 10705363
I'm sorry I've never done anything like this before. Do you think you could write out the spaghetti code?

In principle I understand how this works but for some reason when I try to write it out it all goes sour.
0
 
LVL 14

Author Comment

by:CyrexCore2k
ID: 10709648
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Simple Linear Regression
Progress

636 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