Solved

General Trigonomic Algorithm question...

Posted on 2004-03-28
3
348 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
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
mikkelp earned 125 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 58
wordsWithout 49 80
array6 challenfge 6 64
Basic Java Case or If-Else statement... 3 13
This article will show, step by step, how to integrate R code into a R Sweave document
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now