How to get correct vertices coordinates of scaled object? - scale

So I have this object (abstract one)
I know all the coordinates (x, y) of black points (vertices) and the middle one. Now I want to scale it by a factor of 0.5 or 2.0 with the origin being the red point.
How do I get the new coordinates for the points for the Scaled object? Red would not change, left goes to left, right to right, etc... What is the formula or technique?
Any help greatly appreciated!

(x,y)=((x,y)-(redx,redy))*2+(redx,redy)

Related

Even distribution of objects on circle

I'm creating a circle dynamically based on two positions; the first is the centre, and second is the radius. I'm then determining how many of my objects will fit onto the perimeter of the circle by int fillCount = Mathf.RoundToInt(circumference / sizeOfObject);
So now I've got a circle, I know how many things will fit on it, I know the circumference, I know the radius, and I've cobbled together a function that will find the Vector3 of any given point on the circle.
What I can't figure out is how to evenly distribute each object. i.e, place an object every 'n' degrees. I don't think I need to worry about arc-reparameterization, or do I? I think the answer lies in finding the degree of placement by using the inverse cosine/sine, but I'm not sure and my maths isn't that good.
If anyone has any input or advice, I'd greatly appreciate it.
If you know how many objects are in the circle, you can divide 360deg by the number of objects to determine the angle on the circle each object will be placed. Since we know the point on a circle is located at x=r*cos(angle), y=r*sin(angle) you can add this Vector2 to the Vector2 center of your circle.
As an example, if you have 3 objects to place around the circle. Get your angle by dividing 360/3 = 120. Each object will be placed 120deg from each other.
Pick your starting point (we will pick 0 degrees),
Vector2(r*Mathf.Deg2Rad*cos(0), r*Mathf.Deg2Rad*sin(0)).
The next object will be at 120deg, which will be
Vector2(r*Mathf.Deg2Rad*cos(120), r*Mathf.Deg2Rad*sin(120)).
Similarly, the 3rd object will be at 240deg,
Vector2(r*Mathf.Deg2Rad*cos(240), r*Mathf.Deg2Rad*sin(240))

how to get gps coordinate using one coordinate and distance

For example , it assumes that the black rectangle is a square.
and The gps coordinates of the red circle , which is in the square is lat 126.993611 long 37.5727
i want to know the yellow circle and blue circle coordinates displayed on the screen.
Units of length are all M(meter)
please let me know best calculate formula!
You can use geofence for this.
https://developer.android.com/training/location/geofencing.html
or you write a method which calculates your distance by coordinates.
Then you can use a rise and this method to get the new location.

How to find the x and y coordinates of a circle given a plot, the original rotation, the new rotation, the origin and radius?

The easiest way I know how to explain this is with a picture so here it is:
http://pbrd.co/19RxqqV
For simplicity the origin is 0,0 and the angles are easy to work with but they could potentially be anything. The only things I really consistently know for this type of problem is the rotation of the circle, the origin and the radius and then of course the new degree/rotation of the circle.
This question, I think is similar but not really the exact same thing:
Finding the coordinates on the edge of a circle
Thanks! I hope my question is clear enough.
The coordinates of a point with angle a with respect to x-axis on a circle of radius r are:
x = r*cos(a*Pi/180), y = r*sin(a*Pi/180)
In your case a=45+135

Math Problem: Getting Coordinates From Position And Angle

let me begin by stating that's i'm dreadful at math.
i'm attempting to reposition and rotate a rectangle. however, i need to rotate the rectangle from a point that is not 0,0 but according to how far its coordinates has shifted. i'm sure that doesn't make much sense, so i've made some sketches to help explain what i need.
the image above shows 3 stages of the red rectangle moving from 0% to 100%. the red rectangle's X and Y coordinates (top left of the red rectangle) only moves a percentage of the blue rectangle's height.
the red rectangle can rotate. focusing only on the middle example ("Distance -50%") from above, where the red rectangle is repositioned at -50 of the blue rectangle's height, its new angle in the above image is now -45º. it has been rotated from its 0, 0 point.
now, my problem is that i want its rotational point to reflect its position.
the red and blue rectangles are the same size, but have opposite widths and heights. since the red rectangle's 0,0 coordinates are now -50% of the blue rectangle's height, and since they have opposite widths and heights, i want the rotational point to be 50% of the red rectangle's width (or 50% of the blue rectangle's height, which is the same thing).
rather than specifically telling the red rectangle to rotate at 50% of its width, in order to do what i want, i need to emulate doing so by using a formula that will position the red rectangle's X and Y coordinates so that its rotational point reflects its position.
Here's an illustrated solution to your problem:
I don't exactly understand what you need, but it seems that a procedure to rotate a rectangle around an arbitrary point may help.
Suppose we want to rotate a point (x,y) d radians around the origin (0,0). The formula for the location of the rotated point is:
x' = x*cos(d) - y*sin(d)
y' = x*sin(d) + y*cos(d)
Now we don't want to rotate around the origin, but around a given point (a,b). What we do is first move the origin to (a,b), then apply the rotation formula above, and then move the origin back to (0,0).
x' = (x-a)*cos(d) - (y-b)*sin(d) + a
y' = (x-a)*sin(d) + (y-b)*cos(d) + b
This is your formula for rotating a point (x,y) d radians around the point (a,b).
For your problem (a,b) would be the point halfway on the right side of the blue rectangle, and (x,y) would be every corner of the red rectangle. The formula gives (x',y') for the coordinates of the corners of rotated red rectangle.
It's quite simple really.
1. Let's settle on your point you want to rotate the rectangle about, i.e. the point of rotation (RP) which does not move when you swivel your rectangle around. Let's assume that the point is represented by the diamond in the figure below.
2. Translate the 4 points so that RP is at (0,0). Suppose the coordinates of that point is (RPx,RPy), therefore subtract all 4 corners of the rectangle by those coordinates.
3. Rotate the points with a rotation matrix (which rotates a point anticlockwise around the origin through some angle which is now the point of rotation thanks to the previous translation):
The following figure shows the rectangle rotated by 45° anticlockwise.
4. Translate the rectangle back (by adding RP to all 4 points):
I assume this is what you want :)
It seems like you could avoid a more complex rotation by more crafty positioning initially? For example, in the last example, position the red box at "-25% Blue Height" and "-25% Red Height" -- if I follow your referencing scheme -- then perform the rotation you want.
If you know the origin O and a point P on the side of rotated rectangle, you can calculate the vector between the two:
(source: equationsheet.com)
You can get the angle between the vector and the x-axis by taking the dot product with this vector:
(source: equationsheet.com)
Given this, you can transform any point on the rectangle by multiplying it by a rotation matrix:
(source: equationsheet.com)

mapping from normalized device coordinates to view space

I'd like to map from normalized device coordinates back to viewspace.
The other way arround works like this:
viewspace -> clip space : multiply the homogeneous coordinates by the projection matrix
clip space -> normalized device coordinates: divide the (x,y,z,w) by w
now in normalized device coordinates all coordinates which were within the view frustum fall into the cube x,y,z € [-1,1] and w=1
Now i'd like to transform some points on the boundary of that cube back into view coordinates. The projection matrix is nonsingular, so I can use the inverse to get from clipsace to viewspace. but i don't know how to get from normalized device space to clipspace, since i don't know how to calculate the 'w' i need to multiply the other coordinates with.
can someone help me with that? thanks!
Unless you actually want to recover your clip space values for some reason you don't need to calculate the W. Multiply your NDC point by the inverse of the projection matrix and then divide by W to get back to view space.
The flow graph on the top, and the formulas described on the following page, might help you : http://www.songho.ca/opengl/gl_transform.html

Resources