开发者

How can I get the "front" of a parallelogram given 4 points and an angle

开发者 https://www.devze.com 2023-03-25 02:11 出处:网络
This should be a simple matter, but for some reason I can\'t grasp it. I have a parallelogram, defined as four points (in anti-clockwise order, but apart from that I do not know which corner is which

This should be a simple matter, but for some reason I can't grasp it.

I have a parallelogram, defined as four points (in anti-clockwise order, but apart from that I do not know which corner is which). I also have the center point of the parallelogram, and it's orientation (the angle it if "facing"). What I want to get is the midpoint of the line at the "front" of the parallelogram.

To do this, I imagine I would have to trace a ray from the midpoint, at the angle the parallelogram is facing, and check which of the four lines it intersects and where. This is where I'm stuck. I can't figure out a formula to achieve this goal. Any ideas?

I am coding in C#, but this is a math problem more than anything, so I'll accept a formula or psuedocode.

EDIT: It seems there has been a bit if confusion in my problem; apologies for that. I should have specified that I'm working with two dimens开发者_Go百科ions, and the "front" is defined as the line on the parallelogram that intersects the ray generated by casting from the midpoint, at the angle provided (to the origin). As suggested in the comments, here is a diagram:

How can I get the "front" of a parallelogram given 4 points and an angle

The orange points represent the corners of the parallelogram, the blue point is the centroid, and the yellow curve is the angle I am given. The purple line is simply parallel to the X-axis to help represent the angle. The grey line extending from the blue point is (a subsection of) the ray I mentioned previously, and thus the green point is the point I wish to calculate. Please also note that this diagram is just a sketch to help visualize the problem, and not generated by my program.

Hopefully this helps clear up any confusion.


A bit brute-force and not elegant, but try this to get the coordinates of your green point (I hope it's green anyway; I'm a bit color blind):

  1. You have four line segments. Calculate the equation of the line that contains each line segment (y = mx + b and all that). There will be four equations.
  2. Calculate the angle from your center point to each of your four parallelogram vertices.
  3. Determine which side your ray intersects by seeing which two angles your yellow angle is between. It will either intersect one of the sides, or one of the vertices. If you hit one of the vertices, you're done.
  4. Otherwise, solve for the intersection of your ray (which has its own equation) with the appropriate equation for the appropriate side.


Here is a great page on line intersection algorithms.

0

精彩评论

暂无评论...
验证码 换一张
取 消